How to compute excess returns for several companies and dates?

2 次查看(过去 30 天)
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)!

回答(1 个)

Andrei Bobrov
Andrei Bobrov 2014-4-25
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)];

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by