aywinng 发表于 2012-4-8 00:28 
哦,我终于搞明白了,是我自己模型没有看懂。
还想请教您一个问题,这个函数里面Maturity都是日期格式 ...
如果你是作这方面的研究
请仔细看finfixed.pdf page 128/549 的范例
你的数据型态就像
ukdata20080430一样建立
日期转换参考page 21/549
Settle = [datenum('1-Feb-2000');
datenum('1-Feb-2000');
datenum('1-Feb-2000')];
Maturity = [datenum('1-Feb-2030')];
Using the Nelson-Siegel Method to Fit an IRFunctionCurve Object.
The Nelson-Siegel model represents a dynamic three-factor model: level,
slope, and curvature. However, the Nelson-Siegel factors are unobserved, or
latent, which allows for measurement error, and the associated loadings have
economic restrictions (forward rates are always positive, and the discount
factor approaches zero as maturity increases).
%%%%%%
load
ukdata20080430
%Convert repo rates to be equivalent zero coupon bonds:
RepoCouponRate = repmat(0,size(RepoRates));
RepoPrice = bndprice(RepoRates, RepoCouponRate, RepoSettle, RepoMaturity);
%Aggregate the data:
Settle = [RepoSettle;BondSettle];
Maturity = [RepoMaturity;BondMaturity];
CleanPrice = [RepoPrice;BondCleanPrice];
CouponRate = [RepoCouponRate;BondCouponRate];
Instruments = [Settle Maturity CleanPrice CouponRate];
InstrumentPeriod = [repmat(0,6,1);repmat(2,31,1)];
CurveSettle = datenum('30-Apr-2008');
%fit Nelson-Siegel curve
NSModel = IRFunctionCurve.fitNelsonSiegel('Zero',CurveSettle,...
Instruments,'Compounding',-1,'InstrumentPeriod',InstrumentPeriod);
%Plot the Nelson-Siegel interest-rate curve for forward rates:
PlottingDates = CurveSettle+20:30:CurveSettle+365*25;
TimeToMaturity = yearfrac(CurveSettle,PlottingDates);
NSForwardRates = NSModel.getForwardRates(PlottingDates);
plot(TimeToMaturity,NSForwardRates)
title('Nelson Siegel model of UK instantaneous nominal forward curve')