0

我有这个循环(它是更大代码的一部分),它输出连续SettleEvo日期的债券价格(HW2FPrice)。如何让它输出单个 HW2FPrice 数组而不是大量单独的输出?我希望数组是HW2FPrice Vs。解决Evo。非常感谢,

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
4

1 回答 1

1
HW2FPrices = []; % creates an empty array

for SettleEvo = Settle:datenum('14-Mar-2013');
    % ... whatever other code is in your loop
    HW2FPrice = mean(Price_Ind)
    HW2FPrices(end+1) = HW2FPrice;
end

循环完成后,HW2FPrinces将是一个数组,其中包含HW2FPrice您在循环中看到的所有值。

于 2012-08-06T16:47:13.557 回答