Hello,

is there any documentation on how to use ARIMA models on securities forecasting? Im trying to build something basic, but im not sure if for instance the self.arima.current.value is a forecast or not, also it seems that the model is not warming up…. The goal would be an ARIMA that updates itself with every bar, and would make a prediction with the stock price.

 

Best

Álvaro

 

 

 

from clr import AddReference

AddReference("System")
AddReference("QuantConnect.Algorithm")
AddReference("QuantConnect.Common")

from System import *
from QuantConnect import *
from QuantConnect.Algorithm import *

# <summary>
# Regression algorithm to test the behaviour of ARMA versus AR models at the same order of differencing.
# In particular, an ARIMA(1,1,1) and ARIMA(1,1,0) are instantiated while orders are placed if their difference
# is sufficiently large (which would be due to the inclusion of the MA(1) term).
# </summary>
class AutoRegressiveIntegratedMovingAverageRegressionAlgorithm(QCAlgorithm):
    def Initialize(self):
        '''Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.'''
        self.SetStartDate(2021, 10, 1)
        self.SetEndDate(2021, 10, 20)
        
        self.EnableAutomaticIndicatorWarmUp = True
        self.SetCash(10000000)
        self.ticker = self.AddCrypto("BTCUSD",Resolution.Minute)
        #self.ticker = self.AddEquity("SPY", Resolution.Daily)
        
        #self.setBenchmark("SPY")
        
        
        self.arima = self.ARIMA(self.ticker.Symbol, 1, 1, 1, 50)
        self.ar = self.ARIMA(self.ticker.Symbol, 1, 1, 0, 50)
        


    def OnData(self, data):
        '''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.

        Arguments:
            data: Slice object keyed by symbol containing the stock data
        '''
        if self.arima.IsReady:
            if self.arima.Current.Value > self.Securities[self.ticker.Symbol].Close and self.Portfolio.Invested == 0:
                self.SetHoldings(self.ticker.Symbol,1)
            elif self.Portfolio.Invested > 0 and self.arima.Current.Value < self.Securities[self.ticker.Symbol].Close:
                self.Liquidate()
            
        
        
        #    if abs(self.arima.Current.Value - self.ar.Current.Value) > 1:
        #        if self.arima.Current.Value > self.last:
        #            self.MarketOrder("SPY", 1)
        #        else:
        #            self.MarketOrder("SPY", -1)
        #    self.last = self.arima.Current.Value
            
        #self.Plot('SPY', self.Securities[self.ticker.Symbol].Close)
        self.Plot('BTCUSD',self.Securities[self.ticker.Symbol].Close)
        self.Plot('AR',self.ar.Current.Value)
        self.Plot('ARIMA',self.arima.Current.Value)

 

Best

Alvaro