any help on this?
How to estimate the summation equation quickly in Matlab?
2 ビュー (過去 30 日間)
古いコメントを表示
I have to estimate PCi for 6 series. I have a dataset with daily data for 2 months which has DATE in format yyyy-mm-dd and 6 return series P1,P2,P3,P4,P5,P6 for day t.
I need to estimate the equation given as image for each month. I have to estimate PC1 to PC6 for all 6 series. Kindly guide how to code it fast.
In this equation t is day and T is month ; i is 6 prices series.
採用された回答
Guillaume
2019 年 9 月 7 日
編集済み: Guillaume
2019 年 9 月 7 日
If I've understood your formula correctly:
returns = readtable('PC Example.xlsx'); %read the data
[year, month] = ymd(returns.DATE); %extract year and month
[bin, binyear, binmonth] = findgroups(year, month); %bin all days of the same year/month combination together
%pcifun is a function that applies to a monthly matrix of 7 columns (returns)
%the first column (returns(:, 1)) is rt, column 2:7 (returns(:, 2:end) are rit.
%the function returns a 1x6 vector according to the given formula
pcifun = @(returns) sum(returns(:, 2:end) ./ returns(:, 1).* abs(returns(:, 1)) / sum(abs(returns(:, 1))), 1);
pcis = splitapply(pcifun, returns{:, 2:end}, bin); %apply the function to each bin (month)
result = array2table([binyear, binmonth, pcis], 'VariableNames', {'year', 'month', 'pci1', 'pci2', 'pci3', 'pci4', 'pci5', 'pci6'}) %convert to table for better display
Note: I've done my best to use functions that exist in R2016a, I may have got it wrong.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Number Theory についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!