How to estimate the summation equation quickly in Matlab?

1 vue (au cours des 30 derniers jours)
NS
NS le 6 Sep 2019
Commenté : NS le 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 commentaires
NS
NS le 7 Sep 2019
Sir in data file rt is given as ReturnforDay.
NS
NS le 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) .

Connectez-vous pour commenter.

Réponse acceptée

Guillaume
Guillaume le 7 Sep 2019
Modifié(e) : Guillaume le 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 commentaire
NS
NS le 7 Sep 2019
Thank you sir. Let me check with my data. Thanks for all the help.

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by