Hi All,
I'm using custom data. A lot of it is actually trading data - plain good old OHLCV bars/candles.
It just came to me that instead of using the usual way, documented here https://www.quantconnect.com/docs/algorithm-reference/importing-custom-data, basically returning a custom class object to encapsulate your custom data and then having to look into the fields of that custom object to access your data, if your custom data is basically TradeBar, you can simply return a TradeBar object that you create from your custom data, as such:
class MyCustomData(PythonData):
def GetSource(self, config, date, isLive):
source = "My source goes here for the given date"
return SubscriptionDataSource(source, SubscriptionTransportMedium.LocalFile) # Could also be remote
def Reader(self, config, line, date, isLive):
data = line.split(",")
return TradeBar(<Use data fields, for instance data[0], date and datetime.strptime() to compute the correct date and time for the beginning of the bar>, config.Symbol, float(data[1]), float(data[2]), float(data[3]), float(data[4]), float(data[5]), <Use timedelta to provide the period of the bar, for instance timedelta(minutes=1)>)
Then, when LEAN gives you your custom data, for instance in OnData, it is already TradeBar instead of your custom object, from which, oftentimes, you need to create a TradeBar anyway.
I guess I was somewhat blinded by the custom data documentation and did not think about it before now. Good thing if everyone else already thought about it. Also good thing if this helps at least one mate out there.
Fred
Fred Painchaud
Sorry. This works fine until you use your custom data TradeBar into Lean where the symbol signals a type of DynamicData (the type for custom data which gets attributed to your symbol by AddData()). Then, it fails as TradeBar is not DynamicData, of course.
Got excited before I fully tested the idea across the board in all my strategies…
So… this becomes a post about making sure you do not do this 😊. Except if you are willing to do a lot of what is provided by “helper methods” manually.
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!