How to use soe method in fMBT

Best Python code snippet using fMBT_python

StickyEparams.py

Source:StickyEparams.py Github

copy

Full Screen

1'''2This module holds calibrated parameter dictionaries for the cAndCwithStickyE paper.3It defines dictionaries for the six types of models in cAndCwithStickyE:4 51) Small open economy62) Small open Markov economy73) Cobb-Douglas closed economy84) Cobb-Douglas closed Markov economy95) Representative agent economy106) Markov representative agent economy11 12For the first four models (heterogeneous agents), it defines dictionaries for13the Market instance as well as the consumers themselves. All parameters are quarterly.14'''15#import sys 16#import os17#sys.path.insert(0, os.path.abspath('../'))18import numpy as np19from copy import copy20from HARKutilities import approxUniform21# Choose file where the Stata executable can be found. This should point at the22# exe file itself, but the string does not need to include '.exe'. Two examples23# are included (for locations on two authors' local computers). This variable24# is irrelevant when the use_stata boolean in cAndCwithStickyE.py is set to False.25# Using Stata to run the regressions allows the tables to include the KP test26# statistic; Python's statsmodels.api currently does not have this functionality.27# NOTE: To successfully use_stata, you must have Baum, Schaffer, and Stillman's28# ivreg2 Stata module installed, as well as Kleibergen and Schaffer's ranktest29# module. These modules are archived by RePEc IDEAS at:30# https://ideas.repec.org/c/boc/bocode/s425401.html31# https://ideas.repec.org/c/boc/bocode/s456865.html32# You can also simply type "ssc install ivreg2" and "ssc install ranktest" in Stata.33#stata_exe = "C:\Program Files (x86)\Stata14\stataMP-64"34stata_exe = "C:\Program Files (x86)\Stata15\StataSE-64"35# Choose directory paths relative to the StickyE files36calibration_dir = "./Calibration/" # Relative directory for primitive parameter files37tables_dir = "./Tables/" # Relative directory for saving tex tables38results_dir = "./Results/" # Relative directory for saving output files39figures_dir = "./Figures/" # Relative directory for saving figures40def importParam(param_name):41 return float(np.max(np.genfromtxt(calibration_dir + param_name + '.txt')))42# Import primitive parameters from calibrations folder43CRRA = importParam('CRRA') # Coefficient of relative risk aversion44DeprFacAnn = importParam('DeprFacAnn') # Annual depreciation factor45CapShare = importParam('CapShare') # Capital's share in production function46KYratioSS = importParam('KYratioSS') # Steady state capital to output ratio (PF-DSGE)47UpdatePrb = importParam('UpdatePrb') # Probability that each agent observes the aggregate productivity state each period (in sticky version)48UnempPrb = importParam('UnempPrb') # Unemployment probability49DiePrb = importParam('DiePrb') # Quarterly mortality probability50TranShkVarAnn = importParam('TranShkVarAnn') # Annual variance of idiosyncratic transitory shocks51PermShkVarAnn = importParam('PermShkVarAnn') # Annual variance of idiosyncratic permanent shocks52TranShkAggVar = importParam('TranShkAggVar') # Variance of aggregate transitory shocks53PermShkAggVar = importParam('PermShkAggVar') # Variance of aggregate permanent shocks54DiscFacSOE = importParam('betaSOE') # Discount factor, SOE model55# Calculate parameters based on the primitive parameters56DeprFac = 1. - DeprFacAnn**0.25 # Quarterly depreciation rate57KSS = KtYratioSS = KYratioSS**(1./(1.-CapShare)) # Steady state Capital to labor productivity58wRteSS = (1.-CapShare)*KSS**CapShare # Steady state wage rate59rFreeSS = CapShare*KSS**(CapShare-1.) # Steady state interest rate60RfreeSS = 1. - DeprFac + rFreeSS # Steady state return factor61LivPrb = 1. - DiePrb # Quarterly survival probability62DiscFacDSGE = RfreeSS**(-1) # Discount factor, HA-DSGE and RA models63TranShkVar = TranShkVarAnn*4. # Variance of idiosyncratic transitory shocks64PermShkVar = PermShkVarAnn/4. # Variance of idiosyncratic permanent shocks65#TempDstn = approxMeanOneLognormal(N=7,sigma=np.sqrt(PermShkVar))66#DiscFacSOE = 0.99*LivPrb/(RfreeSS*np.dot(TempDstn[0],TempDstn[1]**(-CRRA))) # Discount factor, SOE model67# Choose basic simulation parameters68periods_to_sim = 21010 # Total number of periods to simulate; this might be increased by DSGEmarkov model69ignore_periods = 1000 # Number of simulated periods to ignore (in order to ensure we are near steady state)70interval_size = 200 # Number of periods in each subsample interval71AgentCount = 20000 # Total number of agents to simulate in the economy72# Use smaller sample for micro regression tables to save memory73periods_to_sim_micro = 400074AgentCount_micro = 500075# Choose extent of discount factor heterogeneity (inapplicable to representative agent models)76TypeCount = 1 # Number of heterogeneous discount factor types77DiscFacMeanSOE = DiscFacSOE # Central value of intertemporal discount factor for SOE model78DiscFacMeanDSGE = DiscFacDSGE # ...for HA-DSGE and RA79DiscFacSpread = 0.0 # Half-width of intertemporal discount factor band, a la cstwMPC80# These parameters are for a rough "beta-dist" specification that fits the wealth distribution in DSGE simple81#TypeCount = 782#DiscFacMeanSOE = 0.9673883#DiscFacMeanDSGE = 0.96738 84#DiscFacSpread = 0.0227 85# Choose parameters for the Markov models86StateCount = 11 # Number of discrete states in the Markov specifications87PermGroFacMin = 0.9925 # Minimum value of aggregate permanent growth in Markov specifications88PermGroFacMax = 1.0075 # Maximum value of aggregate permanent growth in Markov specifications89Persistence = 0.5 # Base probability that macroeconomic Markov state stays the same; else moves up or down by 190RegimeChangePrb = 0.00 # Probability of "regime change", randomly jumping to any Markov state91# Make the Markov array with chosen states, persistence, and regime change probability92PolyMrkvArray = np.zeros((StateCount,StateCount))93for i in range(StateCount):94 for j in range(StateCount):95 if i==j:96 PolyMrkvArray[i,j] = Persistence97 elif (i==(j-1)) or (i==(j+1)):98 PolyMrkvArray[i,j] = 0.5*(1.0 - Persistence)99PolyMrkvArray[0,0] += 0.5*(1.0 - Persistence)100PolyMrkvArray[StateCount-1,StateCount-1] += 0.5*(1.0 - Persistence)101PolyMrkvArray *= 1.0 - RegimeChangePrb102PolyMrkvArray += RegimeChangePrb/StateCount103# Define the set of aggregate permanent growth factors that can occur (Markov specifications only)104PermGroFacSet = np.exp(np.linspace(np.log(PermGroFacMin),np.log(PermGroFacMax),num=StateCount))105# Define the set of discount factors that agents have (for SOE and DSGE models)106DiscFacSetSOE = approxUniform(N=TypeCount,bot=DiscFacMeanSOE-DiscFacSpread,top=DiscFacMeanSOE+DiscFacSpread)[1]107DiscFacSetDSGE = approxUniform(N=TypeCount,bot=DiscFacMeanDSGE-DiscFacSpread,top=DiscFacMeanDSGE+DiscFacSpread)[1]108###############################################################################109# Define parameters for the small open economy version of the model110init_SOE_consumer = { 'CRRA': CRRA,111 'DiscFac': DiscFacMeanSOE,112 'LivPrb': [LivPrb],113 'PermGroFac': [1.0],114 'AgentCount': AgentCount/TypeCount, # Spread agents evenly among types115 'aXtraMin': 0.00001,116 'aXtraMax': 40.0,117 'aXtraNestFac': 3,118 'aXtraCount': 48,119 'aXtraExtra': [None],120 'PermShkStd': [np.sqrt(PermShkVar)],121 'PermShkCount': 7,122 'TranShkStd': [np.sqrt(TranShkVar)],123 'TranShkCount': 7,124 'UnempPrb': UnempPrb,125 'UnempPrbRet': 0.0,126 'IncUnemp': 0.0,127 'IncUnempRet': 0.0,128 'BoroCnstArt':0.0,129 'tax_rate':0.0,130 'T_retire':0,131 'MgridBase': np.array([0.5,1.5]),132 'aNrmInitMean' : np.log(0.00001),133 'aNrmInitStd' : 0.0,134 'pLvlInitMean' : 0.0,135 'pLvlInitStd' : 0.0,136 'UpdatePrb' : UpdatePrb,137 'T_age' : None,138 'T_cycle' : 1,139 'cycles' : 0,140 'T_sim' : periods_to_sim141 }142# Define market parameters for the small open economy143init_SOE_market = { 'PermShkAggCount': 5,144 'TranShkAggCount': 5,145 'PermShkAggStd': np.sqrt(PermShkAggVar),146 'TranShkAggStd': np.sqrt(TranShkAggVar),147 'PermGroFacAgg': 1.0,148 'DeprFac': DeprFac,149 'CapShare': CapShare,150 'Rfree': RfreeSS,151 'wRte': wRteSS,152 'act_T': periods_to_sim,153 }154###############################################################################155# Define parameters for the small open Markov economy version of the model156init_SOE_mrkv_consumer = copy(init_SOE_consumer)157init_SOE_mrkv_consumer['MrkvArray'] = PolyMrkvArray158# Define market parameters for the small open Markov economy159init_SOE_mrkv_market = copy(init_SOE_market)160init_SOE_mrkv_market['MrkvArray'] = PolyMrkvArray161init_SOE_mrkv_market['PermShkAggStd'] = StateCount*[init_SOE_market['PermShkAggStd']]162init_SOE_mrkv_market['TranShkAggStd'] = StateCount*[init_SOE_market['TranShkAggStd']]163init_SOE_mrkv_market['PermGroFacAgg'] = PermGroFacSet164init_SOE_mrkv_market['MrkvNow_init'] = StateCount/2165init_SOE_mrkv_market['loops_max'] = 1166###############################################################################167# Define parameters for the Cobb-Douglas DSGE version of the model168init_DSGE_consumer = copy(init_SOE_consumer)169init_DSGE_consumer['DiscFac'] = DiscFacMeanDSGE170init_DSGE_consumer['aXtraMax'] = 120.0171init_DSGE_consumer['MgridBase'] = np.array([0.1,0.3,0.5,0.6,0.7,0.8,0.9,0.98,1.0,1.02,1.1,1.2,1.3,1.4,1.5,1.6,2.0,3.0,5.0])172# Define market parameters for the Cobb-Douglas economy173init_DSGE_market = copy(init_SOE_market)174init_DSGE_market.pop('Rfree')175init_DSGE_market.pop('wRte')176init_DSGE_market['CRRA'] = CRRA177init_DSGE_market['DiscFac'] = DiscFacMeanDSGE178init_DSGE_market['intercept_prev'] = 0.0179init_DSGE_market['slope_prev'] = 1.0180###############################################################################181# Define parameters for the Cobb-Douglas Markov DSGE version of the model182init_DSGE_mrkv_consumer = copy(init_DSGE_consumer)183init_DSGE_mrkv_consumer['MrkvArray'] = PolyMrkvArray 184# Define market parameters for the Cobb-Douglas Markov economy185init_DSGE_mrkv_market = copy(init_SOE_mrkv_market)186init_DSGE_mrkv_market.pop('Rfree')187init_DSGE_mrkv_market.pop('wRte')188init_DSGE_mrkv_market['CRRA'] = init_DSGE_mrkv_consumer['CRRA']189init_DSGE_mrkv_market['DiscFac'] = init_DSGE_mrkv_consumer['DiscFac']190init_DSGE_mrkv_market['intercept_prev'] = StateCount*[0.0]191init_DSGE_mrkv_market['slope_prev'] = StateCount*[1.0]192init_DSGE_mrkv_market['loops_max'] = 10193###############################################################################194# Define parameters for the representative agent version of the model195init_RA_consumer = { 'CRRA': CRRA,196 'DiscFac': DiscFacMeanDSGE,197 'LivPrb': [1.0],198 'PermGroFac': [1.0],199 'AgentCount': 1,200 'aXtraMin': 0.00001,201 'aXtraMax': 120.0,202 'aXtraNestFac': 3,203 'aXtraCount': 48,204 'aXtraExtra': [None],205 'PermShkStd': [np.sqrt(PermShkAggVar)],206 'PermShkCount': 7,207 'TranShkStd': [np.sqrt(TranShkAggVar)],208 'TranShkCount': 7,209 'UnempPrb': 0.0,210 'UnempPrbRet': 0.0,211 'IncUnemp': 0.0,212 'IncUnempRet': 0.0,213 'BoroCnstArt':0.0,214 'tax_rate':0.0,215 'T_retire':0,216 'aNrmInitMean' : np.log(0.00001),217 'aNrmInitStd' : 0.0,218 'pLvlInitMean' : 0.0,219 'pLvlInitStd' : 0.0,220 'PermGroFacAgg' : 1.0,221 'UpdatePrb' : UpdatePrb,222 'CapShare' : CapShare,223 'DeprFac' : DeprFac,224 'T_age' : None,225 'T_cycle' : 1,226 'T_sim' : periods_to_sim,227 'tolerance' : 1e-6228 }229###############################################################################230# Define parameters for the Markov representative agent model231init_RA_mrkv_consumer = copy(init_RA_consumer)232init_RA_mrkv_consumer['MrkvArray'] = PolyMrkvArray233init_RA_mrkv_consumer['MrkvNow'] = [StateCount/2]...

Full Screen

Full Screen

benchmark.py

Source:benchmark.py Github

copy

Full Screen

1import os2import time3import sys4from prettytable import PrettyTable5os.system("make > /dev/null")6soe_names = ["soe", "soe_odd_only",7"soe_odd_only_blockwise", "soe_odd_only_blockwise_sqrt"]8rows = [' ']9for soe_name in soe_names[:2]:10 rows.append(soe_name)11 rows.append(soe_name + " P")12t = PrettyTable(rows)13cur_power = 614N = 10**cur_power15while cur_power <= 11:16 times = ["10^{}".format(cur_power)]17 for soe_name in soe_names[:2]:18 start = time.time()19 if os.system("./main {} {} > /dev/null".format(soe_name, N)):20 times.append("MEM")21 else:22 times.append(round(time.time() - start, 2))23 start = time.time()24 if os.system("./main {} {} {} > /dev/null".format(soe_name, N, "P")):25 times.append("MEM")26 else:27 times.append(round(time.time() - start, 2))28 t.add_row(times)29 N *= 1030 cur_power += 131print(t)...

Full Screen

Full Screen

count_prime_number_sum_that_is_also_prime.py

Source:count_prime_number_sum_that_is_also_prime.py Github

copy

Full Screen

1import math as m2def retSOE(n):3 soe=[True for i in range(0,n+1)]4 soe[0]=False5 soe[1]=False6 for i in range(2,n+1,1):7 if soe[i]:8 for j in range(pow(i,2),n,i):9 soe[j]=False10 return soe11def count_prime_numbers(l,r):12 soe=retSOE(r)13 solution=[]14 for i in range(l,r,1):15 if soe[i]:16 sumOfNum=017 num=i18 while num!=0:19 sumOfNum+=(num%10)20 num//=1021 if soe[sumOfNum]:22 solution.append(i)23 return len(solution)24 ...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run fMBT automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful