Back

Customized TradeBar

Hello guys,

I'm generating my own 1-second resolution OHLC data from Tick data and storing them to my file system. My OHLC data is containing additional information usually not available from TradeBar such VWAP and more. I'm wondering what's the best way to acheive this without customizing too much Lean and avoiding potential future merge conflicts. I was tempted to inherit from TradeBar and create my CustomTradeBar data but looks like I'll need further changes to tell to Lean to use my custom data with my Custom universe selector (by default Lean is using TradeBar).

I don't want to deal with Tick data directly in Lean for performance reason.

Thanks in advance for further thoughts?

Mathieu

 

Update Backtest







0

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.


Hey Mathieu,

The best way to import your data into Lean is as custom data source. You can create a custom data type CustomTradeBar, in which you can store as many different fields as you wish, including OHLC and VWAP data. Your custom data class must inherit from BaseData, and also implement the GetSource and Reader methods.  You can learn to create a custom data source in the documentation.

public class CustomTradeBar : BaseData
{
public decimal Open = 0;
public decimal High = 0;
public decimal Low = 0;
public decimal Close = 0;
public decimal VWAP = 0;

public override SubscriptionDataSource GetSource(
SubscriptionDataConfig config,
DateTime date,
bool isLive)
{
// Provide Source for Data

}


public override BaseData Reader(
SubscriptionDataConfig config,
string line,
DateTime date,
bool isLive)
{

var bar = new CustomTradeBar();
// open, high, low, close, vwap = Parse(line);
bar.Open = open;

....

Return CustomTradeBar
}
}

Best
Rahul

0

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.


Hey Rahul unfornately, I'm already well aware of that part of Lean and it doesnt suit my needs. Maybe I wasn't clear enough so sorry for that. What I need it really to attach datapoints along with existing TradeBar. Let's say you want to know for each TradeBar how many trades happened or the VWAP for that particular bar. It doesn't make sense to go with CustomData because that info should already be part of the bar. I discussed that with Martin and there's no example doing that. So I ended up adding properties to TradeBar class and adapting the way lines are parsed to read the new values.

Regards,

Mathieu

0

Hi Mathieu Paquette ,

The objects that carry data information in Lean implements the IBaseData interface which contains the Symbol, the EndTime (DateTime object, used in the synchronization), and a Value (decimal object). Consequently, if we create data that will be represented by a custom data class with the same Symbol and EndTime of the TradeBar, it will be included in the Slice object at the same time of the TradeBar, and there is no need to be part of the same object.
This is the way that alternative data is implemented in Lean, and this is how it is used:

// Request underlying equity data.
var ibm = AddEquity("IBM", Resolution.Minute).Symbol;
// Add news data for the underlying IBM asset
AddData<TiingoNews>(ibm);

 

0

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.


Update Backtest





0

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.


Loading...

This discussion is closed