/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using QuantConnect.Data;
namespace QuantConnect.Indicators
{
///
/// Represents a piece of data at a specific time
///
public class IndicatorDataPoint : BaseData, IEquatable, IComparable, IComparable
{
///
/// Initializes a new default instance of IndicatorDataPoint with a time of
/// DateTime.MinValue and a Value of 0m.
///
public IndicatorDataPoint()
{
Value = 0m;
Time = DateTime.MinValue;
}
///
/// Initializes a new instance of the DataPoint type using the specified time/data
///
/// The time this data was produced
/// The data
public IndicatorDataPoint(DateTime time, decimal value)
{
Time = time;
Value = value;
}
///
/// Initializes a new instance of the DataPoint type using the specified time/data
///
/// The symbol associated with this data
/// The time this data was produced
/// The data
public IndicatorDataPoint(Symbol symbol, DateTime time, decimal value)
{
Symbol = symbol;
Time = time;
Value = value;
}
///
/// Indicates whether the current object is equal to another object of the same type.
///
///
/// true if the current object is equal to the parameter; otherwise, false.
///
/// An object to compare with this object.
public bool Equals(IndicatorDataPoint other)
{
if (other == null)
{
return false;
}
return other.Time == Time && other.Value == Value;
}
///
/// Compares the current object with another object of the same type.
///
///
/// A value that indicates the relative order of the objects being compared. The return value has the following meanings: Value Meaning Less than zero This object is less than the parameter.Zero This object is equal to . Greater than zero This object is greater than .
///
/// An object to compare with this object.
public int CompareTo(IndicatorDataPoint other)
{
if (ReferenceEquals(other, null))
{
// everything is greater than null via MSDN
return 1;
}
return Value.CompareTo(other.Value);
}
///
/// Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.
///
///
/// A value that indicates the relative order of the objects being compared. The return value has these meanings: Value Meaning Less than zero This instance precedes in the sort order. Zero This instance occurs in the same position in the sort order as . Greater than zero This instance follows in the sort order.
///
/// An object to compare with this instance. is not the same type as this instance. 2
public int CompareTo(object obj)
{
var other = obj as IndicatorDataPoint;
if (other == null)
{
throw new ArgumentException(Messages.IndicatorDataPoint.InvalidObjectTypeToCompareTo(GetType()));
}
return CompareTo(other);
}
///
/// Returns a string representation of this DataPoint instance using ISO8601 formatting for the date
///
///
/// A containing a fully qualified type name.
///
/// 2
public override string ToString()
{
return Messages.IndicatorDataPoint.ToString(this);
}
///
/// Indicates whether this instance and a specified object are equal.
///
///
/// true if and this instance are the same type and represent the same value; otherwise, false.
///
/// Another object to compare to.
/// 2
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
return obj is IndicatorDataPoint && Equals((IndicatorDataPoint) obj);
}
///
/// Returns the hash code for this instance.
///
///
/// A 32-bit signed integer that is the hash code for this instance.
///
/// 2
public override int GetHashCode()
{
unchecked
{
return (Value.GetHashCode()*397) ^ Time.GetHashCode();
}
}
///
/// Returns the data held within the instance
///
/// The DataPoint instance
/// The data held within the instance
public static implicit operator decimal(IndicatorDataPoint instance)
{
return instance.Value;
}
///
/// This function is purposefully not implemented.
///
public override BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, bool isLiveMode)
{
throw new NotImplementedException(Messages.IndicatorDataPoint.UnsupportedMethod(nameof(Reader)));
}
///
/// This function is purposefully not implemented.
///
public override SubscriptionDataSource GetSource(SubscriptionDataConfig config, DateTime date, bool isLiveMode)
{
throw new NotImplementedException(Messages.IndicatorDataPoint.UnsupportedMethod(nameof(GetSource)));
}
}
}