Skip to content

Instantly share code, notes, and snippets.

View brianr747's full-sized avatar
💭
Working on a new book, with small additions to existing libraries.

brianr747

💭
Working on a new book, with small additions to existing libraries.
View GitHub Profile
@brianr747
brianr747 / c20190502_greek_GDP.R
Last active May 5, 2019 12:45
Example R code using the Python myplatform. basefn2.r (ugly!) loads the wrap functions.
source('basefn2.R', encoding='UTF-8')
# Path to original = https://github.com/brianr747/platform/blob/master/legacy/R/c20190502_greek_GDP.R
ser <- pfetch("D@Eurostat/namq_10_gdp/Q.CP_MEUR.SCA.B1GQ.EL")
p2 <- PlotLowLevel1(ser/1000,"Bn. EUR","Greek Nominal GDP")
p2 <- SetXAxis(p2,"1997-01-01", 2)
PlotFromLowLevel(p2,"c20190502_greek_GDP.png","Eurostat via DB.nomics")
@brianr747
brianr747 / Log_file.txt
Last active May 11, 2019 02:43
Example of loading and plotting series using econ_platform
2019-05-10 22:42:34 INFO Starting
2019-05-10 22:42:34 DEBUG Fetching D@Eurostat/namq_10_gdp/Q.CP_MEUR.SCA.B1GQ.EL
2019-05-10 22:42:34 DEBUG Starting new HTTPS connection (1): api.db.nomics.world:443
2019-05-10 22:42:34 DEBUG https://api.db.nomics.world:443 "GET /v22/series?observations=1&series_ids=Eurostat/namq_10_gdp/Q.CP_MEUR.SCA.B1GQ.EL&offset=0 HTTP/1.1" 200 None
2019-05-10 22:42:34 INFO Writing D@Eurostat/namq_10_gdp/Q.CP_MEUR.SCA.B1GQ.EL
2019-05-10 22:42:34 INFO Load loop
2019-05-10 22:42:34 DEBUG Fetching D@Eurostat/namq_10_gdp/Q.CP_MEUR.SCA.B1GQ.EL from Text File Database
2019-05-10 22:42:34 DEBUG Fetching D@Eurostat/namq_10_gdp/Q.CP_MEUR.SCA.B1GQ.EL from Text File Database
2019-05-10 22:42:34 DEBUG Fetching D@Eurostat/namq_10_gdp/Q.CP_MEUR.SCA.B1GQ.EL from Text File Database
2019-05-10 22:42:34 DEBUG Fetching D@Eurostat/namq_10_gdp/Q.CP_MEUR.SCA.B1GQ.EL from Text File Database
@brianr747
brianr747 / recession_random_walk.py
Last active April 6, 2019 02:29
A random walk recession simulator.
"""
recession_random_walk.py
This file has nothing to do with pricing applications, it's just code that generates charts
for a random walk simulation of recessions. The explanation of what I am doing will appear in an
article on my website, and in my upcoming book on recessions.
"""
import random
from statistics import mean
import math
@brianr747
brianr747 / ex20171127_equations_state_space_models.py
Created November 28, 2017 16:04
State Space Models Demonstrating Robustness Analysis
"""
ex20171127_equations_state_space_models.py
And now for something completely different...
This code just uses the equation parser and solver to generate the solutions for state space models.
One of the stranger applications of framework code...
"""
from sfc_models.equation_solver import EquationSolver
from sfc_models.examples.Quick2DPlot import Quick2DPlot
@brianr747
brianr747 / ex20170209_SIMEX1.py
Last active February 10, 2017 15:23
The first variant of the SIMEX model (Godley & Lavoie, Chapter 3).
import os
from sfc_models.gl_book.chapter3 import SIMEX1, SIM
from sfc_models.examples.Quick2DPlot import Quick2DPlot
builder_SIMEX = SIMEX1(country_code='C1', use_book_exogenous=True)
model = builder_SIMEX.build_model()
model.main(base_file_name=os.path.join('output','ex20170209_SIMEX1'))
"""
ex20161128_tax_cut_comparison.py
Extend the SIM model (Godley and Lavoie, Chapter 3) with a capitalist sub-sector,
and then look at the effect of a tax cut.
Copyright 2016 Brian Romanchuk
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@brianr747
brianr747 / ex20161103_SIM_2_country.py
Created November 3, 2016 13:54
Build a two country model to compare model SIM with and without profits.
"""
ex20161103_SIM_2_country.py
Build a modified SIM model (G&L Chapter 3) for two countries, one with non-zero profits,
using sfc_model classes.
Copyright 2016 Brian Romanchuk
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@brianr747
brianr747 / build_SIM_script.py
Created October 26, 2016 13:56
Build Model SIM
# Works on Version 0.2.1 of sfc_models...
from sfc_models.models import *
from sfc_models.sectors import *
# Create model, which holds all entities
mod = Model()
# Create first country - Canada. (This model only has one country.)
can = Country(mod, 'Canada', 'CA')
# Create sectors
gov = DoNothingGovernment(can, 'Government', 'GOV')
@brianr747
brianr747 / run_SIM_machine_generated.py
Created October 17, 2016 14:19
Example to generate the SIM model from Godly and Lavoie with machine-interpreted equations
"""
run_SIM_machine_generated.py
Script to generate model SIM from [G&L 2012] from text equation specification.
"""
from plot_for_examples import Quick2DPlot
import sfc_models.iterative_machine_generator as generator
filename = 'SIM_model.py'