필터 지우기
필터 지우기

How to estimate the summation equation quickly in Matlab?

조회 수: 1 (최근 30일)
NS
NS 2019년 9월 6일
댓글: NS 2019년 9월 7일
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
NS
NS 2019년 9월 7일
Sir in data file rt is given as ReturnforDay.
NS
NS 2019년 9월 7일
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) .

댓글을 달려면 로그인하십시오.

채택된 답변

Guillaume
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.
  댓글 수: 1
NS
NS 2019년 9월 7일
Thank you sir. Let me check with my data. Thanks for all the help.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Number Theory에 대해 자세히 알아보기

제품


릴리스

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by