Back to Community
n

jj

Clone Algorithm
1
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.stocks= [ sid (3214) , sid (3384) , sid (3443) , sid (3695) , sid (4010) , sid (3766) ,
    sid (3971) , sid (4263) , sid (4297) , sid (5035) , sid (5029) , sid (5442) ,
    sid (5387) , sid (5729) , sid (4118) , sid (5885) , sid (5923) , sid (5792) ,
    sid (5773) , sid (6116) , sid (5938) , sid (6583) , sid (6928) , sid (7011) ,
    sid (7800) , sid (7761) , sid (7883) , sid (21964) ]
    context.weight = 1.0 / len (context.stocks)
    context.re_invest = True
    set_commission(commission.PerShare(cost=0.005, min_trade_cost=1))
    set_slippage(slippage.FixedBasisPointsSlippage(basis_points=5, volume_limit=0.025))

def handle_data (context, data):
    for sym in context.stocks:
        if sym in data and context.portfolio.positions[sym].amount == 0:
            order_percent (sym, context.weight)
            
    if context.re_invest:
        cash = context.portfolio.cash
        cost = sum ([data[i].price for i in context.stocks if i in data])
        if cash > cost:
            for sym in context.stocks:
                if sym in data:
                    order(sym,1)
    record(cash = context.portfolio.cash, positions =  context.portfolio.positions_value)
There was a runtime error.