I'm planning to build up this algorithm, bit-by-bit here. This is the first piece. More details to come. --Grant

Clone Algorithm

155

Loading...

There was an error loading this backtest.
Retry

Backtest from
to
with
initial capital

Cumulative performance:

Algorithm
Benchmark

Custom data:

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 |

import numpy as np # globals for get_data batch transform decorator R_P = 0 # refresh period W_L = 5 # window length in days (390*W_L minutes) def initialize(context): context.stocks = [sid(21519),sid(8554)] def handle_data(context, data): # get shifted moving average avg = get_avg(data,context.stocks) if avg == None: return mavg_0 = data[context.stocks[0]].mavg(3) mavg_1 = data[context.stocks[1]].mavg(3) window = 3*390 # minutes print data[context.stocks[0]].datetime print avg.shape print avg print avg[window-1,0]-mavg_0 print avg[window-1,1]-mavg_1 @batch_transform(refresh_period=R_P, window_length=W_L) # set globals R_P & W_L above def get_avg(datapanel,sids): p = np.flipud(datapanel['price'].as_matrix(sids)) p_cumsum = np.cumsum(p,axis=0) n = np.cumsum(np.ones(p_cumsum.shape),axis=0) avg = np.divide(p_cumsum,n) return avg

This backtest was created using an older version of the backtester. Please re-run this backtest to see results using the latest backtester. Learn more about the recent changes.