Hi, guys. How can I calculate Volatility for the data set (https://en.wikipedia.org/wiki/Volatility_(finance))? I'm pretty newbie in Matlab and programming, that's why loops are hard for my understanding.
Z = 252;
n = 20;
Volat=zeros(length(ticker)- n, 1);
for i = 1:n
log_change = log(ticker(2:n+1)./ticker(1:n));
stdev = std(log_change);
Vol(i) = (stdev*sqrt(252))';
It calculates the only one number, however I'm trying to do 2 things: 1) Create "volatility" array (dataset), which, of course, will contain "ticker minus n" numbers; 2) Create "volatility" as window - from number of start element to number of end element from original dataset.
Will be glad for any assistance.