Market Bias Indicator

Just wanted to share this indicator I've been working on in case anyone sees any value. The basic idea is to determine trend while reducing the false positives in moving averages. So instead of caring about whether a price is above or below a MA, it looks at the relationship between the mean of the price for n periods vs the mean of the MA for the same period.

def get_bias(ma,pc,context):
ma = ma[-context.bias_lookback:]# array of moving average values
pc = pc[-context.bias_lookback:]# array of price close values
ma_mean = np.mean(ma)# mean of moving averages
pc_mean = np.mean(pc)# mean of price values
if ma_mean > pc_mean:# determines down bias and gets strength
strength = ma_mean - pc_mean
return 2,strength #short

if pc_mean > ma_mean:# determines up bias and gets strength
strength = pc_mean - ma_mean
return 1,strength #long


By returning the strength of the bias (up or down), we can place long and short trades for the given bias and adjust the shares according to the strength. So if the long bias is low, then we only risk a few shares and vice versa for a strong bias.

38
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
# Backtest ID: 55fcc8cf26f1750dfd3e6983
There was a runtime error.
5 responses

things to consider

34
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
# Backtest ID: 55fd4410b284be0e0a6390d0
There was a runtime error.

Interesting, thanks garyha. I suspect this may have more of an intraday application - unfortunately that's hard to test out in Quantopian

@garyha... It stop working....

def handle_data(context, data):
----> prices_close = history(context.lookback, context.charttype, 'close_price')
prices_close = list(prices_close.values.flatten())
-----> prices = history(context.lookback, context.charttype, 'price')[context.stock]
prices = history(context.lookback, context.charttype, 'price')[context.stock]

Here is slightly modified Gary version for Q2

20
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
# Backtest ID: 572fc7bd1590140f86bd2295
There was a runtime error.

thanks Vladimir.... having alot of difficulty in using this new api... and codes... which are not working anymore... its not backward compatible.... with codes that have work in the the pass....