Skip to content

Fix remittances in aggregate resource constraint#1036

Merged
jdebacker merged 4 commits intoPSLmodels:masterfrom
rickecon:remit
Jun 23, 2025
Merged

Fix remittances in aggregate resource constraint#1036
jdebacker merged 4 commits intoPSLmodels:masterfrom
rickecon:remit

Conversation

@rickecon
Copy link
Copy Markdown
Member

This PR fixes a sign error typo on the remittances term in the aggregate resource constraint.

  • Fixes the sign error on the RM term in aggregates.py, resource_constraint() function.
  • Added a test with positive remittances to test_aggregates.py, test_resource_constraint() function.

I also ran a test execution script that took the baseline specification from run_ogcore_example.py and added the Philippine remittance calibration specification.

og_spec = {
    "frisch": 0.41,
    "start_year": START_YEAR,
    "cit_rate": [[0.21]],
    "debt_ratio_ss": 1.0,
    "alpha_T": alpha_T.tolist(),
    "alpha_G": alpha_G.tolist(),
    "initial_guess_r_SS": 0.04,
    "alpha_RM_1": 0.083,
    "alpha_RM_T": 0.083,
    "g_RM": [0.03]
}

This specification ran perfectly in both the SS and TPI computations.

Steady-state equilibrium computation output

GE loop errors = [1.6329923524516232e-12, 1.6438933547746615e-12, 1.6328050023162177e-11, 0.0, -8.956169139651138e-13, 6.089226345373788e-13, 7.715633687510604e-13, 2.642833868415906e-12, 5.010644676950449e-13, -4.038141349083091e-13, 2.54230664298305e-12, -3.54231401156202e-13, -8.060219158778636e-14, 1.0793865801161928e-12]
Iteration: 1  Distance: 8.828619615632333e-11
SS debt = 0.6165550819911706, 0.007838787715122064
IO: (1, 1), C: (1,)
Foreign debt holdings = 0.24662203279646824
Foreign capital holdings = 0.036461601788039456
resource constraint: [-9.03652153e-14]
Checking constraints on capital, labor, and consumption.
	There were no violations of the constraints on labor  supply.
	There were no violations of the constraints on  consumption.
Maximum error in labor FOC = 3.552713678800501e-13
Maximum error in savings FOC = 3.7347902548390266e-13
JUST SAVED SS output to  /Users/richardevans/Docs/Economics/OSE/OG/OG-Core/run_examples/OG-Core-RM-PHL/OUTPUT_BASELINE/SS/SS_vars.pkl

Transition path equilibrium computation output (24 min 0 sec)

Maximum debt ratio:  1.493724944224733
w diff: 8.17279948162053e-07, -2.137170427296553e-07
r diff: 3.129908086180189e-08, -1.232675157711305e-07
r_p diff: -1.1151960258026783e-09, -1.2603517966780498e-07
p_m diff: 0.0, 0.0
BQ diff: 1.168565591166959e-07, -1.7487559615669834e-08
TR diff: 4.597033187447863e-08, -2.91214937969686e-07
Iteration: 21
	Distance: 6.188478319354992e-06
Max absolute value resource constraint error: 7.955282764621208e-07
Checking time path for violations of constraints.
Max Euler error, savings: 3.970657136420641e-12
Max Euler error labor supply: 9.401368572525826e-13
Time path iteration complete.
It took 1440.3786189556122 seconds to get that part done.
run time =  1440.3799769878387

Merging this PR will resolve and close Issue #1035 and will allow us update the remittances calibration in the OG-PHL repository (see OG-PHL Issue #40 and PR #39 thread).

cc: @jdebacker

@rickecon rickecon linked an issue Jun 23, 2025 that may be closed by this pull request
@rickecon
Copy link
Copy Markdown
Member Author

@jdebacker. I checked everywhere else in the theory to see if there were any other errors, and I couldn't find any. The test run that I ran locally on my machine (see above output) worked great. This is ready to merge as soon as you review.

@jdebacker
Copy link
Copy Markdown
Member

@rickecon Looks very good.

Can you go ahead and fix the resource constraint equations in the docs? e.g. this one

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Jun 23, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.67%. Comparing base (e35cfd5) to head (8848a71).
⚠️ Report is 299 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1036   +/-   ##
=======================================
  Coverage   72.67%   72.67%           
=======================================
  Files          20       20           
  Lines        5068     5068           
=======================================
  Hits         3683     3683           
  Misses       1385     1385           
Flag Coverage Δ
unittests 72.67% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
ogcore/__init__.py 100.00% <100.00%> (ø)
ogcore/aggregates.py 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rickecon
Copy link
Copy Markdown
Member Author

@jdebacker. The resource constraint is correct everywhere in the documentation that I can find it. Equation (121) is correct and has this form:

$$ Y = C + I + G - RM $$

The minus is like imports. They are subtracted off the right-hand-side. But the resource constraint error should be the following:

$$ error = Y - C - I - G + RM $$

The issue was that I had the resource constraint error as "minus RM" rather than "plus RM". That is fixed now, and all the documentation was right all along.

@jdebacker jdebacker merged commit 1a943f4 into PSLmodels:master Jun 23, 2025
8 checks passed
@rickecon rickecon deleted the remit branch March 30, 2026 07:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remittance theory and code need to be fixed

3 participants