yhilpisch/py4fi

【chapter6】data['Mov_Vol'] = data['Return'].rolling(window=252).std() * math.sqrt(252)

Closed this issue · 2 comments

Rolling.std(ddof=1, *args, **kwargs) calculates rolling standard deviation, normalized by N-1 by default. It means, by default, it uses the sample standard deviation function, in which the denominator is a N-1. The denominator can be set to 1 in this case, if std(ddof=251), then N-251=1. I guess the multiplying of math.sqrt(252) here may be a mistake of confusing rolling.std with numpy.std. The default ddof in numpy.std is 0, which means its denominator is a N. In that case, multiplying of math.sqrt(252) can offset the denominator of 252 exactly.

It is assumed that the calculated standard deviation is the "right one" on a daily basis (for EOD data). Usually the value is calculated based on multiple years worth of data, year for about one year worth of data. The factor math.sqrt(252) then annualizes the volatility value, since a typical trading year has about 252 days.

Got it. Thank you.