楼主: tulipsliu
5762 14

[程序分享] MATLAB绘制copula图形 [推广有奖]

促进中国计量经济学发展学科带头人

学科带头人

43%

还不是VIP/贵宾

-

威望
0
论坛币
386093 个
通用积分
469.9098
学术水平
127 点
热心指数
140 点
信用等级
103 点
经验
46957 点
帖子
1769
精华
0
在线时间
2471 小时
注册时间
2007-11-5
最后登录
2024-4-19

初级热心勋章

相似文件 换一批

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
图片:


程序代码:
  1. % Code to generate iso-probability contour plots of bivariate
  2. % distributions, all with N(0,1) marginal distributions and connected via various copulas
  3. %
  4. %  Andrew Patton
  5. %
  6. %  21 august 2006

  7. % Written for the following paper:
  8. %
  9. % Patton, A.J., 2006, Copula-Based Models for Financial Time Series.
  10. % To be published in T.G. Andersen, R.A. Davis, J.-P. Kreiss and T. Mikosch (eds.),
  11. % "Handbook of Financial Time Series", Springer Verlag.
  12. %
  13. % http://fmg.lse.ac.uk/~patton



  14. T = 100;  % takes only around 15 seconds when T=100 on a single-processor 2.6GHz machine

  15. % i cannot see a difference in the printed graph based on T=100 vs T=500,
  16. % though it is a lot smaller and faster to load. so just use T=100;

  17. tic;
  18. xx = (-2:4/(T-1):2)';
  19. uu = normcdf(xx);

  20. v = (0.02:0.03:0.2);

  21. % 1. Normal copula
  22. rho = 0.5;
  23. zz = nines(T,T);  % this the the part of the pdf from the X variable
  24. tic;
  25. for ii=1:T;
  26.    zz(:,ii) = bivnormpdf(xx,xx(ii),[0,0],theta2rho(rho));
  27. end
  28. toc

  29. figure(101);subplot(3,2,1),contour(xx,xx,zz,v,'r-'),...
  30.     title('Normal copula, \rho = 0.5');
  31. figure(102);subplot(3,2,1),contour(xx,xx,zz,v,'k-'),...
  32.     title('Normal copula, \rho = 0.5');
  33. hold on;subplot(3,2,1),plot([-2,2],[0,0],'k--',[0,0],[-2,2],'k--');hold off;   

  34. % 2. Student's t copula
  35. rho = 0.5;
  36. nu = 3;
  37. zz = normpdf(xx)*ones(1,T);  % this the the part of the pdf from the X variable
  38. tic;
  39. for ii=1:T;
  40.    zz(:,ii) = zz(:,ii).*normpdf(xx(ii)).*tcopula_pdf(uu,uu(ii),rho,nu);
  41. end
  42. toc
  43. figure(101);subplot(3,2,2),contour(xx,xx,zz,v,'m-'),...
  44.     title('Student''s t copula, \rho = 0.5, \nu = 3'),...
  45. figure(102);subplot(3,2,2),contour(xx,xx,zz,v,'k-'),...
  46.     title('Student''s t copula, \rho = 0.5, \nu = 3'),...
  47. hold on;subplot(3,2,2),plot([-2,2],[0,0],'k--',[0,0],[-2,2],'k--');hold off;   

  48. % 3. Clayton copula
  49. kappa = 1;
  50. zz = normpdf(xx)*ones(1,T);  % this the the part of the pdf from the X variable
  51. tic;
  52. for ii=1:T;
  53.    zz(:,ii) = zz(:,ii).*normpdf(xx(ii)).*clayton_pdf(uu,uu(ii),kappa);
  54. end
  55. toc

  56. figure(101);subplot(3,2,3),contour(xx,xx,zz,v,'Color',[0 0.7 0]),...
  57.     title('Clayton copula, \kappa = 1');
  58. figure(102);subplot(3,2,3),contour(xx,xx,zz,v,'k-'),...
  59.     title('Clayton copula, \kappa = 1');
  60. hold on;subplot(3,2,3),plot([-2,2],[0,0],'k--',[0,0],[-2,2],'k--');hold off;   


  61. % 4. Gumbel copula
  62. kappa = 1.5;
  63. zz = normpdf(xx)*ones(1,T);  % this the the part of the pdf from the X variable
  64. tic;
  65. for ii=1:T;
  66.    zz(:,ii) = zz(:,ii).*normpdf(xx(ii)).*gumbel_pdf(uu,uu(ii),kappa);
  67. end
  68. toc

  69. figure(101);subplot(3,2,4),contour(xx,xx,zz,v,'Color',[1 0.4 0]),...
  70.     title('Gumbel copula, \kappa = 1.5');
  71. figure(102);subplot(3,2,4),contour(xx,xx,zz,v,'k-'),...
  72.     title('Gumbel copula, \kappa = 1.5');
  73. hold on;subplot(3,2,4),plot([-2,2],[0,0],'k--',[0,0],[-2,2],'k--');hold off;   


  74. % 5. SJC copula
  75. tauU = 0.45;
  76. tauL = 0.2;
  77. zz = normpdf(xx)*ones(1,T);  % this the the part of the pdf from the X variable
  78. tic;
  79. for ii=1:T;
  80.    zz(:,ii) = zz(:,ii).*normpdf(xx(ii)).*sym_jc_pdf(uu,uu(ii),tauU,tauL);
  81. end
  82. toc
  83. figure(101);subplot(3,2,5),contour(xx,xx,zz,v,'Color',[0.5 0.5 0.5 ]),...
  84.     title('SJC copula, \tau^U = 0.45, \tau^L = 0.2');
  85. figure(102);subplot(3,2,5),contour(xx,xx,zz,v,'k-'),...
  86.     title('SJC copula, \tau^U = 0.45, \tau^L = 0.2');
  87. hold on;subplot(3,2,5),plot([-2,2],[0,0],'k--',[0,0],[-2,2],'k--');hold off;   


  88. % 6. Mixture of normals copula
  89. rho1 = 0.95;
  90. rho2 = 0.05;
  91. zz = nines(T,T);  % this the the part of the pdf from the X variable
  92. tic;
  93. for ii=1:T;
  94.    zz(:,ii) = 0.5*bivnormpdf(xx,xx(ii),[0,0],theta2rho(rho1)) + 0.5*bivnormpdf(xx,xx(ii),[0,0],theta2rho(rho2));
  95. end
  96. toc
  97. figure(101);subplot(3,2,6),contour(xx,xx,zz,v,'Color',[0 0 1 ]),...
  98.     title('Mixed normal copula, \rho_1 = 0.95, \rho_2 = 0.05');
  99. figure(102);subplot(3,2,6),contour(xx,xx,zz,v,'k-'),...
  100.     title('Mixed normal copula, \rho_1 = 0.95, \rho_2 = 0.05');
  101. hold on;subplot(3,2,6),plot([-2,2],[0,0],'k--',[0,0],[-2,2],'k--');hold off;   
复制代码


工具箱压缩包下载:
Patton_copula_toolbox.zip (77.87 KB)
二维码

扫码加我 拉你入群

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

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

关键词:MATLAB Copula atlab matla opula 图形

劳动经济学
沙发
xjtuwm 发表于 2013-3-13 23:21:32 |只看作者 |坛友微信交流群
刚复制运行了下,运行失败啊
??? Undefined function or method 'nines' for input arguments of type 'double'.

使用道具

藤椅
tulipsliu 在职认证  发表于 2013-3-14 15:55:26 |只看作者 |坛友微信交流群
xjtuwm 发表于 2013-3-13 23:21
刚复制运行了下,运行失败啊
??? Undefined function or method 'nines' for input arguments of type 'do ...
其实这个是 patton 的 copula 工具箱里的一个程序文件;你在论坛找找可以下载不;
在网上用google也可以找到的;实在不行,我到时候上传整个文件夹的zip文件到论坛;
劳动经济学

使用道具

板凳
xjtuwm 发表于 2013-3-14 22:02:26 |只看作者 |坛友微信交流群
是啊,请楼主上传下整个文件吧

使用道具

报纸
tulipsliu 在职认证  发表于 2013-3-15 18:11:59 |只看作者 |坛友微信交流群
xjtuwm 发表于 2013-3-14 22:02
是啊,请楼主上传下整个文件吧
昨天已经上传了。在帖子的最后有一个压缩文件,是Patton 的copula工具箱,所有程序都在里面,包括那个绘图程序。
劳动经济学

使用道具

地板
elite7502 发表于 2013-3-16 10:17:00 |只看作者 |坛友微信交流群
谢谢楼主分享copula的工具包,另外楼主能留下QQ吗?想请教您一些copula的问题

使用道具

7
tulipsliu 在职认证  发表于 2013-3-16 12:33:39 |只看作者 |坛友微信交流群
elite7502 发表于 2013-3-16 10:17
谢谢楼主分享copula的工具包,另外楼主能留下QQ吗?想请教您一些copula的问题
280201722
劳动经济学

使用道具

8
liuzunx 发表于 2013-8-15 15:29:19 |只看作者 |坛友微信交流群
谢谢提供的代码,这页面上的代码源自何处?copula学习中

使用道具

9
tulipsliu 在职认证  发表于 2013-8-15 18:42:31 |只看作者 |坛友微信交流群
Patton;  Engle 的学生;
劳动经济学

使用道具

10
fengnoname 发表于 2013-12-23 01:01:26 |只看作者 |坛友微信交流群
樓主您好!

跑出的程式碼有錯誤 是顯示為

Undefined function or method 'tdis_inv' for input arguments of type
'double'.

Error in ==> tcopula_pdf at 24
X1 = tdis_inv(U,NU);

Error in ==> dynamic1223 at 50
   zz(:,ii) = zz(:,ii).*normpdf(xx(ii)).*tcopula_pdf(uu,uu(ii),rho,nu);


我也已下載patton的copula工具箱 想知道問題是出在哪呢?

使用道具

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

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-19 23:10