Contents
Indicator Reference
Auto Regressive Integrated Moving Average
Introduction
An Autoregressive Intergrated Moving Average (ARIMA) is a time series model which can be used to describe a set of data. In particular,with Xₜ representing the series, the model assumes the data are of form (after differencing
Create Manual Indicators
You can manually create a AutoRegressiveIntegratedMovingAverage
indicator, so it doesn’t automatically update. Manual indicators let you update their values with any data you choose. The following reference table describes the AutoRegressiveIntegratedMovingAverage
constructor.
AutoRegressiveIntegratedMovingAverage()1/2
AutoRegressiveIntegratedMovingAverage QuantConnect.Indicators.AutoRegressiveIntegratedMovingAverage ( )
This particular constructor fits the model by means of TwoStepFit
for a specified name.
AutoRegressiveIntegratedMovingAverage()2/2
AutoRegressiveIntegratedMovingAverage QuantConnect.Indicators.AutoRegressiveIntegratedMovingAverage ( )
This particular constructor fits the model by means of TwoStepFit
using ordinary least squares.
Update Manual Indicators
You can update the indicator automatically or manually.
Automatic Update
To register a manual indicator for automatic updates with the security data, call the RegisterIndicator
method.
private AutoRegressiveIntegratedMovingAverage _arima; // In Initialize() _arima = new AutoRegressiveIntegratedMovingAverage(name, arOrder, diffOrder, maOrder, period, intercept); _arima.Updated += IndicatorUpdateMethod; RegisterIndicator(symbol, _arima, Resolution.Daily); // In IndicatorUpdateMethod() if (_arima.IsReady) { var indicatorValue = _arima.Current.Value; }
# In Initialize() self.arima = AutoRegressiveIntegratedMovingAverage(name, arOrder, diffOrder, maOrder, period, intercept) self.arima.Updated += self.IndicatorUpdateMethod self.RegisterIndicator(symbol, self.arima, Resolution.Daily) # In IndicatorUpdateMethod() if self.arima.IsReady: indicator_value = self.arima.Current.Value
To customize the data that automatically updates the indicator, see Custom Indicator Periods and Custom Indicator Values.
Manual Update
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
method with time/decimal pair. The indicator will only be ready after you prime it with enough data.
private AutoRegressiveIntegratedMovingAverage _arima; private Symbol symbol; // In Initialize() _arima = new AutoRegressiveIntegratedMovingAverage(arOrder, diffOrder, maOrder, period, intercept); symbol = AddEquity("SPY").Symbol; // In OnData() if (data.ContainsKey(_symbol)) { _arima.Update(data[symbol].EndTime, data[symbol].High); } if (_arima.IsReady) { var indicatorValue = _arima.Current.Value; }
# In Initialize() self.arima = AutoRegressiveIntegratedMovingAverage(arOrder, diffOrder, maOrder, period, intercept) self.symbol = self.AddEquity("SPY").Symbol # In OnData() if data.ContainsKey(self.symbol): self.arima.Update(data[self.symbol].EndTime, data[self.symbol].High) if self.arima.IsReady: indicator_value = self.arima.Current.Value
Create Automatic Indicators
The ARIMA method creates an AutoRegressiveIntegratedMovingAverage indicator, sets up a consolidator to update the indicator, and then returns the indicator so you can use it in your algorithm.
The following reference table describes the ARIMA
method:
ARIMA()1/1
AutoRegressiveIntegratedMovingAverage QuantConnect.Algorithm.QCAlgorithm.ARIMA (Symbol
symbol,Int32
arOrder,Int32
diffOrder,Int32
maOrder,Int32
period,*Nullable<Resolution>
resolution )
Creates a new ARIMA indicator.
If you don't provide a resolution, it defauls 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.
Get Indicator Values
To get the value of the indicator, use its Current.Value
attribute.
private AutoRegressiveIntegratedMovingAverage _arima; // In Initialize() var symbol = AddEquity("SPY").Symbol; _arima = ARIMA(symbol, arOrder, diffOrder, maOrder, period); // In OnData() if (_arima.IsReady) { var arResidualError = _arima.ArResidualError.Current.Value; var maResidualError = _arima.MaResidualError.Current.Value; var current = _arima.Current.Value; }
# In Initialize() symbol = self.AddEquity("SPY").Symbol self.arima = self.ARIMA(symbol, arOrder, diffOrder, maOrder, period) # In OnData() if self.arima.IsReady: ar_residual_error = self.arima.ArResidualError.Current.Value ma_residual_error = self.arima.MaResidualError.Current.Value current = self.arima.Current.Value
Visualization
To plot indicator values, in the OnData
event handler, call the Plot
method.
private AutoRegressiveIntegratedMovingAverage _arima; // In Initialize() var symbol = AddEquity("SPY").Symbol; _arima = ARIMA(symbol, arOrder, diffOrder, maOrder, period); // In OnData() if (_arima.IsReady) { Plot("My Indicators", "arresidualerror", _arima.ArResidualError); Plot("My Indicators", "maresidualerror", _arima.MaResidualError); Plot("My Indicators", "autoregressiveintegratedmovingaverage", _arima.Current); }
# In Initialize() symbol = self.AddEquity("SPY").Symbol self.arima = self.ARIMA(symbol, arOrder, diffOrder, maOrder, period) # In OnData() if self.arima.IsReady: self.Plot("My Indicators", "arresidualerror", self.arima.ArResidualError) self.Plot("My Indicators", "maresidualerror", self.arima.MaResidualError) self.Plot("My Indicators", "autoregressiveintegratedmovingaverage", self.arima.Current)
For more information about plotting indicators, see Plotting Indicators.