Calculating within-month standard deviation from daily return data

2 ビュー (過去 30 日間)
Sophal
Sophal 2014 年 9 月 17 日
回答済み: Steven Lord 2019 年 4 月 9 日
I have imported a matrix with 2 columns into matlab. The 1st column is serial date number (not date string) and the 2nd column is daily returns from 1996-2014. I wish to calculate the standard deviation within each month, but the window lengths from month to month are different.
Please kindly help provide me the detailed scripts to do so as I'm new to matlab and I will need to do the same thing to 19 other institutions.
  1 件のコメント
Guillaume
Guillaume 2014 年 9 月 17 日
Unless you're willing to pay somebody, it's very unlikely you'll get a detailed script from here (Note I'm not offering).

サインインしてコメントする。

採用された回答

Andrei Bobrov
Andrei Bobrov 2014 年 9 月 17 日
[Y,M] = datevec(data(:,1));
[a,~,c] = unique([Y,M],'rows');
out = [a, accumarray(c,data(:,2),[],@(x)std(x))];
  3 件のコメント
Sean de Wolski
Sean de Wolski 2014 年 9 月 17 日
accumarray for the win!
Anas Khalfi
Anas Khalfi 2019 年 4 月 9 日
Dear Andrei, I think I have the same problem. I have financial data for different countries but because of business days, I don't have the same amount of values for each month. Could you give me a bit of explanations about your code because I tried to understand it to adapt it but I really don't have any idea about what you've done.

サインインしてコメントする。

その他の回答 (1 件)

Steven Lord
Steven Lord 2019 年 4 月 9 日
Since this message was originally written we've introduced the timetable data type. I'd store the data in a timetable and call retime on the timetable, specifying 'monthly' as the value for the newTimeStep input and @std as the method input.

カテゴリ

Help Center および File ExchangeTables についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by