econ-ark / CGMPortfolio

7 stars 4 forks source link

A problem #11

Open kingarthur72 opened 1 week ago

kingarthur72 commented 1 week ago

I ran the code in this webpage on my local computer:

https://github.com/econ-ark/CGMPortfolio/blob/master/Code/Python/CGMPortfolio.ipynb

I ran into the following error:

image

I am using Anaconda: Anaconda3-2024.06-1-Windows-x86_64.exe

Please check.

Thanks.

MridulS commented 1 week ago

Can you post the whole error message?

kingarthur72 commented 1 week ago

The Error Message.pdf

kingarthur72 commented 1 week ago

Exception Traceback (most recent call last) Cell In[3], line 2 1 # Solve the model with the given parameters ----> 2 agent = cpm.PortfolioConsumerType(**dict_portfolio) 3 agent.solve()

File ~\AppData\Local\anaconda3\Lib\site-packages\HARK\ConsumptionSaving\ConsPortfolioModel.py:172, in PortfolioConsumerType.init(self, verbose, quiet, kwds) 169 self.PortfolioBool = True 171 # Initialize a basic consumer type --> 172 RiskyAssetConsumerType.init(self, verbose=verbose, quiet=quiet, kwds) 174 # Set the solver for the portfolio model, and update various constructed attributes 175 if self.IndepDstnBool:

File ~\AppData\Local\anaconda3\Lib\site-packages\HARK\ConsumptionSaving\ConsRiskyAssetModel.py:70, in IndShockRiskyAssetConsumerType.init(self, verbose, quiet, kwds) 67 self.sim_common_Rrisky = True 69 # Initialize a basic consumer type ---> 70 IndShockConsumerType.init(self, verbose=verbose, quiet=quiet, kwds) 72 # These method must be overwritten by classes that inherit from 73 # RiskyAssetConsumerType 74 if self.PortfolioBool:

File ~\AppData\Local\anaconda3\Lib\site-packages\HARK\ConsumptionSaving\ConsIndShockModel.py:2295, in IndShockConsumerType.init(self, verbose, quiet, **kwds) 2293 solver = ConsIndShockSolver 2294 self.solve_one_period = make_one_period_oo_solver(solver) -> 2295 self.update()

File ~\AppData\Local\anaconda3\Lib\site-packages\HARK\ConsumptionSaving\ConsPortfolioModel.py:191, in PortfolioConsumerType.update(self) 190 def update(self): --> 191 RiskyAssetConsumerType.update(self) 192 self.update_ShareGrid() 193 self.update_ShareLimit()

File ~\AppData\Local\anaconda3\Lib\site-packages\HARK\ConsumptionSaving\ConsRiskyAssetModel.py:88, in IndShockRiskyAssetConsumerType.update(self) 87 def update(self): ---> 88 IndShockConsumerType.update(self) 89 self.update_AdjustDstn() 90 self.update_RiskyDstn()

File ~\AppData\Local\anaconda3\Lib\site-packages\HARK\ConsumptionSaving\ConsIndShockModel.py:2348, in IndShockConsumerType.update(self) 2336 def update(self): 2337 """ 2338 Update the income process, the assets grid, and the terminal solution. 2339 (...) 2346 None 2347 """ -> 2348 self.update_income_process() 2349 self.update_assets_grid() 2350 self.update_solution_terminal()

File ~\AppData\Local\anaconda3\Lib\site-packages\HARK\ConsumptionSaving\ConsIndShockModel.py:2313, in IndShockConsumerType.update_income_process(self) 2297 def update_income_process(self): 2298 """ 2299 Updates this agent's income process based on his own attributes. 2300 (...) 2307 none 2308 """ 2309 ( 2310 IncShkDstn, 2311 PermShkDstn, 2312 TranShkDstn, -> 2313 ) = self.construct_lognormal_income_process_unemployment() 2314 self.IncShkDstn = IncShkDstn 2315 self.PermShkDstn = PermShkDstn

File ~\AppData\Local\anaconda3\Lib\site-packages\HARK\ConsumptionSaving\ConsIndShockModel.py:3733, in IndShockConsumerType.construct_lognormal_income_process_unemployment(self) 3729 self.neutral_measure = False 3731 neutral_measure_list = [self.neutral_measure] * len(PermShkCount_list) -> 3733 IncShkDstn = IndexDistribution( 3734 engine=BufferStockIncShkDstn, 3735 conditional={ 3736 "sigma_Perm": PermShkStd, 3737 "sigma_Tran": TranShkStd, 3738 "n_approx_Perm": PermShkCount_list, 3739 "n_approx_Tran": TranShkCount_list, 3740 "neutral_measure": neutral_measure_list, 3741 "UnempPrb": UnempPrb_list, 3742 "IncUnemp": IncUnemp_list, 3743 }, 3744 RNG=self.RNG, 3745 seed=self.RNG.integers(0, 231 - 1), 3746 ) 3748 PermShkDstn = IndexDistribution( 3749 engine=LognormPermIncShk, 3750 conditional={ (...) 3756 seed=self.RNG.integers(0, 231 - 1), 3757 ) 3759 TranShkDstn = IndexDistribution( 3760 engine=MixtureTranIncShk, 3761 conditional={ (...) 3768 seed=self.RNG.integers(0, 2**31 - 1), 3769 )

File ~\AppData\Local\anaconda3\Lib\site-packages\HARK\distribution.py:1315, in IndexDistribution.init(self, engine, conditional, RNG, seed) 1310 self.dstns = [ 1311 self.engine(seed=self._rng.integers(0, 231 - 1), conditional) 1312 ] 1314 else: -> 1315 raise ( 1316 Exception( 1317 f"IndexDistribution: Unhandled case for getitem access. item0: {item0}; conditional: {self.conditional}" 1318 ) 1319 )

Exception: IndexDistribution: Unhandled case for getitem access. item0: [0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563 0.1029563]; conditional: {'sigma_Perm': array([0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563, 0.1029563]), 'sigma_Tran': array([0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155, 0.27166155]), 'n_approx_Perm': [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], 'n_approx_Tran': [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], 'neutral_measure': [False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False], 'UnempPrb': [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 'IncUnemp': [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]} Click to add a cell.

kingarthur72 commented 1 week ago

Hi, Mridul,

I posted the error in two formats: PDF and Text.

Thanks.

Arthur