From c860850e2448f308f5e9b22543752ecb4ecc9f64 Mon Sep 17 00:00:00 2001 From: Adriano Meligrana <68152031+Tortar@users.noreply.github.com> Date: Fri, 29 Nov 2024 00:01:20 +0100 Subject: [PATCH] Update scenario_analysis_via_shock.jl --- examples/scenario_analysis_via_shock.jl | 30 ++++++++++++++----------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/examples/scenario_analysis_via_shock.jl b/examples/scenario_analysis_via_shock.jl index 4d84da9..ea5ac6f 100644 --- a/examples/scenario_analysis_via_shock.jl +++ b/examples/scenario_analysis_via_shock.jl @@ -1,26 +1,28 @@ # # Scenario analysis via custom shocks -# In this tutorial we will illustrate how to perform a scenario analysis by running the model multiple times -# under a specific shock and comparing the results with the unshocked model. +# In this tutorial we will illustrate how to perform a scenario analysis by +# running the model multiple times under a specific shock and comparing the +# results with the unshocked model. import BeforeIT as Bit using Plots, StatsPlots - parameters = Bit.AUSTRIA2010Q1.parameters initial_conditions = Bit.AUSTRIA2010Q1.initial_conditions -# initialise the model and the data collector +# Initialise the model and the data collector T = 20 model = Bit.init_model(parameters, initial_conditions, T); # Simulate the model for T quarters data_vec_baseline = Bit.run_n_sims(model, 4) -# Now, apply a shock to the model and simulate it again -# A shock is simply a function that takes the model and changes some of its parameters for a specific time period. +# Now, apply a shock to the model and simulate it again. +# A shock is simply a function that takes the model and changes some of +# its parameters for a specific time period. -# In this case, let's define an interest rate shock that sets the interest rate for a number of epochs. +# In this case, let's define an interest rate shock that sets the interest +# rate for a number of epochs. # We do this by first defining a "struct" with some useful attributes struct CustomShock @@ -28,15 +30,16 @@ struct CustomShock final_time::Int # number of epochs for the shock end -# and then by making the struct a callable function that changes the interest rate in the model, -# this is done in Julia using the syntax below +# and then by making the struct a callable function that changes the interest +# rate in the model, this is done in Julia using the syntax below function (s::CustomShock)(model::Bit.Model) if model.agg.t <= s.final_time model.cb.r_bar = s.rate end end -# Now we define a specific shock with a rate of 0.01 for the first 10 epochs, and run a shocked simulation +# Now we define a specific shock with a rate of 0.01 for the first 10 epochs, +# and run a shocked simulation custom_shock = CustomShock(0.0, 10) data_vec_shocked = Bit.run_n_sims(model, 4; shock = custom_shock) @@ -63,6 +66,7 @@ StatsPlots.errorline!( ylabel = "GDP", ) -# Note that, importantly, once the function central_bank_rate has been changed, the model will use the new -# interest rate in all the simulations, unless the function is changed again. -# To restore the original interest rate, we can simply re-import the function central_bank_rate +# Note that, importantly, once the function `central_bank_rate` has been changed, +# the model will use the new interest rate in all the simulations, unless the function +# is changed again. To restore the original interest rate, we can simply re-import the +# function `central_bank_rate`.