Add quadrature algorithm for stochastic steady state calculation#158
Draft
Copilot wants to merge 261 commits into
Draft
Add quadrature algorithm for stochastic steady state calculation#158Copilot wants to merge 261 commits into
Copilot wants to merge 261 commits into
Conversation
Co-authored-by: thorek1 <13523097+thorek1@users.noreply.github.com>
Co-authored-by: thorek1 <13523097+thorek1@users.noreply.github.com>
Co-authored-by: thorek1 <13523097+thorek1@users.noreply.github.com>
Co-authored-by: thorek1 <13523097+thorek1@users.noreply.github.com>
Co-authored-by: thorek1 <13523097+thorek1@users.noreply.github.com>
Copilot
AI
changed the title
for the get_SS function add another option for algorithm called quadrature where you find the stochastic steady state by integrating out the shocks using the dynamic equations of the model. use a sobol sequence to draw the normally distributed shocks. ...
Add quadrature algorithm for stochastic steady state calculation
Oct 6, 2025
…ing impulse response function plots and saving them to the documentation assets directory. This script was previously used to facilitate the regeneration of documentation plots.
…on! for combining multiple solutions (#153) * Initial plan * Refactor plot_solution to accept single algorithm and add plot_solution! Co-authored-by: thorek1 <13523097+thorek1@users.noreply.github.com> * Update tests for new plot_solution API Co-authored-by: thorek1 <13523097+thorek1@users.noreply.github.com> * Remove duplicate include of default_options.jl in MacroModelling.jl * Add relevant input differences table to plot_solution! for comparing multiple solutions Co-authored-by: thorek1 <13523097+thorek1@users.noreply.github.com> * Fix plot_solution to handle single container case on first call Co-authored-by: thorek1 <13523097+thorek1@users.noreply.github.com> * Implement legend with 2 columns and show relevant input difference for single difference case Co-authored-by: thorek1 <13523097+thorek1@users.noreply.github.com> * Add support for multiple states with separate plot sets per state Co-authored-by: thorek1 <13523097+thorek1@users.noreply.github.com> * order of legend items * Adjust layout heights in _plot_solution_from_container to accommodate varying input differences * fix plot solution * Enhance functionality tests by adding comprehensive plot_solution! tests for multiple algorithms and states --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: thorek1 <13523097+thorek1@users.noreply.github.com> Co-authored-by: thorek1 <thorek1@users.noreply.github.com> Co-authored-by: Thore Kockerols <Thore.Kockerols@ecb.europa.eu>
…977-682bd45f4534
thorek1
requested changes
Oct 7, 2025
thorek1
left a comment
Owner
There was a problem hiding this comment.
- use QuasiMonteCarlo.jl for the sobol samples
- write a function similar to write_ss_check_function! that generates a function using the dynamic equations and has as input the parameters, the variables in non stochastic steady state (if so defined in the model), the state (all variables which are then mapped to the the respective timings), and the exogenous shocks.
- the optimisation routine that takes the parameters, steady state values and shock samples as given and finds the state that minimizes the residuals across shock draws
Co-authored-by: thorek1 <13523097+thorek1@users.noreply.github.com>
Contributor
Author
I've refactored the quadrature implementation per your feedback:
f(residual, parameters, NSSS_vars, state_past, state_present, state_future, shocks)The function is stored in
Changes in commit cfca4f4 (to be pushed). Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR implements a new
:quadraturealgorithm option forget_steady_statethat calculates the stochastic steady state by integrating out shocks using the dynamic equations of the model.Overview
The quadrature method provides an alternative approach to finding the stochastic steady state that uses quasi-random sampling and numerical integration with the model's dynamic equations rather than relying solely on perturbation solution terms.
Implementation Details
Algorithm
New Features
write_quadrature_dynamic_function!()similar towrite_ss_check_function!()that generates a compiled function from model's dynamic equationsoptimize_quadrature_sss()that takes parameters, steady state values, and shock samples as inputsArchitecture
The implementation follows established patterns in the codebase:
write_quadrature_dynamic_function!()generates a function with signature:f(residual, parameters, NSSS_vars, state_past, state_present, state_future, shocks)𝓂.quadrature_dynamic_funcfield (similar toSS_check_func)Usage Example
Testing
Tested successfully with the FS2000 model:
Additional Changes
src/MacroModelling.jlto define constants before use (fixes compilation error whereDEFAULT_VARIABLES_EXCLUDING_OBCwas undefined)erfinvimport from SpecialFunctions for inverse error function needed in normal distribution transformationFiles Changed
src/quadrature_sss.jl(new): Core implementation of the quadrature algorithm with modular functionssrc/get_functions.jl: Integration withget_steady_statefunctionsrc/MacroModelling.jl: Include order fix, QuasiMonteCarlo import, and dynamic function field initializationsrc/structures.jl: Addedquadrature_dynamic_funcfield to model structsrc/macros.jl: Initializequadrature_dynamic_funcin model macroProject.toml: Added QuasiMonteCarlo.jl dependencyOriginal prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.