How to compute volatility (standard deviation) in rolling window in Pandas

前端 未结 4 2063
醉话见心
醉话见心 2021-02-08 04:23

I have a time series \"Ser\" and I want to compute volatilities (standard deviations) with a rolling window. My current code correctly does it in this form:

w=10         


        
4条回答
  •  猫巷女王i
    2021-02-08 04:46

    Typically, [finance-type] people quote volatility in annualized terms of percent changes in price.

    Assuming you have daily prices in a dataframe df and there are 252 trading days in a year, something like the following is probably what you want:

    df.pct_change().rolling(window_size).std()*(252**0.5)

提交回复
热议问题