Supported Indicators
Time Series Forecast
Introduction
This indicator represents an indicator capable of predicting new values given previous data from a window. source
To view the implementation of this indicator, see the LEAN GitHub repository.
Using TSF Indicator
To create an automatic indicators for TimeSeriesForecast
, call the TSF
helper method from the QCAlgorithm
class. The TSF
method creates a TimeSeriesForecast
object, hooks it up for automatic updates, and returns it so you can used it in your algorithm. In most cases, you should call the helper method in the Initialize
initialize
method.
public class TimeSeriesForecastAlgorithm : QCAlgorithm { private Symbol _symbol; private TimeSeriesForecast _tsf; public override void Initialize() { _symbol = AddEquity("SPY", Resolution.Daily).Symbol; _tsf = TSF(_symbol, 3); } public override void OnData(Slice data) { if (_tsf.IsReady) { // The current value of _tsf is represented by itself (_tsf) // or _tsf.Current.Value Plot("TimeSeriesForecast", "tsf", _tsf); } } }
class TimeSeriesForecastAlgorithm(QCAlgorithm): def Initialize(self) -> None: self._symbol = self.AddEquity("SPY", Resolution.Daily).Symbol self.tsf = self.TSF(self.symbol, 3) def on_data(self, slice: Slice) -> None: if self.tsf.IsReady: # The current value of self.tsf is represented by self.tsf.Current.Value self.plot("TimeSeriesForecast", "tsf", self.tsf.Current.Value)
The following reference table describes the TSF
method:
TSF()1/1
TimeSeriesForecast QuantConnect.Algorithm.QCAlgorithm.TSF (Symbol
symbol,Int32
period,*Nullable<Resolution>
resolution,*Func<IBaseData, Decimal>
selector )
Creates a new Time Series Forecast indicator.
If you don't provide a resolution, it defaults to the security resolution. If you provide a resolution, it must be greater than or equal to the resolution of the security. For instance, if you subscribe to hourly data for a security, you should update its indicator with data that spans 1 hour or longer.
For more information about the selector argument, see Alternative Price Fields.
For more information about plotting indicators, see Plotting Indicators.
You can manually create a TimeSeriesForecast
indicator, so it doesn't automatically update. Manual indicators let you update their values with any data you choose.
Updating your indicator manually enables you to control when the indicator is updated and what data you use to update it. To manually update the indicator, call the Update
update
method with time/number pair or an IndicatorDataPoint
. The indicator will only be ready after you prime it with enough data.
public class TimeSeriesForecastAlgorithm : QCAlgorithm { private Symbol _symbol; private TimeSeriesForecast _tsf; public override void Initialize() { _symbol = AddEquity("SPY", Resolution.Daily).Symbol; _tsf = new TimeSeriesForecast(3); } public override void OnData(Slice data) { if (data.Bars.TryGetValue(_symbol, out var bar)) { _tsf.Update(bar.EndTime, bar.Close); } if (_tsf.IsReady) { // The current value of _tsf is represented by itself (_tsf) // or _tsf.Current.Value Plot("TimeSeriesForecast", "tsf", _tsf); } } }
class TimeSeriesForecastAlgorithm(QCAlgorithm): def Initialize(self) -> None: self._symbol = self.AddEquity("SPY", Resolution.Daily).Symbol self.tsf = TimeSeriesForecast(3) def on_data(self, slice: Slice) -> None: bar = slice.Bars.get(self.symbol) if bar: self.tsf.Update(bar.EndTime, bar.Close) if self.tsf.IsReady: # The current value of self.tsf is represented by self.tsf.Current.Value self.plot("TimeSeriesForecast", "tsf", self.tsf.Current.Value)
To register a manual indicator for automatic updates with the security data, call the RegisterIndicator
method.
public class TimeSeriesForecastAlgorithm : QCAlgorithm { private Symbol _symbol; private TimeSeriesForecast _tsf; public override void Initialize() { _symbol = AddEquity("SPY", Resolution.Daily).Symbol; _tsf = new TimeSeriesForecast(3); RegisterIndicator(_symbol, _tsf, Resolution.Daily); } public override void OnData(Slice data) { if (_tsf.IsReady) { // The current value of _tsf is represented by itself (_tsf) // or _tsf.Current.Value Plot("TimeSeriesForecast", "tsf", _tsf); } } }
class TimeSeriesForecastAlgorithm(QCAlgorithm): def Initialize(self) -> None: self._symbol = self.AddEquity("SPY", Resolution.Daily).Symbol self.tsf = TimeSeriesForecast(3) self.RegisterIndicator(self.symbol, self.tsf, Resolution.Daily) def on_data(self, slice: Slice) -> None: if self.tsf.IsReady: # The current value of self.tsf is represented by self.tsf.Current.Value self.plot("TimeSeriesForecast", "tsf", self.tsf.Current.Value)
The following reference table describes the TimeSeriesForecast
constructor:
TimeSeriesForecast()1/2
TimeSeriesForecast QuantConnect.Indicators.TimeSeriesForecast (string
name,int
period )
Creates a new TimeSeriesForecast indicator with the specified period.
TimeSeriesForecast()2/2
TimeSeriesForecast QuantConnect.Indicators.TimeSeriesForecast (
int
period
)
Creates a new TimeSeriesForecast indicator with the specified period.
Visualization
The following image shows plot values of selected properties of TimeSeriesForecast
using the plotly library.