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
Louis Szeto
Hi Joseph
It looks like you're creating a jagged array since “T” is an array but not a scalar. We suggest using the debugger to investigate “T” to make sure it is the correct input.
Best
Louis
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Joseph Matteo Scorsone
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!