Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Beta of a stock

Hi everyone,

How do I get the beta of a stock? I know I could compute it, but how do I find the variance of the market at a particular point in time?

3 responses

Hi Luke,

There are essentially two ways to do this. You could either piggy-back on the existing Beta calculation we use for the returns of your algorithm by simply buying say 1 share of the stock you are interested in on the first event and then just hold this stock until the end of the simulation.

Another way would be to compute this by hand. We have a std transform you can use to compute variance of the market by using an index like SPY as a proxy. We do not have a covariance transform currently but the computation is quite simple to do in your algorithm. Let me know if you need help with coding this up or if you have any other questions.

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.

Hello Luke & Thomas,

I'm interested, as well, in how to compute the beta of a security over a specified time period (and also the total volume, number of trade events, etc.). From Thomas' comment above, I get the impression that we can effectively write our own transforms within an algorithm, correct?

Hi Grant,

Yes, that's correct, although there is currently not a lot of documentation regarding this. I think it is easiest to wait until we have the batch_transform in place properly which will make this pretty easy. What ultimately be amazing is if users wrote these transforms and supplied them to our open-source backtester zipline (https://github.com/quantopian/zipline see the transforms directory). Once included there it would also be available to all Quantopian users!

Thomas