Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
First Algorithm: Berkshire A/B Arbitrage

Hi guys,

This is my first working algorithm. It does a simple arbitrage between Berkshire Hathaway class A and B shares.

This is set up without slippage or commissions: I doubt this would be profitable under realistic conditions and I just wanted to learn the basics of Quantopian without dealing with the mechanics of real executions. This also won't work prior to Jan. 2010 when the class b shares split.

I don't have very much python or trading experience and I am new to Quantopian so I would really appreciate any feedback you have on the algorithm.

I also have a couple specific questions if anyone wants to help me out.

Appropriate capital base
The capital base is only $10,000 in this. I think the theory here is sound: the short in class A raises the cash to go long in B so almost no net cash is actually required to put on the position. That said, if this was your entire account I don't think it would meet basic margin requirements. What would be an appropriate capital base for this trade?

First position
I am concerned that the first time the algorithm puts on the position it doesn't look like the spread hit the required threshold. Is it possible that the custom chart just isn't showing it? The trade appears to happen profitably.

Thanks!

2 responses

That's a great algo Adam, thanks for sharing.

I ran a full backtest, and you're going long $100k and short $100k with only $10k of your own capital. Brokers aren't going to let you do that. What your broker will let you do is pretty variable. In general, I'd expect that you have to post just over 100% of the short as collateral, and you can borrow 50% of the long. I'm not an expert at this kind of thing, but my guess is that you'd need something north of $150k to run this strategy. However, some brokers use really intense margin calculators, and they'd understand how well you are hedged, and maybe you'd be OK in a model like that. You can do more research here on IB's site.

The custom chart is showing day-granularity, and your algo is in minute-granularity. The day number is an average. So that first trade was probably just very short, and the graph is being confusing. We need to figure out a way to make that more clear.

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

Thanks for the reply Dan,

I think I am going to leave this as a nice little first algorithm and move onto something more realistic.

For anyone who is interested in taking this algorithm further:

I took a deeper look and even without slippage there are occasions when, by the time the trade gets executed, the spread has actually slipped back to 1:1: or worse & the position isn't profitable. I took a crack at using limit orders to ensure that it doesn't enter these positions but I found that with limit orders sometimes it would end up executing one side of the position and not the other which defeats the purpose here. One idea might be to set up some sort of "broken trade" function which would look at the ratio between the actual positions you entered and take some corrective action if it was worse than 1:1