我有这个名为的表BondData
,其中包含以下内容:
Settlement Maturity Price Coupon
8/27/2016 1/12/2017 106.901 9.250
8/27/2019 1/27/2017 104.79 7.000
8/28/2016 3/30/2017 106.144 7.500
8/28/2016 4/27/2017 105.847 7.000
8/29/2016 9/4/2017 110.779 9.125
对于此表中的每一天,我将执行一项特定任务,即为变量分配多个值并执行必要的计算。逻辑是这样的:
do while Settlement is the same
m_settle=current_row_settlement_value
m_maturity=current_row_maturity_value
and so on...
my_computation_here...
end
这就像我想遍历我的结算日期并执行任务,只要日期相同。
编辑:为了澄清我的问题,我正在使用 Nelson-Siegel 和 Svensson 模型实现收益率曲线拟合。到目前为止,这是我的代码:
function NS_SV_Models()
load bondsdata
BondData=table(Settlement,Maturity,Price,Coupon);
BondData.Settlement = categorical(BondData.Settlement);
Settlements = categories(BondData.Settlement); % get all unique Settlement
for k = 1:numel(Settlements)
rows = BondData.Settlement==Settlements(k);
Bonds.Settle = Settlements(k); % current_row_settlement_value
Bonds.Maturity = BondData.Maturity(rows); % current_row_maturity_value
Bonds.Prices=BondData.Price(rows);
Bonds.Coupon=BondData.Coupon(rows);
Settle = Bonds.Settle;
Maturity = Bonds.Maturity;
CleanPrice = Bonds.Prices;
CouponRate = Bonds.Coupon;
Instruments = [Settle Maturity CleanPrice CouponRate];
Yield = bndyield(CleanPrice,CouponRate,Settle,Maturity);
NSModel = IRFunctionCurve.fitNelsonSiegel('Zero',Settlements(k),Instruments);
SVModel = IRFunctionCurve.fitSvensson('Zero',Settlements(k),Instruments);
NSModel.Parameters
SVModel.Parameters
end
end
同样,我的主要目标是每天获取每个模型的参数(beta0、beta1、beta2 等)。我收到一个错误,Instruments = [Settle Maturity CleanPrice CouponRate];
因为 Settle 仅包含一条记录(2016 年 8 月 27 日),假设有两条,因为该日期有两行。此外,我注意到 Maturity、CleanPrice 和 CouponRate 包含所有记录。它们应该只包含每天的相应数据。
希望我现在让我的问题更清楚。顺便说一句,我使用的是 MATLAB R2015a。