Back to Community
William´s VIX FIX

Trying to run a William´s VIX FIX with APPL. Runned twice. Once only with AAPL and this one buying TLT when short

Clone Algorithm
12
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.stock = sid(24)
    context.bond = sid(23921)
    schedule_function(handle_data, date_rules.every_day(), time_rules.market_close(hours = 1))  

def handle_data(context, data):  
    UB, DB  = 2.0, 0.5 
    LB = UB - DB 

    prices = data.history(context.stock, 'close',20, '1d')  
    lows = data.history(context.stock, 'low',20, '1d')  
    highest_close = prices.rolling(20, center = False).max()

    WVF = ((highest_close - lows[-1])/(highest_close)) * 100  
    
    record(WVF = WVF[-1], UB = UB, LB = LB )
    
    if WVF[-1] < LB :  
            order_target_percent(context.stock, 1.0)
            order_target_percent(context.bond, 0.0)
    
    elif WVF[-1] > UB :  
            order_target_percent(context.bond, 0)
            order_target_percent(context.bond, 1.0)
There was a runtime error.