Back to Community
SPY constant volatility w/ dynamic leverage (Quantapolis)

Hi Quantopians,

Here's the second bare-bones strategy example, this time about ex-ante volatility targeting. In a way it's a simple version of this and demonstrates the immediate benefits of volatility scaling in both rough and calm waters - which is why it's frequently used for position sizing in more complex trading strategies.

We're also rolling out the public beta for in-wiki voting on quantapolis.com. It's pretty wild - you can check it out on the "Algorithms" page. (You'll need to create an account for now until we figure out an efficient way to combat bot spamming)

The previous bare-bones example in the series can be found here:
Value Example (long-short)

Clone Algorithm
26
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 55cb9593a512050c73343435
There was a runtime error.
5 responses

Also, here's a simple mod of the strategy with a trend-filter for graceful scale-out and an allocation to bonds if the equity leverage drops below 1.0. It's an easy way to smoothen returns when markets are in turmoil.

Clone Algorithm
44
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 55ce46efc210150c6b285e9e
There was a runtime error.

Nice algo results, Origin!

Unfortunately, I don't fully understand what you are doing. If you could add more comments, I'm sure several of us beginners could learn how to do more advanced algos.

BTW, I created a wiki account on your site with the intention to help vote on algos like this one. :)

Tristan

Hi Tristan, glad you like it.

The algo here really is a code template. It shows a building block of some of the algorithms shared by Quantopian pros in the past. I use the inverse of the 21-day standard deviation for position sizing - intuitively, the more SPY jumps around, the fewer shares I hold. Other approaches, such as Average-True-Range (ATR) do a similar job. The trend filter then prevents the algorithm from increasing its position in SPY should the market be below the 200-day moving average.

I'll add more comments to future examples so they're easier to follow.

Thanks for the explanation, it really helps!

I tried various backtests with different inputs into your algorithm and this is the best improvement I got. (Depending on your scoring metric, it may not be better, with higher volatility and drawdown)

Is it a good idea to optimize inputs like this, or is it just curve-fitting the backtest?

Clone Algorithm
31
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 55d110c038669b0c631c0d62
There was a runtime error.