The ATR of is calculated using closing prices, which were around -60 in the 20 days leading up to the calculation date of 2007-12-05. As far as I can tell, the divisor is the total value of the portfolio including any cash.

So this is a huge concentration, which doesn't seem right.

Further to this, I note this algorithm uses pipeline, which adjusts for splits and dividends very differently from the old backtester: https:// It seems the ATR is calculated correctly using prices .

However, it seems the order_target function is using the old backtester paradigm of back-adjusting the data for all past and future splits, before the algorithm starts.

From the charts it looks to be around end of 2007 when SPY falls below its 200 day moving average, and the algorithm stops entering new positions.

Secondly, there do seem to be times the leverage jumps above 1.Top 10 long positions of all time (and max%) [u' LIFE' u' GENZ' u' AGN' u' TLD' u' AGNC' u' ELE' u' NTT' u' T' u' YPF' u' TXU'] [ 0.545 0.11 0.107 0.103 0.102 0.101 0.101 0.099 0.098 0.097] # Implementation of the Stocks On The Move system by Andreas Clenow # import numpy as np import pandas as pd import scipy.stats as stats import time from quantopian.pipeline import Pipeline from quantopian.pipeline import Custom Factor from quantopian.import morningstar from quantopian.pipeline.factors import EWMA, Latest, Simple Moving Average from quantopian.builtin import USEquity Pricing from quantopian.algorithm import attach_pipeline, pipeline_output import talib as talib Universe Size = 500 Daily Range Per Stock = 0.001 # targeting 10bp of account value Rebalance Threshold = 0.005 # don't rebalance if the difference is less than 50bp of account value # This is the momentum factor, which is the 'slope' of an exponential regression # (ie a linear regression of logarithms), multiplied the the R-Squared of that regression class Momentum(Custom Factor): inputs = [USEquity Pricing.close] window_length = 90 def compute(self, today, assets, out, close): x = pd.T), dtype=np.float64) for i in range(0,len(assets)): if (cap_ranks[i] filtered['sma100' return filtered def before_trading_start(context, data): results = pipeline_output('sotm').sort('momentum_rank') filtered = filter_pipeline_results(results) = filtered update_universe(filtered.index) def sell_positions(context, data): cash_freed = 0.0 s = "" for sid in context.portfolio.positions: position = context.portfolio.positions[sid] cash_worth = position.amount * position.last_sale_price # anything not in the pool of allowed stocks is immediately sold if ((sid not in index) & (sid in data)): s = s "%s, " % sid.symbol order_target_percent(sid, 0.0) cash_freed = cash_freed cash_worth log.info(s) return cash_freed def calculate_atr(context, data, sid): highs = history(21, '1d', 'high')[sid] lows = history(21, '1d', 'low')[sid] closes = history(21, '1d', 'close_price')[sid] return talib.In a live trading algorithm, the stored variable needs to have the split applied to the price and volume.In a backtest, the split is already applied retroactively to all data.For example, right at the end of 2012, the leverage increases briefly to 1.2x I will look into it more.

||

Secondly, there do seem to be times the leverage jumps above 1.

Top 10 long positions of all time (and max%) [u' LIFE' u' GENZ' u' AGN' u' TLD' u' AGNC' u' ELE' u' NTT' u' T' u' YPF' u' TXU'] [ 0.545 0.11 0.107 0.103 0.102 0.101 0.101 0.099 0.098 0.097] # Implementation of the Stocks On The Move system by Andreas Clenow # import numpy as np import pandas as pd import scipy.stats as stats import time from quantopian.pipeline import Pipeline from quantopian.pipeline import Custom Factor from quantopian.import morningstar from quantopian.pipeline.factors import EWMA, Latest, Simple Moving Average from quantopian.builtin import USEquity Pricing from quantopian.algorithm import attach_pipeline, pipeline_output import talib as talib Universe Size = 500 Daily Range Per Stock = 0.001 # targeting 10bp of account value Rebalance Threshold = 0.005 # don't rebalance if the difference is less than 50bp of account value # This is the momentum factor, which is the 'slope' of an exponential regression # (ie a linear regression of logarithms), multiplied the the R-Squared of that regression class Momentum(Custom Factor): inputs = [USEquity Pricing.close] window_length = 90 def compute(self, today, assets, out, close): x = pd.

T), dtype=np.float64) for i in range(0,len(assets)): if (cap_ranks[i] filtered['sma100']] return filtered def before_trading_start(context, data): results = pipeline_output('sotm').sort('momentum_rank') filtered = filter_pipeline_results(results) = filtered update_universe(filtered.index) def sell_positions(context, data): cash_freed = 0.0 s = "" for sid in context.portfolio.positions: position = context.portfolio.positions[sid] cash_worth = position.amount * position.last_sale_price # anything not in the pool of allowed stocks is immediately sold if ((sid not in index) & (sid in data)): s = s "%s, " % sid.symbol order_target_percent(sid, 0.0) cash_freed = cash_freed cash_worth log.info(s) return cash_freed def calculate_atr(context, data, sid): highs = history(21, '1d', 'high')[sid] lows = history(21, '1d', 'low')[sid] closes = history(21, '1d', 'close_price')[sid] return talib.

In a live trading algorithm, the stored variable needs to have the split applied to the price and volume.

In a backtest, the split is already applied retroactively to all data.

For example, right at the end of 2012, the leverage increases briefly to 1.2x I will look into it more.

||

Secondly, there do seem to be times the leverage jumps above 1.

Top 10 long positions of all time (and max%) [u' LIFE' u' GENZ' u' AGN' u' TLD' u' AGNC' u' ELE' u' NTT' u' T' u' YPF' u' TXU'] [ 0.545 0.11 0.107 0.103 0.102 0.101 0.101 0.099 0.098 0.097] # Implementation of the Stocks On The Move system by Andreas Clenow # import numpy as np import pandas as pd import scipy.stats as stats import time from quantopian.pipeline import Pipeline from quantopian.pipeline import Custom Factor from quantopian.import morningstar from quantopian.pipeline.factors import EWMA, Latest, Simple Moving Average from quantopian.builtin import USEquity Pricing from quantopian.algorithm import attach_pipeline, pipeline_output import talib as talib Universe Size = 500 Daily Range Per Stock = 0.001 # targeting 10bp of account value Rebalance Threshold = 0.005 # don't rebalance if the difference is less than 50bp of account value # This is the momentum factor, which is the 'slope' of an exponential regression # (ie a linear regression of logarithms), multiplied the the R-Squared of that regression class Momentum(Custom Factor): inputs = [USEquity Pricing.close] window_length = 90 def compute(self, today, assets, out, close): x = pd.

T), dtype=np.float64) for i in range(0,len(assets)): if (cap_ranks[i] filtered['sma100']] return filtered def before_trading_start(context, data): results = pipeline_output('sotm').sort('momentum_rank') filtered = filter_pipeline_results(results) = filtered update_universe(filtered.index) def sell_positions(context, data): cash_freed = 0.0 s = "" for sid in context.portfolio.positions: position = context.portfolio.positions[sid] cash_worth = position.amount * position.last_sale_price # anything not in the pool of allowed stocks is immediately sold if ((sid not in index) & (sid in data)): s = s "%s, " % sid.symbol order_target_percent(sid, 0.0) cash_freed = cash_freed cash_worth log.info(s) return cash_freed def calculate_atr(context, data, sid): highs = history(21, '1d', 'high')[sid] lows = history(21, '1d', 'low')[sid] closes = history(21, '1d', 'close_price')[sid] return talib.

In a live trading algorithm, the stored variable needs to have the split applied to the price and volume.

]] Tags: , ,