def forecast_dsge(file_name): data_plotter = DataPlotter() raw_model, estimations = parse_model_file(file_name) model = model_builder.build(raw_model) forecast_alg = ForecastAlgorithm(model) # likelihood_algorithm = LikelihoodAlgorithm() preposterior = model.get_prior_posterior() transition_matrix, shock_matrix = model.build_matrices(preposterior) noise_covariance = model.noise_covariance(preposterior) structural_mean = len(model.variables) posterior = NormalVectorDistribution( np.linalg.solve(transition_matrix - np.eye(transition_matrix.shape[0]), np.zeros(transition_matrix.shape[0], dtype='float')), np.zeros((structural_mean, structural_mean)))#model.get_prior_posterior() # _, distribution = likelihood_algorithm.get_likelihood_probability(model, estimations, posterior) posteriors = [(preposterior, posterior)] observables = forecast_alg.calculate(posteriors, 100, 100, estimations.estimation_time, estimations) data_plotter.add_plots(observables.prepare_plots()) data_plotter.draw_plots()
def forecast_blanchard_dsge_debug(file_name): data_plotter = DataPlotter() raw_model, estimations = parse_model_file(file_name) variables, structural, shocks = raw_model.entities() EquationParser.parse_equations_to_matrices(raw_model.equations, variables, shocks)
def run_dsge(file_name): data_plotter = DataPlotter() raw_model, estimations = parse_model_file(file_name) model = model_builder.build(raw_model) likelihood_algorithm = LikelihoodAlgorithm() print("Posterior") print(model.get_prior_posterior()) # retries = 0 rounds = 3 # probability = likelihood_algorithm.get_likelihood_probability(model, estimations, model.get_prior_posterior()) mh_algorithm = RandomWalkMH(rounds, model, estimations, with_covariance=model.posterior_covariance()) posteriors, history = mh_algorithm.calculate_posterior() histories = [history] # print(posteriors.get_post_burnout()[0]) # for i in range(retries): # mh_algorithm = RandomWalkMH(rounds, model, estimations, posterior) # posterior, data_history, observables = mh_algorithm.calculate_posterior() # histories.append(data_history) forecast_alg = ForecastAlgorithm(model) observables = forecast_alg.calculate([posteriors.get_post_burnout()[0]], 50, 10, estimations.estimation_time, estimations) print("calculated observables") # print(observables) posterior, _ = posteriors.last() print("calculated posterior") print(posterior) # for i in range(len(histories)): # name = "calculated posterior" # for j in range(posterior.shape[0]): # data_x, data_y = histories[i].prepare_plot(j) # print("data") # print(data_x) # print(data_y) # data_plotter.add_plot(StackedPlot(name, [data_x], [data_y], 'iter', 'post')) # name = '' data_plotter.add_plots(observables.prepare_plots()) data_plotter.draw_plots()
def forecast_blanchard_dsge(file_name, with_static=True): data_plotter = DataPlotter() raw_model, estimations = parse_model_file(file_name) model = model_builder.build(raw_model) blanchard_forecast_alg = BlanchardKahnForecast() observables = blanchard_forecast_alg.calculate(model, 80, with_static) data_plotter.add_plots(observables.prepare_plots()) data_plotter.draw_plots()
def blanchard_raw_test(file_name): # A = Matrix([[1.1 , 1], [0.3, 1]]) # B = Matrix([[0.95, 0.75], [1.8, 0.7]]) # C = Matrix([[0.3, 0.1], [-0.5, -1.2]]) raw_model, estimations = parse_model_file(file_name) model = model_builder.build(raw_model) A, B, C = model.blanchard_raw_representation([]) print("Matrix triple:") pprint(A) pprint(B) pprint(C) BlanchardRaw().non_singular_calculate(A, B, C, np.zeros(model.state_var_count), model.shock_prior.get_mean(), model.state_var_count, len(model.variables) - model.state_var_count, 20)