matlab批处理参数估计,nelson siegel 参数估计

怎样利用matlab 里的 fitsvensson  fit nelsonsiegel ,的 图形做出参数估计 呢 , 我在我那个上搜到3 个某国程序人编的 对这个 有帮组吗,欢迎高人来指点 , 我是新手

下面是3 个 程序

function[y] = nelsonfun(x,par)

% NELSONFUN Evaluate Nelson-Siegel function

% Inputs    x   - n*1 or 1*n vector

%           par - structure with fields 'beta' (3*1 or 1*3 vector), 'tau' (scalar)

% Outputs   y   - n*1 vector

% Example   par.beta = [.05 .1 .5]

%           par.tau  = 1

%           x = [.125 .25 .5 1 2 3 5 7 10 20 30]

%           y = nelsonfun(x,par)

% Author    Dimitri Shvorob, dimitri.shvorob@vanderbilt.edu, 12/30/07

checkfield('beta',3)

checkfield('tau' ,1)

i = x(:)/par.tau;

j = 1-exp(-i);

y = par.beta(1) + par.beta(2)*j./i + par.beta(3)*((j./i)+j-1);

function checkfield(name,n)

if ~isfield(par,name)

error('Field "%s" not found in parameter structure',name)

else

if ~isvector(par.(name)) || numel(par.(name)) ~= n

error('Field "%s" must have %d elements',name,n)

end

end

end

end

2

function[par] = nelsonfit(x,y)

% NELSONFIT Fit Nelson-Siegel function

% Inputs    x,y - n*1 or 1*n vectors

% Outputs   par - structure with fields 'beta' (3*1 vector), 'tau' (scalar)

% Notes     No non-negativity constraints are imposed on betas; taus are

%           searched over by FMINBND within range (0,10).

% Example   x = [.125 .25  .5   1    2    3    5    7    10   20   30]

%           y = [2.57 3.18 3.45 3.34 3.12 3.13 3.52 3.77 4.11 4.56 4.51]

%           par = nelsonfit(x,y)

% Author    Dimitri Shvorob, dimitri.shvorob@vanderbilt.edu, 12/30/07

par.tau  = fminbnd(@(tau) nelsonsse(tau),0,10);

par.beta = lsbetas(par.tau);

function[f] = nelsonsse(tau)

[b,f] = lsbetas(tau);                        %#ok

end

function[b,varargout] = lsbetas(tau)

i = x(:)/tau;

j = 1-exp(-i);

n = length(x);

z = [ones(n,1) j./i (j./i)+j-1];

b = (z'*z)\(z'*y(:));

e = y(:) - z*b;

varargout(1) = {e'*e};

end

end

3

function[par] = nelsonfit(x,y)

% NELSONFIT Fit Nelson-Siegel function

% Inputs    x,y - n*1 or 1*n vectors

% Outputs   par - structure with fields 'beta' (3*1 vector), 'tau' (scalar)

% Notes     No non-negativity constraints are imposed on betas; taus are

%           searched over by FMINBND within range (0,10).

% Example   x = [.125 .25  .5   1    2    3    5    7    10   20   30]

%           y = [2.57 3.18 3.45 3.34 3.12 3.13 3.52 3.77 4.11 4.56 4.51]

%           par = nelsonfit(x,y)

% Author    Dimitri Shvorob, dimitri.shvorob@vanderbilt.edu, 12/30/07

par.tau  = fminbnd(@(tau) nelsonsse(tau),0,10);

par.beta = lsbetas(par.tau);

function[f] = nelsonsse(tau)

[b,f] = lsbetas(tau);                        %#ok

end

function[b,varargout] = lsbetas(tau)

i = x(:)/tau;

j = 1-exp(-i);

n = length(x);

z = [ones(n,1) j./i (j./i)+j-1];

b = (z'*z)\(z'*y(:));

e = y(:) - z*b;

varargout(1) = {e'*e};

end

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值