楼主: heulingxiao
6219 14

[问答] 做Nelson-Siegel的非线性拟合,但是程序有问题,老是报错,希望大虾指点! [推广有奖]

  • 2关注
  • 0粉丝

已卖:605份资源

硕士生

6%

还不是VIP/贵宾

-

威望
0
论坛币
1261 个
通用积分
1.3600
学术水平
4 点
热心指数
7 点
信用等级
3 点
经验
3080 点
帖子
84
精华
0
在线时间
116 小时
注册时间
2012-10-13
最后登录
2023-2-25

楼主
heulingxiao 发表于 2015-4-25 18:59:02 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
       本人想利用matlab中的fit函数和fittype自定义的属性拟合Nelson-Siegel参数,但是写完程序老是报错,程序和错误如下:
程序如下:
yield = xlsread('20141118.xls','sheet4','I3:I21');
t = xlsread('20141118.xls','sheet4','C3:C21');
plot(t,yield,'o')
hold on
fo = fitoptions('Method','NonlinearLeastSquares',...
               'Lower',[0,0],...
               'Upper',[Inf,max(t)],...
               'StartPoint',[0.26 0.0041]);
ftp = fittype ('b0+b1*[(1-exp(-t/tau))/(t/tau)]+b2*[(1-exp(-t/tau))/(t/tau)-exp(-t/tau)]',...
               'dependent','yield','independent','t','coefficients',{'b0','b1','b2'},'problem','tau','options',fo);
[c2,gof2]= fit(t,yield,ftp,'problem',2)
plot(c2,'m')
hold off

错误提示:

Warning: Length of lower bounds is > length(x); ignoring extra bounds.
> In checkbounds at 29
  In lsqnsetup at 63
  In lsqcurvefit at 190
  In E:\studying software\Matlab\matlab r2012\toolbox\shared\optimlib\lscftsh.p>lscftsh at 37
  In cflscftsh at 8
  In curvefit\private\cflsqcurvefit at 55
  In fit>iFit at 373
  In fit at 109
  In firstNS at 11
Warning: Length of upper bounds is > length(x); ignoring extra bounds.
> In checkbounds at 38
  In lsqnsetup at 63
  In lsqcurvefit at 190
  In E:\studying software\Matlab\matlab r2012\toolbox\shared\optimlib\lscftsh.p>lscftsh at 37
  In cflscftsh at 8
  In curvefit\private\cflsqcurvefit at 55
  In fit>iFit at 373
  In fit at 109
  In firstNS at 11
Error using fit>iFit (line 415)
Not enough inputs to FITTYPE function.

Error in fit (line 109)
[fitobj, goodness, output, convmsg] = iFit( xdatain, ydatain, fittypeobj, ...

Error in firstNS (line 11)
[c2,gof2]= fit(t,yield,ftp,'problem',2);
Caused by:
    Failure in initial user-supplied objective function evaluation. LSQCURVEFIT cannot continue.




二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:Nelson Siegel Siege son gel matlab hold 程序

沙发
enxizheng 发表于 2015-4-25 21:13:47
fo = fitoptions('Method','NonlinearLeastSquares',...
                'Lower',[0,0],...
                'Upper',[Inf,max(t)],...
                'StartPoint',[0.26 0.0041 0.1]);

藤椅
enxizheng 发表于 2015-4-25 21:31:04
enxizheng 发表于 2015-4-25 21:13
fo = fitoptions('Method','NonlinearLeastSquares',...
                'Lower',[0,0],...
            ...
你有3个系数b0,b1,b2, 却只给了2个初值(StartPoint), 这可能是出错的原因

板凳
heulingxiao 发表于 2015-4-26 14:17:56
enxizheng 发表于 2015-4-25 21:31
你有3个系数b0,b1,b2, 却只给了2个初值(StartPoint), 这可能是出错的原因
恩恩,谢谢你的帮助,第一次用fittype,不太熟悉,调整后我拟合了一下,成功了,,我把初值赋好就行了,这里拟合好之后怎么查看对应的参数值呢? 我拟合的曲线

fitnelsonsiegel.jpg (16.31 KB)

fitnelsonsiegel.jpg

报纸
enxizheng 发表于 2015-4-26 15:10:26
heulingxiao 发表于 2015-4-26 14:17
恩恩,谢谢你的帮助,第一次用fittype,不太熟悉,调整后我拟合了一下,成功了,,我把初值赋好就行了,这 ...
参数结果存在你的 c2 变量中, 在命令窗口输入 c2, 回车即可.
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
heulingxiao + 1 + 1 + 1 热心帮助其他会员

总评分: 学术水平 + 1  热心指数 + 1  信用等级 + 1   查看全部评分

地板
heulingxiao 发表于 2015-4-26 15:58:28
enxizheng 发表于 2015-4-26 15:10
参数结果存在你的 c2 变量中, 在命令窗口输入 c2, 回车即可.
做出来了,非常感谢!!!

7
enxizheng 发表于 2015-4-26 16:17:23
heulingxiao 发表于 2015-4-26 15:58
做出来了,非常感谢!!!
不客气

8
xia5505676 发表于 2017-2-22 23:27:30
楼主您好,我最近在做这个模型,零基础不会编程,楼主可以分享一下你的代码吗?不胜感激
我的邮箱2418532925@qq.com

9
heulingxiao 发表于 2017-3-3 14:59:47
xia5505676 发表于 2017-2-22 23:27
楼主您好,我最近在做这个模型,零基础不会编程,楼主可以分享一下你的代码吗?不胜感激
我的邮箱24185329 ...
什么意思呀,我这个帖子最上面就是我写的代码啊,前面需要读入数据,数据肯定是要你自己的,可能会有问题,不过你看后面的人的留言,就能做出来了。

10
yanghuanwen 发表于 2017-5-8 10:00:11
求问楼主有没有做加权后的NS模型啊?也是用非线性最小二乘拟合做吗?

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-26 04:29