Hello! I am trying to use AI to help me with the Tauchen and Pitts model however I am getting an issue I can't resolve regarding arrays. “Setting an array element with a sequence”.  It is in the function SimulationPrices. If someone can help that would be very appreciated I plan on making a YT video about this whole program if it works.

 

# region imports
from AlgorithmImports import *
import numpy as np
# endregion

class TauchenPittsAlgorithm(QCAlgorithm):
    def Initialize(self):
        # Set the Start and End Date
        self.SetStartDate(2021, 1, 1)
        self.SetEndDate(2021, 12, 31) 

        # Set the S&P 500 Futures 
        self.SetCash(100000)
        self.symbols = self.AddFuture(Futures.Indices.SP500EMini, extendedMarketHours= True).Symbol

        self.SetBenchmark(self.symbols)
        self.Schedule.On(self.DateRules.EveryDay(self.symbols), self.TimeRules.AfterMarketOpen(self.symbols,5), self.TauchenPittsModel)

    def TauchenPittsModel(self):
        # Tauchen-Pitts Process
        # Tauchen & Pitts (1986) discretization of GBM
        # (Stochastic Volatility Model)
        # 
        # Parameters
        mu = 0.1     # drift
        sigma = 0.2  # volatility
        N = 10       # states

        # Calculate the standard deviation of the shocks
        stdev_shocks = (sigma * (1 - ((2 * mu * N) / (sigma ** 2)))) ** 0.5

        # Construct the transition matrix
        transition_matrix = np.zeros(shape=(N,N))
        for i in range(N):
            for j in range(N):
                transition_matrix[i,j] = np.exp(((1 / stdev_shocks) * ((2 * j + 1) - N)) + (mu - (sigma ** 2) / 2))
 
        # Compute the prices 
        prices = self.SimulationPrices(transition_matrix, N)

        # Plot the prices
        self.Plot(prices, 'Tauchen_Pitts')

    def SimulationPrices(self, T, N):
        M = 1000
        prices = np.zeros(shape=(M,N))
        for i in range(M):
            prices[i,0] = 50
            for j in range(N-1):
                prices[i,j+1] = T[j] * prices[i,j]
        return prices