Back

Simple Algo: Trades TQQQ/SQQQ based on volatility.

Use at your own risk.

Update Backtest








Here's the same algo set to trade after hours as well. It looks like a lot of the after hours trades are being changed into MarketOnOpen trades. Anyone know why? Is this a bug in Quantconnect?

0


Its not a bug. SetHoldings uses market orders -- which can only be done during market hours.

If you'd like to use premarket data you need to use LimitOrders.

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.


Thanks Jared.

0

Nice, I like how short this is. Simple systems are often the most powerful.

QQQ/PSQ are unlevered versions of this (should still use TQQQ as volatility input to preserve behavior). IB handles levered ETFs by upping margin requirements correspondingly. Then again, trading levered ETFs can reduce fees. Idea; Might be possible to short opposite levered ETF than going long due to decay, depends on borrowing costs.

Using QQQ rather than TQQQ as volatility input highlights some important points regarding 1.2 as a magic value:

  • Results with this change gets some massive draw downs (see attached backtest). I think varying the constant in the neighborhood around 1.2 and see how results change would be wise. Both to check how sensitive the system is to this parameter, and to discover potential future drawdown scenarios that are masked by the insample test period.
  • Comparing standard deviation of price versus a fixed value of the same unit (price) won't work in the long run if price grows away from that unit, but system can (and probably should) be re-optimized before long run happens.
Overall, were I to trade this, I would definitely add logic to guard against drawdowns, even if it eats up some profit.
1


Thanks Petter. It's just a simple script that is mostly useful for backtesting at this point.  It shows that there might be some merit to analyzing volatility as the backtest beats the TQQQ. There's no position sizing that takes dollar volume limitations into account so the backtest will show falsely positive results for large initial cash settings. There's no slippage modelling either but I doubt slippage will make much of a difference for small to medium size accounts given the trade frequency and liquidity of the stocks involved. Petter is right about the drawdowns and altering the 1.2 value, there are serious problems there. I'ld definitely consider adding some type of stoploss before trading it.

0

Nice work Warren!

I've made a few changes to the algo. I'm also jsut getting familiar with C# and the Lean API on QC being a Quantopian migrant

Changes made: 

1. Allows trading of multiple leveraged ETF pairs with the ability to independantly set up standard deviation constants for each of the pairs based on research or bactests; you original version was hard coded to 1.2, if I remember correctly. There may be overfitting in this case. Equal weights assigned to all ETF pairs. The arrays defined can take upto 10 ETF pairs.

2. Set the data normalization mode to raw to avoid look ahead bias and adjustments for reverse splits.

Note: The start date reflects the earliest that all pairs ( 2 in this example) were available for trading. If you plan to go further back you might not get results as expected.

The drawdown is quite crazy for this test run. The biggest one being on the Black Monday of August 24th, 2015. Definitely not for the faint of heart. 

1


^ That basically looks typical of being highly levered in market all the time, i.e. it's going to be "exciting" like heck.

Although, the volatility relationship to returns is the core question here and it's probably better to do "some" statistical test on cross correlation (ahem, here's where I can't help you without searching around a bit due to gap of knowledge, too late at night for that) without even creating a backtest. Research environment ftw and I'm starting to realize it's going to be a huge time saver.

I mean, it is a common sense hypothesis positive returns should show correlation with lower volatility, at least for some market regimes. Someone probably already researched it to death as well, so it might be worth going PDF hunting before anything else.

My first post was a fairly lazy in that I didn't take any stance myself beyond saying "go study it yourself you're going to use it", it would be interesting if someone did do a proper statistical study however. :-) For a statistically illiterate bastard like me it's probably worth doing for practice if nothing else. If I find the time then I might

0

I've a "common sense" statistics bent of mind as well. No real formal training there. Just reading up on whatever I can find.

I'd like to play around with this some more. Like you said Petter, adding in some sort of stop loss would be nice, and have it resume when saner conditions prevail. Unlike Quantopian, I've found it hard to find "fun" algos to play with and learn from; But Warrens' posted algos have been pretty sweet. That being said, here's what I'd like to do, and maybe we can bounce ideas around.

1. Play around with

a) some sort of leading indicator that might indicate the sudden downswing and using that either reduce the allocation or temporarily move to cash or a safe haven ETF like TLT or

b) jsut a vanilla stop loss and restart when things have calmed down a bit.

2. looking at the logic for switching between the Lev ETF and it's inverse it's only based on the standard deviation being above or below a threshold. There is a scenario where the volatility is in our favour, but at a rate that puts the std dev above a threshold, and we really don’t want to switch over to the inverse ETF yet.

There are a few other tweaks/ideas, but that can come once I make these adjustments.

0

Hello John, on your points:

1. Related, if you look at stock indices they tend to move in parabolic movements, where the slow down at the end is accompanied by increasing indecisiveness (whether volatility is lower, higher or unchanged is however an open question). As for adjusting risk, I guess the most popular simple method is scaling position by the inverse of standard deviation.

2. Maybe. It's really easy to overfit, though.

Overall though, I'm not too optimistic on finding alpha exploring obvious ideas that everywhere else have tried. However, there is certainly value in navigating beta in a more intelligent manner than B&H.

Did study/slack through ~1.5 intro years in maths and stats in uni for the engineering programme I attended, but I find it's not nearly enough to do this at a scientific level (especially not after basically programming full time in my work years), so I'm on a gradual coarse to correct that. Obviously, deeper statistics would have been beneficial.

0

Valid points, but here's a backtest. I added in a basic directional indicator using ADX with DI+/- to indicate movement. I haven't had time to dissect it; jsut been swamped for the last couple days with my regular day job. But feel free to poke around. It seems that the trading frequency has dropped a lot. trading fees are under 5k on a $1,000,000 starting capital.  Might make sense for folks (given the appetite for risk; this has a 50% DD) trading in an account that have pattern day trader or taxman restrictions. I've kept the base pairs to TQQQ/SQQQ to maintain consistency for comparison purposes, but that can easily be changed.

Still thinking about some sort of stop loss function that makes sense for violently volatile ETFs. Maybe I'll post something here if I can make it work.

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