Back

Coding our Trading Bot in QuantConnect - Trading Bot in Python #5

Hi everyone,

Attached below is the algorithm used in episode 5 of the Trading Bot in Python series. As you can see this backtest is what we will be reviewing in episode 6.

In a comment below I've also attached the algorithm framework version.

Enjoy!

Ollie

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.


Here is the algorithm framework version. Many thanks to Jared for help with this.

1


Hi Ollie,

Thanks for sharing and also great series on YouTube!

In the Algorithm Framework version, within the Alpha module I think you forgot to pass the 'direction' variable to Insight.Price? You're passing InsightDirection.Up for all symbols it seems.

A suggestion for the QC team, for this type of Long-Short Equity strategies, it would amazing to be able to build the factor model within the Universe and flag the longs and shorts separately when sent to the Alpha module so we don't have to re-calculate and find out which symbol was long and which was short. What do you think Guys?

Thanks!

Emilio

InnoQuantivity.com

3

Hi Emilio,

Good spot! Thanks for pointing out the direction problem, I've attached a corrected algorithm.

With regards to defining longs and shorts within universe selection - I think that would work best if you were doing some type of screen, such as a Piotroski F-Score screen to define the longs and shorts rather than factor modelling in universe selection. Unless you were equally weighting your portfolio you would have to calculate the factor again to get weightings anyway and by just adding in one more factor you won't know whether you would be long or short until you calculated your alpha scores. In my opinion ideally you don't want to introduce factor criteria into your universe selection and instead maximise the amount of stocks (that meet liquidity/sector criteria) you pass through to your alpha generation to not negatively impact calculations such as producing z-scores. However, this produces a problem for backtests with frequent rebalances.

Having said that I do think this feature could be useful for screens. It could allow you to not have to recalculate f-scores if you wanted to calculate separate z scores for your long (investment grade) stocks (say f-scores of 8-9) and your short (junk?!) stocks (0-2).

I'd love to hear if you have any more thoughts on this Emilio. Maybe this warrants a separate discussion on the forum?

Many thanks,

Ollie

1


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