Search Framework:
TimeSeriesBase
Namespace: WealthLab.Core
Parent: DateSynchedList<double>
Descendants: BarHistory , TimeSeries

TimeSeriesBase is the common base class used by TimeSeries and BarHistory. It provides shared functionality for working with data synchronized to a List of DateTimes. Two important concrete classes derive from TimeSeriesBase:

  • TimeSeries - manages a series of double values
  • BarHistory - represents historical open, high, low, close, volume, and related market data TimeSeriesBase also provides utility properties for accessing the first and last values, calculating overall and most recent changes, determining a likely HistoryScale, and storing user-defined data. TimeSeriesBase inherits its fundamental DateTime synchronization functionality from DateSynchedList<double>. Important inherited members commonly used with TimeSeriesBase instances include the following.
Inherited Members
Count
public int Count

Returns the number of elements in the series. The DateTimes collection contains the same number of DateTimes. Derived classes maintain their associated data synchronized to these DateTimes.


DateTimes
public virtual List<DateTime> DateTimes

Contains the DateTime corresponding to each element in the series. Derived classes maintain their own values synchronized with this collection, allowing the same index to be used to access both a DateTime and its corresponding data.


EndDate
public DateTime EndDate

Returns the final DateTime in DateTimes. Returns DateTime.MaxValue if the collection is empty.


IndexOf
public int IndexOf(DateTime dt, bool exactMatchOnly = false)

Returns the index corresponding to dt. If exactMatchOnly is false and an exact match does not exist, the method returns the index immediately following the closest earlier DateTime, provided the requested DateTime falls within the range of the series. Returns -1 if the DateTime falls outside the series or if exactMatchOnly is true and no exact match exists.


StartDate
public DateTime StartDate

Returns the first DateTime in DateTimes. Returns DateTime.MinValue if the collection is empty.


TimeSpan
public TimeSpan TimeSpan

Returns the amount of time covered by the DateTimes in the series. Returns a zero TimeSpan if fewer than two DateTimes are available.



Members
Cache
public ConcurrentDictionary<string, object> Cache

A generic cache Dictionary that can be used to associate arbitrary objects with the TimeSeriesBase instance. Indicators can use this Cache to share related calculations and avoid recalculating the same data.


DetermineMarketCloseTime
public TimeSpan DetermineMarketCloseTime()

Attempts to determine the market close time from the DateTimes contained in the series. The method examines transitions between trading days and returns the latest observed time of day immediately preceding a new date. Returns a zero TimeSpan if the series contains no data.


DetermineMarketOpenTime
public TimeSpan DetermineMarketOpenTime()

Attempts to determine the market open time from the DateTimes contained in the series. For intraday data, the method examines the first bar of each trading day. When the detected scale is minute-based, it adjusts the first bar's timestamp backward by one interval to estimate the actual market open time. Returns a zero TimeSpan if the series contains no data.


DetermineScale
public HistoryScale DetermineScale(bool useBarHistory)

Attempts to determine the HistoryScale represented by the DateTimes in the series. If useBarHistory is true and this instance is a BarHistory, the method returns the BarHistory's assigned Scale directly. Otherwise, it examines the spacing between DateTimes and attempts to identify the data as:

  • Tick
  • Second
  • Minute
  • Daily
  • Weekly
  • Monthly
  • Quarterly
  • Yearly If there is insufficient information to determine another scale, the method returns a Daily HistoryScale.

EndDateDisplay
public string EndDateDisplay

Returns EndDate formatted as a short date/time string for display purposes. Returns an empty string if EndDate is DateTime.MaxValue.


FirstValue
public double FirstValue

Returns the first value in the series. Returns Double.NaN if the series contains no values.


IsUpToDate
public virtual bool IsUpToDate(DateTime endDate)

Returns true if the series appears to contain data through the requested endDate. The base implementation evaluates the data using the US Stock Market and a Daily scale. BarHistory overrides this method so that the test can account for the BarHistory's actual market and scale, including market holidays, trading hours, and intraday data.


LastChange
public double LastChange

Returns the change between the final two values in the series:

LastValue - PreviousValue

Returns Double.NaN if the series contains fewer than two values.


LastChangePct
public double LastChangePct

Returns the percentage change between the final two values in the series. Returns Double.NaN if the series contains fewer than two values.


LastValue
public double LastValue

Returns the final value in the series. Returns Double.NaN if the series contains no values.


SortToken
public double SortToken

Contains a temporary numeric value that can be used when sorting TimeSeriesBase instances. WealthLab uses this property internally in certain position sizing and participant-sorting operations. The default value is 0.


StartDateDisplay
public string StartDateDisplay

Returns StartDate formatted as a short date/time string for display purposes. Returns an empty string if StartDate is DateTime.MinValue or DateTime.MaxValue.


SuppressLabels
public bool SuppressLabels

Determines whether labels should be suppressed when the series is plotted on a chart. The default value is false.


TotalProfit
public double TotalProfit

Returns the total change in the series:

Example Code
LastValue - FirstValue

TotalProfitPercent
public double TotalProfitPercent

Returns TotalProfit as a percentage of FirstValue. Returns Double.NaN if FirstValue is zero.


UserData
public object UserData

Provides a general-purpose property for associating custom data with a TimeSeries or BarHistory instance. You can store any object, including primitive values such as an int or double.


UserDataAsDouble
public double UserDataAsDouble

Returns UserData cast to a double. Returns Double.NaN if UserData is null. The value stored in UserData must be compatible with a direct cast to double.


UserDataAsInt
public int UserDataAsInt

Returns UserData cast to an int. Returns 0 if UserData is null. The value stored in UserData must be compatible with a direct cast to int.


WasPlotted
public bool WasPlotted

Indicates whether the series has been plotted. WealthLab uses this property internally when managing charted TimeSeries and indicators. The default value is false.