I am writing my own data importer which is largely inspired by NseMarketDatcConverter. My application helps me import data for options. I was able to import data like OHLCV in a bar and pass it to the lean writer. I have not been able to figure out, how to write open interest data. Can you please point to some relevant code where OI data is being imported?
Fred Painchaud
Hi Amol,
I did not find code for that but in your custom data importer, you can add any attributes/fields you want. So you can simply add OI to it and then refer to it later on when using your custom imported data…
Like, referring to usual custom data examples:
So a field name “OpenInterest” will dynamically be created in your custom data object and the value will be taken out of the data structure created from CSV (or other) parsing. You need to know at which index your open interest data is in that index and put it instead of “some_index”.
Fred
Amol gupta
Fred
Thank you for the response. The dynamic field may be created in python but I am using C#. If you have a look at NMDC
The basic algorithm for importing data is to
-create symbol
-parse OHLCV data to bar
-Push the bar to a list
- Finally, pass the list to the lean data writer and it takes care of writing the data.
The issue is bar object does not have an open interest field. What I am guessing I need to create some other object instead of the bar, add it to list, pass list to lean data writer.
Fred Painchaud
Hi Amol,
I know C# but do not code my algos in C#. Sorry! I assumed Python…
Thanks for the example. The custom data model is much more refined on the C# side!! :) I thought it was looking at the Python one…
So.
IList<TradeBar> fileEnum = new List<TradeBar>();
If you can create custom objects instead of TradeBars, you could create an object with OHLWV and OI. And you could return that. If your object is of type CustomData, inherits from the right class, it will be seen as such by LEAN and treated accordingly.
Of course, when your algo then receives those objects, it's NOT a TradeBar so it cannot be used as-is. When your algo needs TradeBars, TradeBars would need to be created from the data inside your custom object…
So it is an overhead.
IF you can return TradeBars AND some other custom objects, then you could keep OHLCV and OI seperate - but we need to make sure that both objects stay together…. this is easy with a struct or whatever else. But then, I currently don't know what level of flexibility you have exactly with the C# side of LEAN since I have not used it a lot. I read the code so I know what to do and how in Python :).
Fred
Amol gupta
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!