def variance_calculator(series,series_average,win_len):
sma = win_len
temp = series.subtract(series_average) # a-b
temp2 = temp.apply(lambda x: x**2) #(a-b)^2
temp3 = temp2.rolling(sma-1).mean() # summation[(a-b)^2 ]/ (sma -1)
sigma = temp3.apply(lambda x : math.sqrt(x)) #sigma is the standard deviation
return sigma =========================================================== I want to intention behind using temp2.rolling(sma-1).mean() as this is not equivalent of what is in the comment against this line of code # summation[(a-b)^2 ]/ (sma -1). 'temp2.rolling(sma-1).mean() ’ will not calculate sample Standard deviation and is not equivalent of summation[(a-b)^2 ]/ (sma -1), if intention was to calculate sample standard deviation - this can be be done - sigma = series.rolling(win_len).std(ddof=1) ? Can you please advise , if I am thinking along on correct lines ?
or keeping with same code structure we can probably do following -
# Compute rolling sum over full window (sma)
temp3 = temp2.rolling(win_len).sum()
# Apply proper Bessel’s correction: divide by (win_len-1)
temp3 = temp3 / (win_len - 1)
# Take the square root to get standard deviation
sigma = temp3.apply(lambda x: math.sqrt(x))
Thanks for pointing this out. You may have a valid point, and we are currently evaluating it.
If you have any other concerns, feel free to reach out us via the community.