Back

Simple trading strategy, but I am having a hard time understanding how to build this.

The strategy in abstract form is simple. There are two equities ZOO and POO and I want to test 30 minute bar data.

Let X be the difference in price of POO and ZOO at a given time.

The trading order is going long ZOO and POO in an A:B ratio.

Let C be the cost of that order while ignoring market impact and only considering predicatable costs.

If X > C for the Slice :

execute the trade of going long POO and ZOO in an A:B ratio. 

If X = 0

Liquidiate net position.

Close all positions at market close.

 

Other things:

In the future, I intend to backtest this strategy comparing ZOO to a basket of POO's where the A:B ratio of the order depends on what POO actually is.

In my mind this is a toy example of pairs trading, so I imagine this is extremely simple to implementm, but I am having a hard understanding which modules I need to tweak and custom build.

Thanks in advance to anyone who even read all of this!

Best,

Roman

 

 

 

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.


What you describe is very simple and a look at the example algorithms should point you in the right direction.

The only complicating factor is your C (trading cost), which you will need to estimate. Typically, the cost of a fill can be broken down into the following blocks:

  • Bid/ask spread - you can calculate this by looking at the BidPrice and AskPrice of the security objects in question.
  • Slippage - this is hard to predict but can be estimated as some number of ticks depending on volatility and order size (in relation to average volume traded).
  • Commission to broker - given how you're simply comparing X and C, I doubt you want to take commission into account, as this depends on the order size.
Once you have calculated C, the rest should be self-explanatory. If not, please go through the Bootcamps, the example algorithms and the documentation.
2

If I understand well your strategy is mean reversion of two stocks pairs, here some examples that you can use

https://www.quantconnect.com/tutorials/strategy-library/pairs-trading-copula-vs-cointegration

https://www.quantconnect.com/tutorials/strategy-library/trading-with-wti-brent-spread

 

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