Hi,
When using local data files, what is the recommended way of splitting them up?
Is it possible to use data files that are split up by month?
The `GetSource` function of TradeBar class seems to get a date parameters of types: typing.Union[datetime.datetime, datetime.date], but wasn't sure from documentation (below) that this enables splitting up files in a monthly (or anything else than daily) fashion.
def GetSource(self, config: QuantConnect.Data.SubscriptionDataConfig, date: typing.Union[datetime.datetime, datetime.date], isLiveMode: bool) -> QuantConnect.Data.SubscriptionDataSource:
"""
Get Source for Custom Data File
>> What source file location would you prefer for each type of usage:
:param config: Configuration object
:param date: Date of this source request if source spread across multiple files
:param isLiveMode: true if we're in live mode, false for backtesting mode
:returns: String source location of the file.
"""
Any help is appreciated
Fred Painchaud
Hi Notta,
Yep, it's possible. Here is the rationale:
1- The param “date” is the datetime that LEAN is looking data for (depending on resolution - it can be just a date (Daily) or a date and time (Intraday).
2- When the source inside the SubscriptiongDataSource object you return changes, LEAN gets that it needs to load that new source. Then it reads the first line and send to Reader.
3- If the source is the same, it reads the next line and sends to Reader.
So, in a nutshell, return a new source when the month in date changes. Naming your files with years and months would do it and using the year and month in date to coerce the right filename…
The lines in your monthly files need to be in-sync with the resolution you use (seconds, minutes, hours, whatever).
Be careful around Time and EndTime/Period in Reader / wrt what you have in your file or you won't receive the right data at the right time and most people don't even notice since the algo runs…
Fred
Nottakumasato
Fred Painchaud thank you for the prompt answer. Ok so using strftime(FILE_NAMING_SCHEME) I can call the correct file to be read. As a concrete example: With data of resolution of 1 minute, I can put a month's worth of data into a single file with the filename XXX-[MONTH].csv and then just do
to read it within GetSource?
Could you also elaborate on “Be careful around Time and EndTime/Period in Reader / wrt what you have in your file or you won't receive the right data at the right time and most people don't even notice since the algo runs…” ?
I have not been using EndTime for some of the data sources I had since sometimes the data is irregular. Do I have to specify EndTime for all classes inheriting from TradeBar class?
Also for those datasets that I can specify an EndTime, should I be wary of the timezone of the data? Is that what you are referring to in your comment about endTime/Period?
Fred Painchaud
Hi Notta,
Here is an example.
Those files are divided into days but you get the idea. Your line of code is correct.
Note that my files contain end time at minute resolution but .Time is start time. For equity, the time must be in the time zone of the market. If you set .Time and .EndTime, you do not need to set .Period. Or you can set .Time and .Period.
Don't forget to set .Value if you want to trade that custom data.
Fred
Nottakumasato
Fred Painchaud I see, thank you for the detailed answer!
Nottakumasato
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!