Returns and standard deviation groupwise
古いコメントを表示
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!
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Financial Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!