搜索
人大经济论坛 附件下载

附件下载

所在主题:
文件名:  Patton_copula_toolbox.zip
资料下载链接地址: https://bbs.pinggu.org/a-1284962.html
附件大小:
77.87 KB   举报本内容
图片:


程序代码:
  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;
复制代码


工具箱压缩包下载:



    熟悉论坛请点击新手指南
下载说明
1、论坛支持迅雷和网际快车等p2p多线程软件下载,请在上面选择下载通道单击右健下载即可。
2、论坛会定期自动批量更新下载地址,所以请不要浪费时间盗链论坛资源,盗链地址会很快失效。
3、本站为非盈利性质的学术交流网站,鼓励和保护原创作品,拒绝未经版权人许可的上传行为。本站如接到版权人发出的合格侵权通知,将积极的采取必要措施;同时,本站也将在技术手段和能力范围内,履行版权保护的注意义务。
(如有侵权,欢迎举报)
二维码

扫码加我 拉你入群

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

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

GMT+8, 2025-12-26 07:20