Back to Community
Standard Deviation of a Pair

Is there an easy way to calc the standard deviation of a ratio of prices for a certain timeframe? I see the builtin for a single security: "data[sid(XX)].stddev(days)" but what I'm attempting to do is get the standard deviation for a ratio of securities, the price of XOM/AAPL over a certain timeframe for example.

1 response

Call history to get a pandas.DataFrame of prices for the number of days you want, divide one column by the other, take the standard deviation of that. For details, see the documentation of each.