DSGE动态经济学建模Band-Pass filter 程序分享-经管之家官网!

人大经济论坛-经管之家 收藏本站
您当前的位置> 考研考博>>

考研

>>

DSGE动态经济学建模Band-Pass filter 程序分享

DSGE动态经济学建模Band-Pass filter 程序分享

发布:tulipsliu | 分类:考研

关于本站

人大经济论坛-经管之家:分享大学、考研、论文、会计、留学、数据、经济学、金融学、管理学、统计学、博弈论、统计年鉴、行业分析包括等相关资源。
经管之家是国内活跃的在线教育咨询平台!

经管之家新媒体交易平台

提供"微信号、微博、抖音、快手、头条、小红书、百家号、企鹅号、UC号、一点资讯"等虚拟账号交易,真正实现买卖双方的共赢。【请点击这里访问】

提供微信号、微博、抖音、快手、头条、小红书、百家号、企鹅号、UC号、一点资讯等虚拟账号交易,真正实现买卖双方的共赢。【请点击这里访问】

这个代码我调试过,添加了缺少的函数文件ols.m,但是依然还有10%的错误,本来用markdown发帖,但是贴了主程序1100行的代码,太大导致无法发出去。所以就算了。这里插入一个函数计算band-passfilter的。functionyf=BP ...
免费学术公开课,扫码加入


这个代码我调试过,添加了缺少的函数文件 ols.m ,但是依然还有10% 的错误,本来用markdown 发帖,但是贴了主程序1100行的代码,太大导致无法发出去。 所以就算了。
这里插入一个函数计算 band-pass filter的。
  1. function yf=BPF(y,up,dn,K)

  2. % bpf.m
  3. % Program to compute band-pass filtered series
  4. % Inputs are
  5. %y: data (rows = observations, columns=series)
  6. %up:period corresponding to highest frequency (e.g., 6)
  7. %dn:period corresponding to lowest frequency (e.g., 32)
  8. %K: number of terms in approximating moving average
  9. %[calls filtk.m (filter with symmetric weights) as subroutine]
  10. x=[up dn];
  11. disp(' ')
  12. disp('bpf(y,up,dn,K): band-pass filtering of series y with symmetric MA(2K+1)')
  13. disp(' ')
  14. disp(' for additional information see: ')
  15. disp(' ')
  16. disp(' M. Baxter and R.G. King ')
  17. disp(' ')
  18. disp(' Measuring Business Cycles: ')
  19. disp(' Approximate Band-Pass Filters')
  20. disp(' for Macroeconomic Time Series')
  21. disp(' ')
  22. disp('Filter extracts components between periods of: ')
  23. disp(' up dn')
  24. disp(x)
  25. % pause(2)

  26. if (up>dn)
  27. disp('Periods reversed: switching indices up & dn')
  28. disp(' ')
  29. dn=x(1); up=x(2);
  30. end

  31. if (up<2)
  32. up=2;
  33. disp('Higher periodicity > max: Setting up=2')
  34. disp(' ')
  35. end

  36. % convert to column vector
  37. [r c]=size(y);
  38. if (r<c)
  39. y=y';
  40. disp('There are more columns than rows: Transposing data matrix')
  41. disp(' ')
  42. end

  43. % Implied Frequencies
  44. omubar=2*pi/up;
  45. omlbar=2*pi/dn;

  46. % An approximate low pass filter, with a cutoff frequency of "ombar",
  47. % has a frequency response function
  48. %
  49. %alpha(om) = a0 + 2*a1 cos(om) + ... 2*aK cos(K om)
  50. %
  51. % and the ak's are given by:
  52. %
  53. % a0 = ombar/(pi) ak = sin(k ombar)/(k pi)
  54. %
  55. % where ombar is the cutoff frequency.

  56. % A band-pass filter is the difference between two
  57. % low-pass filters,
  58. % bp(L) = bu(L) - bl(L)
  59. % with bu(L) being the filter with the high cutoff point and bl(L) being
  60. % that with the low cutoff point.Thus, the weights are differences
  61. % of weights for two low-pass filters.

  62. % Construct filter weights for bandpass filter (a(0)....a(K)).

  63. akvec=zeros(1,K+1);

  64. akvec(1)=(omubar-omlbar)/(pi);% weight at k=0

  65. for k=1:K;
  66. akvec(k+1)=(sin(k*omubar)-sin(k*omlbar))/(k*pi); % weights at k=1,2,...K
  67. end

  68. % Impose constraint on frequency response at om = 0
  69. % (If high pass filter, this amounts to requiring that weights sum to zero).
  70. % (If low pass filter, this amounts to requiring that weights sum to one).

  71. if (dn>1000)
  72. disp('dn > 1000: assuming low pass filter')
  73. phi=1;
  74. else
  75. phi=0;
  76. end

  77. % sum of weights without constraint
  78. theta=akvec(1)+2*sum(akvec(2:K+1));
  79. % amount to add to each nonzero lag/lead to get sum = phi
  80. theta=(phi-theta)/(2*K+1);
  81. % adjustment of weights
  82. akvec=akvec+theta;

  83. % filter the time series
  84. yf=filtk(y,akvec);

  85. if (r<c)
  86. yf=yf';
  87. end
  88. 
复制代码
插入附件,特别大也许会消耗论坛流量,因为有143M 这样大。 文件夹里有数据、主程序脚本文件、函数文件。 希望对大家的学习有帮助,未来三年推动国内的动态宏观经济学建模向国际一流接近。
因为太大所以我用了网盘,发链接吧。
链接:https://pan.baidu.com/s/1XyKiuoi5g5r_8L2Qregjhw
提取码:取消密码公布
「经管之家」APP:经管人学习、答疑、交友,就上经管之家!
免流量费下载资料----在经管之家app可以下载论坛上的所有资源,并且不额外收取下载高峰期的论坛币。
涵盖所有经管领域的优秀内容----覆盖经济、管理、金融投资、计量统计、数据分析、国贸、财会等专业的学习宝库,各类资料应有尽有。
来自五湖四海的经管达人----已经有上千万的经管人来到这里,你可以找到任何学科方向、有共同话题的朋友。
经管之家(原人大经济论坛),跨越高校的围墙,带你走进经管知识的新世界。
扫描下方二维码下载并注册APP
本文关键词:

本文论坛网址:https://bbs.pinggu.org/thread-8671186-1-1.html

人气文章

1.凡人大经济论坛-经管之家转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
经管之家 人大经济论坛 大学 专业 手机版