Hi everyone,

First of all i don't really have a background in programming so i really don't know what i'm doing, i only use chatgpt to help me out with understanding the code and trying to fix it if there is an error. I'm trying to import the moroccan all shares index (MASI) from this website https://www.investing.com/indices/masi-historical-data


when i run the code below, it doesn't bring up any error, but it also doesn't show and trading results, it's completey blank. I would really really appreciate if someone can help me out because this is for a project i'm working on for my studies. I'm basically trying to test a pre established Deep Learning protfolio optimization code made by a quantconnect user https://github.com/shilewenuw/deep-learning-portfolio-optimizationhttps://github.com/shilewenuw/deep-learning-portfolio-optimization


Only thing i need to change for my test is the historical data in "main.py" as mentionned previously i want to incorporate the MASI index and test it using the Deep Learning algorithm.

I'm sorry if i sound stupid, i'm a complete noob.

Here is the "main.py" provided my chatgpt that doesn't seem to show any result :

from AlgorithmImports import *
class MASIIndexData(PythonData):
'''MASI Custom Data Class'''
def GetSource(self, config: SubscriptionDataConfig, date: datetime, isLiveMode: bool) -> SubscriptionDataSource:
# Replace this path with the actual path to your CSV file
path = r'C:\users\hp\OneDrive\Documents\Moroccan All Shares Historical Data'
return SubscriptionDataSource(path, SubscriptionTransportMedium.LocalFile)
def Reader(self, config: SubscriptionDataConfig, line: str, date: datetime, isLiveMode: bool) -> BaseData:
if not (line.strip() and line[0].isdigit()): return None
# Create a new MASIIndexData object
masi_data = MASIIndexData()
masi_data.Symbol = config.Symbol
try:
# Example File Format:
# Date     Price    Open     High      Low            Vol          Change
# 2023-09-01  12050.0  12000.0  12100.0  11950.0  12345678  100.0
data = line.split(',')
masi_data.Time = datetime.strptime(data[0], "%Y-%m-%d")  # Date format updated
masi_data.EndTime = masi_data.Time + timedelta(days=1)
masi_data.Value = float(data[1])  # Price
masi_data["Open"] = float(data[2])
masi_data["High"] = float(data[3])
masi_data["Low"] = float(data[4])
masi_data["Volume"] = float(data[5])
masi_data["Change"] = float(data[6])
except:
pass
return masi_data
class MyAlgorithm(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2012, 1, 1)  # Set Start Date
self.SetEndDate(2023, 9, 7)  # Set End Date
self.SetCash(100000)  # Set Strategy Cash
# Add the custom data source MASIIndexData
self.AddData(MASIIndexData, "MASI")
n_periods = 50
self.data = RollingWindow[Slice](n_periods)
self.Train(self.DateRules.MonthStart("MASI"), self.TimeRules.Midnight, self.Rebalance)
self.model = None
self.SetWarmup(n_periods)
self.prev_day = -1
def OnData(self, slice):
# this prevents duplicate bars that sometimes occurs because of SetWarmUp
if self.prev_day != self.Time.day:
self.data.Add(slice)
self.prev_day = self.Time.day
def Rebalance(self):
if not self.data.IsReady:
return
try:
# since RollingWindow is recent at top, we need to reverse it
data = self.PandasConverter.GetDataFrame(self.data).iloc[::-1]
except:
return
# No need to turn the closing prices for custom data into columns
# You can access the custom data directly
if self.model is None:
self.model = Model()
# Pass the custom data to your model for optimization
allocations = self.model.get_allocations(data)
self.Log(f'Portfolio Allocations: {allocations}')
# Adjust the code to set holdings based on the custom data
self.SetHoldings("MASI", allocations[0])  # Assuming MASI is the first and only custom data in the listussion