Here, I implemented a strategy that considers, among other factors, the ratio between Berkshire Hathaway Class A stock and Class B stock as an investment signal for both Berkshire Class B stock and SPY as introduced in this SeekingAlpha article. The strategy considers several criteria as buy points for Berkshire Hathaway:

1) Class Ratio > 1510

2) Increasing VIX

3) Volume above twice the 50-day moving average volume

4) Increasing volume

The data above identify times of strong bearishness in Berkshire Hathaway stock as well as strong overall market bearishness, providing buy point indicators.

I'm interested to see what other factors might make this more robust. Anyone have other data sources to add?

Clone Algorithm

Loading...

There was an error loading this backtest.

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 |

# We implement the algorithm # http://seekingalpha.com/article/1999031-berkshire-share-class-ratio-as-a-buy-point-indicator from numpy import mean, std from math import sqrt from pytz import timezone from datetime import datetime, timedelta from zipline.utils.tradingcalendar import get_early_closes # Post function for VIX data import def rename_col_vix(df): df = df.fillna(method='ffill') df = df[['Settle', 'sid']] df = df.tshift(1, freq='b') return df def initialize(context): # Berkshire Class A, Berkshire Class B, SPY context.securities = [sid(1091), sid(11100), sid(8554)] context.class_ratio = 1 context.previous_vix = 0 context.criterion_1 = False context.criterion_2 = False context.criterion_3 = False context.criterion_4 = False context.previous_day = 0 # We look for an above average ratio between the share classes of # Berkshire Hathaway, combined with strong market bearishness in the # Berkshire Hathaway stock along with overall market bearishness. # Buy Point Criteria: # 1) Berkshire Class Ratio: >1510 # 2) Increasing VIX # 3) Volume: Double Average Volume # 4) Volume: Increasing # Import VIX Front Month Future price data fetch_csv('http://www.quandl.com/api/v1/datasets/OFDP/FUTURE_VX1.csv?&trim_start=2004-05-03&trim_end=2014-01-31&sort_order=desc', date_column='Date', symbol='VIX', post_func=rename_col_vix, date_format='%Y-%m-%d') def handle_data(context, data): context.criterion_1 = False context.criterion_2 = False context.criterion_3 = False context.criterion_4 = False context.criterion_5 = False loc_dt = get_datetime().astimezone(timezone('US/Eastern')) date = get_datetime().date() # Compute Class Ratio - CRITERION 1 if 'price' in data[sid(1091)] and 'price' in data[sid(11100)]: context.class_ratio = data[sid(1091)].price/data[sid(11100)].price if context.class_ratio > 1510: context.criterion_1 = True record(ClassRatio = context.class_ratio) # Compute VIX - CRITERION 2 if 'Settle' in data['VIX']: VIX = data['VIX']['Settle'] if VIX > context.previous_vix: context.criterion_2 = True if loc_dt.hour == 3 and loc_dt.minute == 59: context.previous_vix = VIX # Compute Volume - CRITERIA 3 & 4 if 'volume' in data[sid(1091)]: volume_history = history(50, '1d', 'volume') # Compute the 50 day moving average volume_ma = sum(volume_history[sid(1091)])/50 if (volume_history[sid(1091)][-1] > 2*volume_ma): context.criterion_3 = True if (volume_history[sid(1091)][-1] > volume_history[sid(1091)][-2]): context.criterion_4 = True # Check if all the criteria are met if (context.criterion_1 and context.criterion_2 and context.criterion_3 and context.criterion_4 and context.previous_day != loc_dt.day): log.info('Buying point') order(sid(11100), +100) order(sid(8554), +100) context.previous_day = loc_dt.day

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.