楼主: tulipsliu
6613 12

[程序分享] Monte Carlo and Importance sampling [推广有奖]

经济学论述自由撰稿人!

已卖:2751份资源

学科带头人

45%

还不是VIP/贵宾

-

威望
0
论坛币
386043 个
通用积分
526.9298
学术水平
127 点
热心指数
140 点
信用等级
103 点
经验
46986 点
帖子
1773
精华
0
在线时间
2509 小时
注册时间
2007-11-5
最后登录
2024-8-16

初级热心勋章

楼主
tulipsliu 在职认证  发表于 2012-10-30 23:55:00 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
从网上找到的程序,贝叶斯计量经济学,发出来大家互相学习。代码如下:
  1. %Loop to do Monte Carlo and Importance sampling
  2. %R is number of replications
  3. R=10;
  4. %Mean, scale and degrees of freedom for t importance function
  5. ismean=3;
  6. isscale=1;
  7. isdof=2;
  8. %Start all MC and Importance sampling sums at zero
  9. thmeanmc=0;
  10. th2momc=0;
  11. thmeanis=0;
  12. th2mois=0;
  13. wsum=0;
  14. wsum2=0;
  15. for irep=1:R
  16.     %Monte Carlo draw
  17.     thetdraw=randn;   
  18.     thmeanmc=thmeanmc+thetdraw;
  19.     th2momc=th2momc + thetdraw^2;
  20.     %Importance sampling draw. Note: tdis_rnd draws from Student-t
  21.   thdrawis=ismean + sqrt(isscale)*tdis_rnd(1,isdof);

  22.     %Importance sampling weight. Note: tdens evaluates the t density at a point
  23.     w = norm_pdf(thdrawis,0,1)/tdens(thdrawis,ismean,isscale,isdof);
  24.      thmeanis=thmeanis+w*thdrawis;
  25.     th2mois=th2mois + w*thdrawis^2;
  26.     wsum=wsum+w;
  27.     wsum2=wsum2+w^2;
  28. end
  29.    
  30.     thmeanmc=thmeanmc/R;
  31.     th2momc=th2momc/R;
  32.     thsdmc=sqrt(th2momc - thmeanmc^2);
  33.     'Monte Carlo Posterior Mean and Standard Deviation'
  34.     [thmeanmc thsdmc]
  35.      thmeanis=thmeanis/wsum;
  36.     th2mois=th2mois/wsum;
  37.     thsdis=sqrt(th2mois - thmeanis^2);
  38.     'Importance Sampling Posterior Mean and Standard Deviation'
  39.     [thmeanis thsdis]
  40.     'Mean and standard deviation of importance sampling weights'
  41.     wmean=wsum/R;
  42.     wstd=sqrt(wsum2/R - wmean^2);
  43.     [wmean wstd]
复制代码


二维码

扫码加我 拉你入群

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

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

关键词:Monte Carlo importance Sampling import porta 经济学 程序

已有 1 人评分学术水平 热心指数 信用等级 收起 理由
fantuanxiaot + 2 + 2 + 2 精彩帖子

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

劳动经济学

沙发
songlinjl 发表于 2012-10-31 00:08:51
有心人。

藤椅
tulipsliu 在职认证  发表于 2012-10-31 00:09:45
songlinjl 发表于 2012-10-31 00:08
有心人。
这个是我近期关注的领域;
期待能在MCMC上有突破;
劳动经济学

板凳
L-dgao 发表于 2012-11-27 17:07:36
好东西,顶一个

报纸
tulipsliu 在职认证  发表于 2012-11-27 17:27:18
L-dgao 发表于 2012-11-27 17:07
好东西,顶一个
你也对这个感兴趣吗?
劳动经济学

地板
L-dgao 发表于 2012-11-27 17:48:22
tulipsliu 发表于 2012-11-27 17:27
你也对这个感兴趣吗?
嗯 是的,感兴趣,我后面还要用到Monte Carlo,网格算法,样条插值来做一个估计,现在还在努力学习中。。。以后还得请你多多指教了,哈哈

7
cyf8118 发表于 2012-12-19 20:18:33
学习一下

8
gyqznufe 发表于 2013-11-27 20:05:21
楼主,很用心啊!请教楼主:运行上述代码后出现这两个提示:
1 Undefined function 'tdens' for input arguments of type 'double'
2 Undefined function 'simplest_montecarlo0' for input arguments of type 'double'.
有时间帮解答一下,多谢!
知常容·容乃公·公乃王!
创新源于学、问、思、行、果!
言传身教,请用事实与数据说话!
舍而得之:福、禄、寿、喜、财

9
arieny 学生认证  发表于 2013-12-25 21:00:46
顶……我最近正好研究通过这两种算法计算VaR。。。灰常感谢大神啊!

10
arieny 学生认证  发表于 2013-12-25 22:53:15
老师,您好!很感谢您能分享这么重要有用的程序。由于代码中的变量实在是有点多,能不能解释下相关变量,并且说明初始数据的来源?如
  1. ismean=3;
  2. isscale=1;
  3. isdof=2;
复制代码
中的3,1,2是怎么来的?我如果要求信用风险收益率和市场风险收益率的整合风险VaR,那是求什么数据的均值、自由度呢?

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

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