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

附件下载

所在主题:
文件名:  Semi-Parametric-Copula-Approach-master.zip
资料下载链接地址: https://bbs.pinggu.org/a-2933926.html
附件大小:
已经下载论坛很多书籍,大概6000论坛币已经剩下只有300左右吧,此贴不收金币。我太累,已经看不了那么多书。

tulipsliu中国数量经济(群)中国数量金融(群)群主

原则上中国数量经济已经封闭群,只实行邀请制,没通过我的邀请无法进群。

中国数量金融群为开放群,这里分享群号码,想一起学习金融的可以加入。

群嘛,不知道怎么介绍。中国数量金融群号码:949614744

其中应该是半参数那个,作者在程序里设置了Frank copula ,程序运行中途无法继续。我已经修改为 t copula
可以放心运行。贴上半参数里其中一个主程序的代码,可以不复制到你的文件里,因为程序全部在 ZIP 文件里。
这个程序应该是我在 github 网站下载,如果想看更新最新的代码,可以自己去搜索。

  1. %This MATLAB script runs the Semi-Parametric Copula Method presented in Manheim &
  2. %Detwiler (2019) for various analytical test cases. It was originally coded and developed by Derek Manheim,
  3. %at the University of California, Irvine, Department of Civil & Environmental
  4. %Engineering using MATLAB r2015b. It is a fully Global, Moment Independent, Monte Carlo (MC) based sampling method
  5. %that relies on the use of parametric copula models to describe the joint pdf between
  6. %model inputs (i.e., parameters) and outputs. The user must specify what
  7. %test case to run (testfunc, options are 1,2,3), the copula model used
  8. %(options are 'Gaussian','t','Clayton','Frank','Gumbel'), the number of MC sampling points used to construct
  9. %and sample the Copula model (Nevalpts) as well as the repetition number (Rep), which specifies the
  10. %location of the Sobol sequence used for QMC sampling. In addition to the files provided in this download folder,
  11. %in order to run this code users must have the statistics and machine learning toolbox package installed
  12. %and should be running MATLAB r2015 or later. The results are automatically
  13. %saved after running this script. *Note - running over 65536 Nevalpts will
  14. %require more advanced parallel computation (8-16 cores or more) and is not recommended to be run locally.
  15. %Final Version, updated 5-8-2019
  16. clear ; close all; clc

  17. %Run specifications
  18. Rep = 1; %Location in the sobol sequence (1,2,3,4) to set up different repetitions
  19. testfunc = 1; %Which analytical test cases?
  20. CopulaModel = 't'; %Which parametric Copula Model to use?
  21. Nevalpts = 256; %How many MC evaluation points used to construct and sample the Copula model? should be a factor of 2
  22. Delay=500+((Rep-1)*Nevalpts); %This sets the location in the sobol sequence for QMC sampling

  23. %Set up variables required for MLE optimization
  24. if strcmp(CopulaModel,'Clayton')
  25. model = 1;
  26. elseif strcmp(CopulaModel,'Frank')
  27. model = 2;
  28. elseif strcmp(CopulaModel,'Gumbel')
  29. model = 3;
  30. elseif strcmp(CopulaModel,'Gaussian')
  31. model = 4;
  32. elseif strcmp(CopulaModel,'t')
  33. model = 5;
  34. end

  35. %%Set up variables to evaluate each test case
  36. if testfunc == 1 %linear test case
  37. Nvar = 6;
  38. f = @(Xs) (1.5.*Xs(:,1)+1.6.*(Xs(:,2))+1.7.*(Xs(:,3))+1.8.*(Xs(:,4))+1.9.*(Xs(:,5))+2.*(Xs(:,6)));
  39. p = sobolset(Nvar,'skip',Delay);
  40. X = p(1:Nevalpts,:);
  41. for j = 1:Nvar
  42. Xs(:,j) = sqrt(2)*erfinv(2.*X(:,j)-1); %Model inputs
  43. end
  44. [Yn] = f(Xs);
  45. Y = Yn; %Model output
  46. elseif testfunc == 2 %non-linear test case
  47. Nvar = 6;
  48. bi = [4.5,2.5,1.5,0.5,0.3,0.1];
  49. f = @(x,bi) exp(sum(bi.*x,2))-prod((exp(bi)-1)./bi);
  50. p = sobolset(Nvar,'skip',Delay);
  51. X = p(1:Nevalpts,:);
  52. for j = 1:Nevalpts
  53. Yn(j,1) = exp(sum(bi.*X(j,:),2))-prod((exp(bi)-1)./bi);
  54. end
  55. Y = Yn; %model outputs
  56. for j = 1:Nvar
  57. Xs(:,j) = sqrt(2)*erfinv(2.*X(:,j)-1); %model inputs
  58. end
  59. elseif testfunc == 3 %Ishigami test case (non-linear/non-monotonic)
  60. Nvar = 3;
  61. lb1 = repmat([-pi -pi -pi],[Nevalpts 1]);
  62. ub1 = repmat([pi pi pi],[Nevalpts 1]);
  63. %Parameters
  64. a = 7; b = 0.1;
  65. f = @(x) (sin(x(:,1))+ a.*(sin(x(:,2)).^2)+(b.*(x(:,3).^4).*sin(x(:,1))));
  66. p = sobolset(Nvar,'skip',Delay);
  67. X = p(1:Nevalpts,:);
  68. Xss = lb1+((ub1-lb1).*X);
  69. %Evaluate model
  70. [Yn] = f(Xss);
  71. Y = Yn; %model output
  72. %Std normal space for Xs
  73. for j = 1:Nvar
  74. Xs(:,j) = sqrt(2)*erfinv(2.*X(:,j)-1); %model inputs
  75. end
  76. end

  77. %%Estimate alpha values for the Rolling Pin method
  78. %using the maximum likelihood (MLE) optimization approach
  79. %Here, an external call to LSHADEEpSinNLS algorithm is performed
  80. %Note, on 2 cores this will likely take a bit of time, especially if
  81. %Nevalpts is high
  82. ry = Y;
  83. rx = Xs;
  84. Ngens = 20000; %This is the number of generations used for MLE optimization
  85. Npop = 50; %This is the number of population members used for MLE optimization
  86. nTol = 1E-6; %This is the tolerance used to moniter convergence
  87. paramL = zeros(1,Nvar+1); paramU = ones(1,Nvar+1); %boundaries of the alpha parameter values, Rolling Pin method
  88. paramU(1,1) = 0;
  89. x2{1,1} = ry; x2{1,2} = rx; x2{1,3} = model;
  90. [solset] = LSHADEpSinNLS(@MLEObjFuncFinalAll, Nvar+1, paramL, paramU, Npop, nTol, Ngens,x2); %Run optimization call
  91. [m,p] = find(nonzeros(solset.Xbest(:,2)));
  92. alpha = solset.Xbest(m(end),:); %Extract best alpha values for Rolling Pin method

  93. %%Semi-Parametric method begins here
  94. %Estimate Yi, transformed values, Equation 4
  95. for j = 1:Nvar
  96. Yi(:,j) = (1-alpha(1,j+1)).*(ry(:,1))+alpha(1,j+1).*(rx(:,j));
  97. end

  98. %Find the PDFs and CDFs of the transformed distributions, Yi and Xs (Eqs.
  99. %5 and 6)
  100. parfor j = 1:Nvar
  101. tic
  102. pd1{j,1} = fitdist(Yi(:,j),'Kernel');
  103. FYr(:,j) = cdf(pd1{j,1},Yi(:,j));
  104. FX(:,j) = normcdf(rx(:,j),0,1);
  105. toc
  106. end

  107. %Fit Elliptical or Archimidean parametric copula model here using MATLAB's built in
  108. %functions
  109. for j = 1:Nvar
  110. u{j,1} = [FYr(:,j) FX(:,j)];
  111. %Construct Parametric Copula from CDF matrix, t-distribution is a
  112. %special case
  113. if model == 5
  114. [r{j,1},nus{j,1}] = copulafit(CopulaModel,u{j,1});
  115. else
  116. [r{j,1}] = copulafit(CopulaModel,u{j,1});
  117. end
  118. end

  119. %Sample from constructed parametric copula model, using MATLAB's built in
  120. %functions
  121. parfor j = 1:Nvar
  122. tic
  123. if model == 5
  124. cs = copularnd(CopulaModel,r{j,1},nus{j,1},Nevalpts);
  125. else
  126. cs = copularnd(CopulaModel,r{j,1},Nevalpts);
  127. end
  128. FYrn(:,j) = cs(:,1);
  129. FXn(:,j) = cs(:,2);
  130. Yin(:,j) = icdf(pd1{j,1},FYrn(:,j));
  131. Xn(:,j) = norminv(FXn(:,j),0,1);
  132. toc
  133. end

  134. %Find the marginal PDFs of the sampled dists, Yin and Xn (Eqs. 5 and 6)
  135. parfor j = 1:Nvar
  136. tic
  137. FYpdf1(:,j) = pdf(pd1{j,1},Yin(:,j));
  138. Fpdf(:,j) = normpdf(Xn(:,j),0,1);
  139. toc
  140. end

  141. %Transform the sample back to original space, inverse of Equation 4
  142. parfor j = 1:Nvar
  143. Ys(:,j) = (Yin(:,j)-alpha(1,j+1).*Xn(:,j))./(1-alpha(1,j+1));
  144. pd3{j,1} = fitdist(Ys(:,j),'Kernel');
  145. FyPDF(:,j) = pdf(pd3{j,1},Ys(:,j));
  146. end

  147. %Evaluate the parametric copula density
  148. for j = 1:Nvar
  149. %Evaluate joint pdf directly at pts
  150. a = FYpdf1(:,j).*(1-alpha(1,j+1));
  151. b = normpdf(Xn(:,j),0,1).*(1-alpha(1,1));
  152. if model == 5
  153. fXa1(:,j) = copulapdf(CopulaModel,[FYrn(:,j),FXn(:,j)],r{j,1},nus{j,1});
  154. else
  155. fXa1(:,j) = copulapdf(CopulaModel,[FYrn(:,j),FXn(:,j)],r{j,1});
  156. end
  157. fX(:,j) = fXa1(:,j).*a.*b; %Equation 7
  158. end

  159. %Estimate the MI sensitivity indices, Equation 8
  160. for j = 1:Nvar
  161. deltast(:,j) = abs(((FyPDF(:,j).*Fpdf(:,j))./(fX(:,j)))-1);
  162. delta(1,j) = 0.5*mean(deltast(:,j));
  163. end

  164. %Save results here
  165. filename = strcat(['SemiParamCopula_',CopulaModel,'_Test',num2str(testfunc),'_N',num2str(Nevalpts),'_Rep',num2str(Rep),'.mat']);
  166. save(filename,'delta','deltast','solset','Xs','Y','ry','rx');
复制代码









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

扫码加我 拉你入群

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

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

GMT+8, 2026-2-8 02:33