如何在matlab中循环多个期间的投资组合回报计算?

时间:2013-02-11 15:35:39

标签: matlab loops finance portfolio

我有以下数据/集(简化版本以使示例清晰):

  • 3*10由给定期间的数字标识的股票矩阵(3行(我的投资组合)行数* 10天(列中)名为indexBest。
  • 10*10我的Universe中名为dailyret的每个安全性的每个句点的返回矩阵(我的股票范围是10)。

我想创建一个循环,我可以将每个期间的每个投资组合的总和回报计算为一个矩阵,理想情况为1*1010*1(返回*日期,反之亦然)。

我已经为投资组合的一个时期做了这个,见下文:但我希望能够自动完成这个过程,而不是为每个时期的每个投资组合完成所有这些10*。请帮忙!

Portfolio_1_L= indexBest(:,1); %helps me get the portfolio constituents for period one (3 stocks basically).
Returns_1_L= dailyret(Portfolio_1(:,1));%to calculate returns of the portfolio for period 1 I have referenced  the extraction of returns to the portfolio constituents.
Sum_ret_Port_1_L=sum(Returns_1_L); %sum return of the portfolio for period one

如何为所有其他9个时段循环此过程?

1 个答案:

答案 0 :(得分:3)

使用for循环并使用索引变量代替示例代码中的硬编码1。同时索引输出以存储每天的结果。

for day = 1:10
    Portfolio_1_L = indexBest(:,day);
    Returns_1_L = dailyret(Portfolio_1_L);
    Sum_ret_Port_1_L(day) = sum(Returns_1_L);
end