How to estimate the summation equation quickly in Matlab?

2 Ansichten (letzte 30 Tage)
NS
NS am 6 Sep. 2019
Kommentiert: NS am 7 Sep. 2019
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 Kommentare
NS
NS am 7 Sep. 2019
Sir in data file rt is given as ReturnforDay.
NS
NS am 7 Sep. 2019
We just have to calculate the sum of absolute return for the month for denominator of second part of the above equation.
If you break this equation into two parts first part gives the contribution of return of Hour i to Return of the day t. The second part of the equation is contribution of absolute Return of Day t to Sum of absolute Return of the Month i.e. (weighting factor for day in a month) .

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Guillaume
Guillaume am 7 Sep. 2019
Bearbeitet: Guillaume am 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.
  1 Kommentar
NS
NS am 7 Sep. 2019
Thank you sir. Let me check with my data. Thanks for all the help.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by