Back to Community
simulate a 3x etf

how would you do this: https://quantstrattrader.wordpress.com/2014/11/03/seeking-volatility-and-leverage/

with quantopian? I would like to simulate a 3x SPY and TLT from 2000

3 responses

I don't have the patience to work through the reference you provided, so perhaps you could summarize what is needed. I've attached an algo that simply buys SPY at 3X leverage. Is that what you need?

Clone Algorithm
11
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
def initialize(context):
    
    context.spy = sid(8554)
    
    set_commission(commission.PerTrade(cost=0))

def handle_data(context, data):

    order_target_percent(context.spy, 3.0)
There was a runtime error.

Not quite. putting 100% cash in the 3x etf cannot have a negative account balance. It would quickly converge to zero in 2008 but not go negatvie

In the Quantopian research platform, you may be able to synthesize securities, and then run backtests on them.