Back

Creating ticks from bars/Begnning/End of day execution

The following questions only apply to historical simulations.

Given that daily bar data is more readily available historically and daily trading simulations are faster with daily data, is there a way to create open, high, low, and close ticks for the daily bar data so that these can be processed with OnTick?  

Assuming yes, a follow on question would be can the high/low ordering be changed?

Finally, is there a way to execute a a trade at the beginning/end of the day basing the trade decision on the open/close prices of daily bar data?  While not completely accurate, it is plausable to use the open/close prices and execute a trade given the same price(s) to create a reasonable simulation.

Thanks.

Update Backtest








You can use the `OnData(Tradebars data)` event handler to get tradebar data. You can specify what resolution of data you'd like using the AddSecurity/AddEquity methods. I'm not sure what you mean by change the ordering?

You can submit MarketOnOpen orders for the brokerages which support it to have your order filled by the opening bar. 

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.


I believe we are talking about different things.  For example, can OnData execute a fill on the same bar that the event is received, e.g., the make a trade decision based on the open and place a market on close on the same bar?

Regarding the MarketOnOpen orders, I'm not referring to that order type.  As an extension to my example above, a trade decision is made on the open price and an execution is made on the same price.  This is slightly different than a MarketOnOpen order because the decsion is made on the open versus the execution guaranteed.

In the above, the only available data is daily data.  Bar resolution cannot be set below daily but there are 4 ticks available: O, H, L, C for the day.  Note, that while not ideal, historical simulation sometimes is a compromise between having complete information (higher resolution data) and developing a system that is semi-realistic based upon the data that is available.
If the bar data is broken into 4 ticks and processed through OnTick, the ordering of the H and L can become important in certain systems.  

Please let me know.

Thanks.

 

0

@Duane, I believe what you are asking is not possible natively with the QC platform, but there might be a solution using the LEAN engine locally.

When backtesting with Daily resolution data, you only receive TradeBar objects in OnData, containing
Time, Open, High, Low, Close fields. When this TradeBar is emitted, the "algorithm time" is the time of the Close (i.e. the bar is complete). Although we have four data points in each TradeBar, we only have one decision point for each bar, on the Close.

Given only this information, there is no way to know with certainty whether the High happened before or after the Low: you can only guess, perhaps with some distance comparisons (such as if the Open is closer to the High than it is to the Low, then the sequence was O-H-L-C else O-L-H-C).

If I understood the question correctly, you are asking if a TradeBar can be split into 4 Ticks: 
if you use a local installation of Lean, you could certainly convert Daily data files to your own Tick resolution data files (with four rows per day instead of one) and then run a backtest using OnData(Ticks) instead of OnData(TradeBar), with the assumption that you guessed the correct H/L sequence every day.

Hope this helps

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.


@Stefano, I plan to run locally, so your solution will work but if possible, I would like to avoid converting data since it requires extra processing, coding, maintenance, 2x the storage, etc.

For completeness for anyone reading, the solution would require 6 ticks: 2 opens, H, L, and 2 closes to accomidate the trade on open price and trade on close price.

@Jared, it would be great to have this functionality native in a future release.  The solution would probably require either a setting to break the daily bar into 6 ticks (as mentioned above) or alternatively to split the daily bar into 4 ticks and add an OnBarOpening and OnBarClosing event handlers which would be called before the open and close tick, respecitively.  This would give 6 decision points for daily bar data.

Do you think this could be planned for a future release and if yes, when?

Thanks.

0

@Jared, any thoughts on my question in my last post?

Thanks.

0

@Duane this is fairly edge case and can be solved inside your algorithm with a few lines of logic when you receive the TradeBar. The general rule we apply is that if its not useful for 80-90% of the users we don't build it into LEAN but prefer to encourage you to build it into your algorithm.

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.


@Jared, Conceptually, how can this be done with a few lines of code, or any number of lines of code, in OnData or with TradeBar?  Per Stefano's comment, there is only one decision point for a TradeBar which is the close.

I'm all for doing this programmatically using TradeBars but based on the comments above I don't see a solution. 

Please advise. 

0

Using daily data; write 3-4 lines to fire any events as you like - potentially calling the OnData(Ticks) event handler.

You'll can't know what/when the Highs and Lows for the day occur until the very end of the day; so the 4 ticks you're after can't be fired until the very end of the day anyway.

If you find a way to know the high of the day the moment it happens, please let me know  :) 

OnData(TradeBars)
{
    // Break day into X ticks
    // ForEachTick -> Fire separate event handler
}

 

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.


Got it.  I'm not yet familiar with LEAN's capabilities and other platforms prevent the capability you outline.  Regarding the ordering of high/low, it is true that one cannot know when each occurs until after the day but the technique is only meant to prevent best case results when using daily data and therefore it is of use prior to the triggering of close.  Using your pseudo code and based on the system, the high and low ticks can be triggered in an order to prevent a best case result.

I will let you know the month after I figure out how to determine when the high  (or low) of the day is actually occurring.

I appreciate your insights and given the above, LEAN's capabilities w.r.t. to the use case in this post allows for great flexibility.

Thanks.

 

0

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