PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/pymaclab/tests/stats_tests/var_sw_jep.py

https://github.com/TomAugspurger/pymaclab
Python | 167 lines | 127 code | 6 blank | 34 comment | 6 complexity | 718c95784300d7ea01e216f3baa53713 MD5 | raw file
Possible License(s): Apache-2.0
  1. import pandas
  2. import numpy
  3. import matplotlib
  4. from matplotlib import pyplot as plt
  5. from pymaclab import newVAR
  6. import os
  7. modconfig = {}
  8. # This model's name or title, used for pickling results
  9. modname = 'STOCKWATSON_jep_model'
  10. modconfig['modname'] = modname
  11. # Get the data from the directory
  12. datafile = 'stwat_jpe_2001.csv'
  13. modconfig['datafile'] = datafile
  14. datapath = '../data/'
  15. modconfig['datapath'] = datapath
  16. data = pandas.read_csv(os.path.join(datapath,datafile),delimiter=';')
  17. data = data[52:-1] # Select data range
  18. data = data[:164] # Further restriction on data, because commodity index is longer
  19. # Define frequency of data
  20. freq = 'Q'
  21. modconfig['freq'] = freq
  22. # Should the data be standardized?
  23. trans_data = False
  24. modconfig['trans_data'] = trans_data
  25. # Define the number of lags in the VAR
  26. nlags = 4
  27. modconfig['nlags'] = nlags
  28. # How many periods for IRFs ?
  29. irfp = 25
  30. modconfig['irfp'] = irfp
  31. # Calculate variance decomposition?
  32. do_vdc = True
  33. modconfig['do_vdc'] = do_vdc
  34. # How many periods forecast for variance decomposition ?
  35. vdcp = 20
  36. modconfig['vdcp'] = vdcp
  37. # Use the svname matrix for alternative shocks?
  38. use_svnames = False
  39. modconfig['use_svnames'] = use_svnames
  40. # Transform log variables in IRFs into percentages ?
  41. translog = False
  42. modconfig['translog'] = translog
  43. # Transform the percentage responses back into absolutes from the mean ?
  44. transperc = False
  45. modconfig['transperc'] = transperc
  46. # Add impact matrix to Cholesky responses ?
  47. cholimp = False
  48. modconfig['cholimp'] = cholimp
  49. # How many matrices for MA Representation
  50. maxphi = irfp+2
  51. modconfig['maxphi'] = maxphi
  52. # Boostrap IRF confidence intervals ?
  53. bootstrap = True
  54. modconfig['bootstrap'] = bootstrap
  55. ####################### This is experimental stuff, need to clarify the difference between the two #####################
  56. killian_bsinbs = True
  57. modconfig['killian_bsinbs'] = killian_bsinbs
  58. ########################################################################################################################
  59. ########################################## Graphing options for IRFs and other graphs ##################################
  60. graph_options = {}
  61. graph_options['labels'] = {}
  62. graph_options['labels']['title'] = True
  63. graph_options['labels']['xlabel'] = False
  64. graph_options['labels']['ylabel'] = True
  65. graph_options['labels']['text_fs'] = 10
  66. graph_options['labels']['ylabel_fs'] = 10
  67. graph_options['labels']['xlabel_fs'] = 10
  68. graph_options['labels']['title_fs'] = 12
  69. graph_options['labels']['label_fs'] = 8
  70. graph_options['labels']['xticks_fs'] = 8
  71. graph_options['labels']['yticks_fs'] = 8
  72. graph_options['labels']['legend_fs'] = 8
  73. graph_options['labels']['use_tex'] = False
  74. graph_options['lines'] = {}
  75. graph_options['lines']['width'] = 2.0
  76. graph_options['grid'] = True
  77. graph_options['irfs'] = {}
  78. graph_options['irfs']['outer_colour'] = '#D3B0B0'
  79. graph_options['irfs']['inner_colour'] = '#EED6D6'
  80. graph_options['irfs']['line_colour'] = 'black'
  81. graph_options['irfs']['biased_line'] = True # This allows you to also show the biased IRF when Killian's b-i-b option is on
  82. graph_options['irfs']['biased_line_type'] = 'g--'
  83. graph_options['save'] = {}
  84. graph_options['save']['format'] = {}
  85. graph_options['save']['format']['eps'] = True
  86. graph_options['save']['format']['pdf'] = True
  87. modconfig['graph_options'] = graph_options
  88. #########################################################################################################################
  89. # Draw a horizontal zero line into each IRF Plot
  90. hzline = True
  91. modconfig['hzline'] = hzline
  92. # How thick should the hline be?
  93. hzline_width = 1.0
  94. modconfig['hzline_width'] = hzline_width
  95. # How many draws for bootstrap ?
  96. bdraw = 1000
  97. modconfig['bdraw'] = bdraw
  98. # Use multicore processors to speed up bootstrap?
  99. multicpu = True
  100. modconfig['multicpu'] = multicpu
  101. # Specify number of cpu cores or set to 'auto'
  102. ncpus = 'auto'
  103. modconfig['ncpus'] = ncpus
  104. # Level of significance for bootstrap confidence intervals
  105. signif = [0.66,0.95] # implies 1-alpha = 0.66, use 'mix' to graph a variety of CI
  106. modconfig['signif'] = signif
  107. # What kind of intercept/time trend?
  108. const_term = 'ct' # Can be 'None', 'cc' or 'tt'
  109. modconfig['const_term'] = const_term
  110. # Pickle the model run results and settings
  111. pickle_switch = False
  112. # Define the names of the vars used
  113. vnames = []
  114. vnames.append('INF')
  115. vnames.append('LHUR')
  116. vnames.append('FYFF')
  117. modconfig['vnames'] = vnames
  118. # Define the names for the vnames used in plotting
  119. pnames = {}
  120. pnames['INF'] = 'Inflation'
  121. pnames['LHUR'] = 'Unemployment'
  122. pnames['FYFF'] = 'Federal Funds Rate'
  123. # Create the data modification dictionary
  124. tcode_dic = {}
  125. clist = [1,1,1]
  126. for i1,vname in enumerate(vnames):
  127. tcode_dic[vname] = clist[i1]
  128. modconfig['tcode'] = tcode_dic
  129. # Define a matrix for scaling the orthogonalized shock
  130. svnames = {}
  131. for name in vnames:
  132. svnames[name] = 1.0
  133. modconfig['svnames'] = svnames
  134. # Set the transperc_dic
  135. transperc_dic = {}
  136. for name in vnames:
  137. transperc_dic[name] = False
  138. transperc_dic['employment'] = True
  139. modconfig['transperc_dic'] = transperc_dic
  140. # Get the individual series of interest
  141. loglist = []
  142. modconfig['loglist'] = loglist
  143. tlist = []
  144. for name in vnames:
  145. if name in loglist:
  146. tlist.append(data[name].values)
  147. else:
  148. tlist.append(data[name].values)
  149. matd = numpy.array(tlist)
  150. # Transpose and get the dims
  151. matd = matd.T
  152. cols = matd.shape[1]
  153. rows = matd.shape[0]
  154. modconfig['cols'] = cols
  155. modconfig['rows'] = rows
  156. swvar = newVAR(data=matd,vnames=vnames,pnames=pnames,svnames=svnames,irfs=True,boot=True,plot=True,conf=modconfig,mesg=True)
  157. '''
  158. tsvar = var_model.VAR(matd,['INF','LHUR','FYFF'])
  159. tsvar_res = tsvar.fit(4,trend='ct')
  160. '''