我有這個循環(它是一個更大的代碼的一部分),它輸出債券的價格(HW2FPrice)爲連續的SettleEvo日期。 如何讓它輸出一個單一的HW2FPrice數組而不是大量的單個輸出?我想陣列是HW2FPrice VS. SettleEvo。非常感謝,追加for循環matlab
for SettleEvo = Settle:datenum('14-Mar-2013');
NumCouponsRemaining = cpncount(SettleEvo, Maturity, Period, Basis, 1, IssueDate); % Coupon payments remaining until maturity. Calculates the number of periods from start to finish.
nPeriods = NumCouponsRemaining;
[CFlowAmounts, CFlowDates] = cfamounts(CouponRate, SettleEvo, Maturity);
CFlowTimes = yearfrac(SettleEvo,CFlowDates);
CFlowZero = interp1(ZeroTimes,ZeroRates,CFlowTimes,'linear','extrap');
CFlowDF_Zero = zero2disc(CFlowZero,CFlowDates,SettleEvo);
Price_Zero = CFlowAmounts*CFlowDF_Zero';
[CFlowAmounts, CFlowDates, TFactors, Factors] = cfamounts(CouponRate,SettleEvo,repmat(Maturity,1,nTrials),Period,Basis);
CFlowDFSim = cumprod(exp(squeeze(-SimZeroRates(2:end,1,:).*stepSize)));
SimZeroRates是一個數組(nPeriods,nTenors,nTrials);
Price_Ind = sum(CFlowAmounts(:,2:end).*CFlowDFSim',2);
HW2FPrice = mean(Price_Ind)
end
你在這裏問的不完全清楚 - 你能否削減代碼並澄清你需要什麼? – Ansari 2012-08-05 06:25:18
我主要想將HW2FPrice存儲在單個輸出中,而不是單個輸出。這對我有好處。剩下的代碼就是爲了展示SettleEvo日期如何與HW2FPrice依賴的其他值相關聯。這是爲了防止有人能夠進一步進行並在輸出中包含給定的每個HW2FPrice的相應SettleEvo日期。非常感謝您的幫助。 – Mary 2012-08-05 12:03:33