How to estimate the summation equation quickly in Matlab?
2 views (last 30 days)
Show older comments
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.
10 Comments
Accepted Answer
Guillaume
on 7 Sep 2019
Edited: Guillaume
on 7 Sep 2019
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.
More Answers (0)
See Also
Categories
Find more on Number Theory in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!