Back to Community
Live trading not tracking backtesting

I have two algos running in live Quantopian paper trading mode. Unfortunately, neither are tracking the current backtest results. Both of these algos were "borrowed" from other users.

I've attached one example. In live mode, 277 shares of XIV was purchased on 8/25. The backtest shows the current position should be half AGG and half XIV.

I'm at a loss as to how to troubleshoot this and fix it.

I've got another algo also not tracking the backtest -- also a volatility-based system for what that may mean.

Clone Algorithm
Backtest from to with initial capital
Total Returns
Max Drawdown
Benchmark Returns
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
import pandas as pd
import numpy as np
import math
from quantopian.pipeline import Pipeline
from quantopian.algorithm import attach_pipeline, pipeline_output
from import USEquityPricing
from quantopian.pipeline.factors import CustomFactor
from import yahoo_index_vix

NDays = 5

class ImpliedVolatility(CustomFactor):
    inputs = [yahoo_index_vix.close]
    def compute(self, today, assets, out, vix):
        out[:] = np.mean(vix, axis=0) # NB one identical column for every asset
        #out[:] = np.mean(vix) # Does same as above, but more correct for ANTICIPATE CHANGE:

def initialize(context):
    context.vxx = sid(38054)
    context.xiv = sid(40516)
    context.uvxy = sid(41969)
    context.spy = sid(8554) = sid(25485)
    pipe = Pipeline()
    attach_pipeline(pipe, 'example')
    iv = ImpliedVolatility(window_length=NDays)
    pipe.add(iv, 'iv')

def before_trading_start(context, data):

    output = pipeline_output('example')
    output = output.dropna() #makes a copy
    iv = output["iv"].iloc[0]
    hv = calculate_hv(context, data, NDays)  

    context.vrp = iv-hv


def calculate_hv(context, data, days):    
    close = data.history(context.spy, ["price"], days+1, "1d")
    close["ret"] = (np.log(close.price) - np.log(close.price).shift(1))
    return close.ret.std()*math.sqrt(252)*100

def allocate(context, data):
    if context.vrp > 0:
        order_target_percent(context.vxx, 0)
        order_target_percent(context.uvxy, 0)
        order_target_percent(context.xiv, .5)
        order_target_percent(, .5)
        order_target_percent(context.vxx, .5)
        order_target_percent(context.xiv, 0)
        order_target_percent(context.uvxy, 0)
        order_target_percent(, .5)
There was a runtime error.