我有這樣的表名爲BondData
其中包含以下內容:如何通過表圈基於獨特的日期在MATLAB
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
這就像我通過我的結算日期要循環,只要日期是一樣執行任務。
編輯:只是爲了澄清我的問題,我在執行收益率曲線使用納爾遜 - 西格爾和斯文森models.Here是我的代碼至今配件:
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),假設有兩條記錄,因爲此日期有兩行。另外,我注意到成熟度,CleanPrice和CouponRate包含所有記錄。他們應該只包含每天的相應數據。
希望我現在讓我的問題更清楚了。順便說一下,我正在使用MATLAB R2015a。
你到目前爲止試過了什麼?你有你的代碼的最小,完整和可驗證的例子嗎? – bushmills
我試圖得到這樣的獨特的結算日期,但我有一個關於如何實現循環負載債券的問題數據表 A =表(結算,到期日,價格,優惠券); B =唯一(A(:,1),'rows'); – aldrean
你使用哪個MATLAB版本? – EBH