I'm currently testing my algorithm with custom data, when I use .csv file everything works fine but when I try to switch to a zip file I get this error.
I can't find any reference code for using a zip file and would appreciate your help, this is the custom data class.
class MyCustomDataType(PythonData):
def GetSource(
self, config: SubscriptionDataConfig, date: datetime, isLive: bool
) -> SubscriptionDataSource:
return SubscriptionDataSource(
"https://www.dropbox.com/s/brwzhl2wgl13qx0/SNAP.zip?dl=1",
SubscriptionTransportMedium.RemoteFile,
FileFormat.ZipEntryName,
)
def Reader(
self, config: SubscriptionDataConfig, line: str, date: datetime, isLive: bool
) -> BaseData:
if not (line.strip() and line[0].isdigit()):
return None
index = MyCustomDataType()
index.Symbol = config.Symbol
# Example File Format:
# Date Open High Low Close Volume Turnover
# 2023-01-17 11:30:00-05:00 7792.9 7799.9 7722.65 7748.7 116534670 6107.78
data = line.split(",")
index.Time = datetime.strptime(data[0][:-6], "%Y-%m-%d %H:%M:%S")
index.EndTime = index.Time + timedelta(seconds=1)
index.Value = float(data[4])
index["Open"] = float(data[1])
index["High"] = float(data[2])
index["Low"] = float(data[3])
index["Close"] = float(data[4])
index["Volume"] = float(data[5]) * 100
return index
Nico Xenox
Hey Kyrillos Boshra,
you will have to do the followings things to make it work:
Hope it helps ;)
Best,
Nico
Kyrillos Boshra
I found in the documents that I can use zip file, I have no problem using a csv but the file size is too large and the backtesting takes so much time, can you elaborate more because I don't understand your proposed solution or you completely misunderstood what I'm asking for
Nico Xenox
Hey Kyrillos Boshra,
could you please provide the page were you read that? I think that the only way to load custom data was trough a csv file.
Best,
Nico
Kyrillos Boshra
https://www.quantconnect.com/docs/v2/writing-algorithms/importing-data/streaming-data/key-concepts#04-Set-Data-Sources
this part
Nico Xenox
Hey Kyrillos Boshra,
sorry for the long wait. I think you have to add the csv file ("SNAP.csv") to the file format:
Best,
Nico
Ak Trading
Nico Xenox
Ak Trading,
would you mind sending the code?
Ak Trading
Nico Xenox
Hey Ak Trading and Kyrillos Boshra,
sorry I dont know how to solve this I tried multiple things but apparently these doesnt work.
It does work though only using the csv file…
Kyrillos Boshra
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!