Coverage for HARK / ConsumptionSaving / ConsLabeledModel.py: 100%

10 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-01-25 05:22 +0000

1""" 

2ConsLabeledModel - Labeled consumption-saving models using xarray. 

3 

4This module provides consumption-saving models that use xarray's labeled 

5data structures for clear variable naming and easier manipulation of results. 

6 

7The implementation has been refactored into the labeled/ subpackage. 

8This file provides backwards-compatible imports. 

9 

10Classes 

11------- 

12ValueFuncCRRALabeled 

13 Value function interpolation using xarray. 

14ConsumerSolutionLabeled 

15 Solution container for labeled models. 

16ConsPerfForesightLabeledSolver 

17 Solver for perfect foresight model. 

18ConsIndShockLabeledSolver 

19 Solver for model with income shocks. 

20ConsRiskyAssetLabeledSolver 

21 Solver for model with risky asset. 

22ConsFixedPortfolioLabeledSolver 

23 Solver for model with fixed portfolio allocation. 

24ConsPortfolioLabeledSolver 

25 Solver for model with optimal portfolio choice. 

26PerfForesightLabeledType 

27 Agent type for perfect foresight. 

28IndShockLabeledType 

29 Agent type with income shocks. 

30RiskyAssetLabeledType 

31 Agent type with risky asset. 

32PortfolioLabeledType 

33 Agent type with portfolio choice. 

34 

35Functions 

36--------- 

37make_solution_terminal_labeled 

38 Create terminal period solution. 

39make_labeled_inc_shk_dstn 

40 Create labeled income shock distribution. 

41make_labeled_risky_dstn 

42 Create labeled risky return distribution. 

43make_labeled_shock_dstn 

44 Create labeled joint shock distribution. 

45""" 

46 

47# Re-export everything from the labeled subpackage 

48from HARK.Labeled import ( 

49 # Solution classes 

50 ConsumerSolutionLabeled, 

51 ValueFuncCRRALabeled, 

52 # Solvers 

53 ConsFixedPortfolioLabeledSolver, 

54 ConsIndShockLabeledSolver, 

55 ConsPerfForesightLabeledSolver, 

56 ConsPortfolioLabeledSolver, 

57 ConsRiskyAssetLabeledSolver, 

58 # Agent types 

59 IndShockLabeledType, 

60 PerfForesightLabeledType, 

61 PortfolioLabeledType, 

62 RiskyAssetLabeledType, 

63 # Factories 

64 make_labeled_inc_shk_dstn, 

65 make_labeled_risky_dstn, 

66 make_labeled_shock_dstn, 

67 make_solution_terminal_labeled, 

68 # Config objects 

69 IND_SHOCK_CONFIG, 

70 PERF_FORESIGHT_CONFIG, 

71 PORTFOLIO_CONFIG, 

72 RISKY_ASSET_CONFIG, 

73) 

74 

75# Backwards compatibility: Build config dicts from new config objects 

76init_perf_foresight_labeled = PERF_FORESIGHT_CONFIG.build_params() 

77init_ind_shock_labeled = IND_SHOCK_CONFIG.build_params() 

78init_risky_asset_labeled = RISKY_ASSET_CONFIG.build_params() 

79init_portfolio_labeled = PORTFOLIO_CONFIG.build_params() 

80 

81# Also export the constructor dicts for backwards compatibility 

82PF_labeled_constructor_dict = init_perf_foresight_labeled.get("constructors", {}) 

83ind_shock_labeled_constructor_dict = init_ind_shock_labeled.get("constructors", {}) 

84risky_asset_labeled_constructor_dict = init_risky_asset_labeled.get("constructors", {}) 

85init_portfolio_labeled_constructors = init_portfolio_labeled.get("constructors", {}) 

86 

87__all__ = [ 

88 # Solution classes 

89 "ValueFuncCRRALabeled", 

90 "ConsumerSolutionLabeled", 

91 # Solvers 

92 "ConsPerfForesightLabeledSolver", 

93 "ConsIndShockLabeledSolver", 

94 "ConsRiskyAssetLabeledSolver", 

95 "ConsFixedPortfolioLabeledSolver", 

96 "ConsPortfolioLabeledSolver", 

97 # Agent types 

98 "PerfForesightLabeledType", 

99 "IndShockLabeledType", 

100 "RiskyAssetLabeledType", 

101 "PortfolioLabeledType", 

102 # Factories 

103 "make_solution_terminal_labeled", 

104 "make_labeled_inc_shk_dstn", 

105 "make_labeled_risky_dstn", 

106 "make_labeled_shock_dstn", 

107 # Config dicts (backwards compatibility) 

108 "init_perf_foresight_labeled", 

109 "init_ind_shock_labeled", 

110 "init_risky_asset_labeled", 

111 "init_portfolio_labeled", 

112 "PF_labeled_constructor_dict", 

113 "ind_shock_labeled_constructor_dict", 

114 "risky_asset_labeled_constructor_dict", 

115 "init_portfolio_labeled_constructors", 

116]