How to compute excess returns for several companies and dates?
1 view (last 30 days)
Show older comments
Hello,
I have the set of data below (For about 6000 companies and not only 3, and daily data until 2004).
What I need to do is, for each company at a time, set a new column - say column D - with Returns (col.C) minus the risk free rate (col.G) for the correspondent dates.
So for example, for company B it would be B8-G2, B9-G3 and so on. For company C it would be B14-G2 and etc.
Is there a simple way to do this? For example search, while the company code is the same, matching dates between column B and F and set a new array with the subtracted values?
Thank you so much in advance (I'm new to matlab)!
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/161719/image.bmp)
0 Comments
Answers (1)
Andrei Bobrov
on 25 Apr 2014
ABC = {'A','B','C'}';
DATES = num2cell((19630101:100:19630601)');
ii = fullfact([3 6]);
Df = [ABC(ii(:,1)),DATES(ii(:,2))];
p = [1 2 1 0 1 1 ]'*.01;
[~,i0] = ismember(cell2mat(Df(:,2)), cell2mat(DATES));
pc = num2cell(p);
out = [Df,pc(i0)];
0 Comments
See Also
Categories
Find more on Develop Apps Using App Designer 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!