Hello!
I am using custom data in my backtest. I code in Python. I am using minute resolution. My data is in CSV files, one file per day, one line per minute. Each line looks like this:
Time,Open,High,Low,Close,Volume
093100,100.00000,101.00000,99.00000,100.00000,12000
So the time is HHMMSS, timezone is New York, and it is the closing time for the bar. So the example above is for the bar from 9h30 to 9h31.
I have used the Weather example in the docs and I have looked at the LEAN C# code (a whole lot 😊). So I use AddData with a custom class that inherits from PythonData and defines GetSource and Reader. The data loads fine, I can see the engine reporting missing files (some days are missing in my data within my algo start and end times) and if I add a print() in my Reader method, I can also see a whole lot of prints in the console (each minute bar that gets loaded).
The problem is that my algo's OnData method's slice param never includes data for my custom ticker (associated to my custom data). This code is always false:
data.ContainsKey(self.custom_symbol) and data[self.custom_symbol] is not None
When I debug, I can see that the slice only contains 1 item, which is an Equity my algo also subscribe to (I do AddEquity for some other ticker). So what is false is actually the first condition (ContainsKey). It appears that LEAN reads my data fine but then it does not serve it to my algo.
Here is what I tried so far:
1- I tried to set the TimeZone of the algo to America/New York thinking that maybe the local engine I am using is UTC by default (from the logs I could see it was New York but tried anyway). No luck.
2- I tried in my custum data class to use:
a) 9h31 as the Time for the returned object by Reader.
b) use 9h30 (so report the start time of the bar instead of the end time).
c) use 9:30:30, so substract 30 seconds (using “- timedelta(seconds=30)”) from the end time to tell LEAN that the data is within the 9h30-9h31 minute.
All with no luck.
Does anyone have a clue why the engine does not feed my custom data to my algo OnData?
Thanks!
Fred
Fred Painchaud
Alright so I answer my own questions… for those who might have the same issue in the future.
So I was parsing the time, like 093100 (9h31) but I was not setting the date for that time, so it was Jan 1st 1970 (Unix epoch). LEAN was not feeding the custom data to my algo since it was for 1970 and my backtest starts in 2016…
Fred
Fred Painchaud
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!