Can I query fundamental for this data? If not does anyone have a workaround?
Can I query fundamental for this data? If not does anyone have a workaround?
Fundamentals do not contain Beta data. We currently do not expose Beta directly to the user.
However, there are workarounds for this:
1. We have the pyfolio library, which you can find here. There are some functions that deal with rolling Beta within pyfolio, so I suggest searching pyfolio for a function you might find useful, that you can then replicate.
2. Alternatively: you can query the history for your stock, and for SPY (this is the benchmark we use for Beta). You can then use numpy to simply calculate the Beta -- it's a very simple formula. This is what I would do.
Add SPY to your portfolio, then call history() on it, for example: my_history = history(bar_count=20, frequency='1d', field='price'). This should return a dataframe in which you have a column for SPY and a column for every other stock. See the Quantopian Documentation for more help. Then you can compute Beta as per:

Where $r_a$ is the equity you are interested in and $r_b$ is SPY. You can do it like this:
def get_historical_beta(asset_returns, benchmark_returns, window=252):
return pd.rolling_cov(asset_returns, benchmark_returns, window) / pd.rolling_var(benchmark_returns, window)