I have a time series of daily stock prices for several firms. Now I want to calculate the daily returns and the rolling standard deviation of 250 days for each firm. I have no clue how to implement that in Matlab. Whereas in Stata I could only use the "by" command, it didnt find a similar function in Matlab.
I did group my firm ID and tried to apply splitapply. It works but what I get is a cell array. If I do not specify "{}" (cell array) in my function, this function wont work.
func =@(p){log(p(2:end)./p(1:end-1))} ;r = splitapply(func,p,Entity);
The goal is to calculate daily returns (in an array) and annualized std. dev to further calculate the distance to default for each company.
Has someone a hint, how this might work? Thanks for any hint!
Best Answer