Video Of Day

Breaking News

Implementing Unusual Central Inward Sfc_Models

The sfc_models package is a Python framework that automatically generates the equations for stock-flow consistent (SFC) models. This article discusses how unusual central transactions are represented inside the framework. It is an unedited draft department from my upcoming volume on sfc_models; some technical details may last harder to follow for readers unfamiliar alongside the framework. At the goal of the article, I hash out the divergence inwards modelling strategy betwixt sfc_models in addition to that used past times Godley in addition to Lavoie inwards their text Monetary Economics.


The implementation of unusual currency transactions within sfc_models is embedded inwards the ExternalSector class. This shape is a subclass of Country, in addition to it creates special objects that are subclasses of Sector to have the diverse aspects of international transactions. The user is non expected to add together objects to this abstract “country,” although that mightiness alter because of extensions to the code base.

(The advert ExternalSector is somewhat unfortunate every bit it is technically non a Sector subclass; however, the advert seemed to last the most natural from the standpoint of economic science jargon.)

In monastic enjoin to allow a model to back upwards international transactions; the user needs to exercise an ExternalSector object, passing it a Model into which it is embedded.

obj = ExternalSector(model_object)

(It is non fifty-fifty necessary to assign to the variable obj if it is non accessed; the ExternalSector object volition last embedded into model_object inside the constructor.)

Creating the ExternalSector will too exercise 3 Sector objects embedded inside it.

  1. An ExchangeRates object, alongside code XR. This shape holds the diverse central rates inside the model; the user tin telephone holler upwards GetCrossRate() to larn the variable advert for the central charge per unit of measurement betwixt 2 currencies. The embedded central charge per unit of measurement variables tin last adjusted to generate model scenarios.
  2. A ForexTransactions object, alongside code FX. This object does the volume of the piece of work for the external sector, setting upwards the equations associated alongside cross-currency upper-case missive of the alphabet flows. The user volition non unremarkably bargain alongside this object; instead, the framework volition telephone holler upwards it when cross-currency currency flows arise. (Either because of Market interactions or past times registering cash flows.) If user wants to extend the framework, an agreement of how this shape operates would larn a necessity.
  3. An InternationalGold object, alongside code GOLD. This object handles gilded transactions, which involve both flows stated inwards currency or volume (ounces) terms. The GoldStandardCentralBank in addition to GoldStandardGovernment objects automatically laid upwards their gilded transactions, but the user may wishing to add together other sectors that interact alongside the gilded market. This is done past times calling the SetGoldPurchases() method, which registers a variable inside a sector every bit representing  the current of gilded purchases inwards local currency terms. (Gold sales are represented past times negative purchases.)

The ExternalSector simplifies international transactions inwards multicurrency models past times having it acting every bit the intermediary for all cross-currency fiscal flows.

The left percentage of the figure inwards a higher house shows the master configuration of international fiscal flows inwards a three-country model. The diagram on the correct shows how this is implemented inside sfc_models: each master current outset enters the external sector, in addition to and so leaves the external sector to choke to the master recipient. As a result, each province solely has to aspect at its cyberspace current versus the external sector, in addition to non worry most aggregating across multiple bilateral relationships.

(This is non a simplification if nosotros indeed are solely examining a two-currency model. It would last possible to exercise a bilateral unusual central object that emulates the demeanor of ExternalSector, but solely allows for 2 currencies inside the model. The resulting equations should last simpler. However, my preference was to implement the full general multi-currency object earlier roofing special cases.)

Having all transactions intermediated past times this unmarried abstract province greatly simplifies the thorny work of keeping rail of currency values, peculiarly inwards a multi-currency model. If nosotros know that the central charge per unit of measurement betwixt the Australian dollar (AUD) in addition to the Canadian dollar (CAD) is 1:1, in addition to 1 CAD purchases 2 U.S. dollars (USD), nosotros know that 1 AUD too purchases 2 USD. (We say that at that topographic point is an arbitrage human relationship betwixt currency pairs.) Real basis currency quotes contain a bid-offer spread, in addition to so at that topographic point is a small-scale mistake bar simply about the ideal arbitrage-determined currency rates, but nobody tin purchase in addition to sell at a toll far removed from the theoretical fair value for really long without going out of business.

Even if nosotros are non convinced past times arbitrage arguments, nosotros call for to choke along our currency values consistent if nosotros desire consistent accounting. For example, if nosotros were non careful, nosotros mightiness laid the bilateral exchanges rates betwixt CAD in addition to USD as:

  • 1 CAD buys 1 USD; and
  • 2 USD buys 1 CAD.

The values of fiscal flows are determined past times multiplying the unusual currency value past times the cross-currency charge per unit of measurement (USD to CAD, or CAD to USD, depending on the direction of the flow). If nosotros utilisation incoherent prices similar the above, the accounting volition non add together up. Effectively, some sector volition accept exchanged currency at the “wrong” value, in addition to has suffered a upper-case missive of the alphabet hit or loss every bit a result. This hit or loss would effectively last pocketed past times an unknown intermediary. The model accounting would thence intermission downward if the intermediary does non explicitly look inside the model.

Rather than forcefulness the user to brand certain that central charge per unit of measurement changes are coherent, the framework uses a simplification: all currency values are expressed versus a unmarried unit of measurement of account. In the fiscal in addition to economical literature, this unmarried unit of measurement of concern human relationship is known every bit a numéraire. As a result, the currency of the ExternalSector object is ‘NUMERAIRE,’ which has a currency value of 1 for all fourth dimension past times definition. Other currencies are in addition to so specified past times a unmarried fourth dimension series, which is the publish of units of NUMERAIRE than tin last purchased for 1 unit of measurement of the currency. The fourth dimension serial of these currencies is a variable inside the central charge per unit of measurement object (‘XR’), alongside a variable advert equal to the currency code.

This convention agency that a larger currency value inwards the fourth dimension serial corresponds to a stronger currency. For example, if CAD goes from 1 to 2, it is stronger, since a unmarried Canadian dollar tin at nowadays purchase 2 ‘NUMERAIRE’ instead of 1.

Cross-rates accept a variable advert based on the 2 currencies, in addition to they are calculated every bit the corresponding ratio of the 2 currencies versus NUMERAIRE. Since at that topographic point is no merchandise alongside the ExternalSector object, all sector economical demeanor should last based upon the cross-rates alongside “real” currencies.

This currency-naming system could trip upwards unusual currency experts. Currency rates tin either last specified past times naming the dyad inwards total (“USD-GBP” for the U.S. dollar-to-British Pound central rate), or past times simply specifying a non-dollar currency for the charge per unit of measurement versus the U.S. dollar (which would last “GBP” for the previous example). That is, the U.S. dollar is treated every bit the numéraire, in addition to non a fictitious currency. Unfortunately, the convention used (whether the charge per unit of measurement specifies 1 USD versus x foreign, or x USD versus 1 foreign) appears random to the casual observer. (The conventions were determined past times historical developments.) It would last ridiculous to emulate this haphazard approach, in addition to so the sfc_models framework uses a consistent quote convention versus the NUMERAIRE.

Therefore, all that is needed to conform currency values is to laid the value of the currency versus the numeraire; cross-rate values volition automatically adjust.

For example, nosotros tin exercise the following:

model_object.SetExogenous('EXT_XR', 'CAD', '[1.]*5 + [1.2]*100')

This sets the variable CAD inwards the XR sector of EXT to last 1.0 for the outset 5 periods (k=0,..,4) in addition to 1.2 thereafter. This volition crusade CAD to appreciate versus all other currencies inwards the model (assuming the other currencies are themselves unchanged.)

As for international cash flows, these are unremarkably handled inside the framework; the user solely needs to exercise an ExternalSector object. (If the object was non created, cross-currency cash flows volition trigger a LogicError exception. We exercise non desire to exercise the object if the user did non genuinely recall to accept a cross-currency flow.)

There are 2 normal sources of cross-currency flows.

  1. International sectors (exporters) may provide markets; the Market object volition have the cross-currency implications automatically. (There is currently no back upwards for demand sectors to cross currency zones.)
  2. The RegisterCashFlow() method of the Model object may last called, alongside the source in addition to target sectors inwards dissimilar currency zones. The Model code detects that this is a cross-currency flow, in addition to handles it accordingly. (Once again, it volition throw a LogicError if the ExternalSector object was non created past times the fourth dimension cash flows are existence processed.)

The next code uses RegisterCashFlow to exercise a cross-currency flow, it is in all probability the simplest possible way of generating such a flow.

from __future__ import print_function
from sfc_models.objects import *
from sfc_models.sector import Sector

mod = Model()
ExternalSector(mod)
ca = Country(mod, 'CA', currency='CAD')
us = Country(mod, 'US', currency='USD')

hh_ca = Sector(ca, 'HH', has_F=True)
hh_ca.AddVariable('GIFT', 'Sending money..', '5.')
hh_us = Sector(us, 'HH', has_F=True)
mod.RegisterCashFlow(hh_ca, hh_us, 'GIFT')
mod.main()
mod.TimeSeriesCutoff=1
series_list = ('CA_HH__F', 'US_HH__F', 'EXT_FX__NET_CAD', 'EXT_FX__NET_USD')
for s inwards series_list:
    print(s, mod.GetTimeSeries(s)[1])

What this code does is exercise 2 sectors, 1 inwards Canada, in addition to the other inwards the United States. The variable GIFT is created, in addition to laid to last a constant 5.0. Then, a cash current is registered, using the variable advert GIFT every bit the value of the flow. (The value is inwards the source currency.)

The output is every bit follows:

CA_HH__F -5.0
US_HH__F 5.0
EXT_FX__NET_CAD 5.0
EXT_FX__NET_USD -5.0

When run, nosotros come across that the fiscal assets (F) inwards the Canadian sector are falling past times 5.0 per period, spell it is rising past times 5.0 inwards the United States. (The central rates are laid to 1 past times default.)

However, something is wrong. The Canadian sector sends out 5 CAD, spell the sector inwards the US receives 5 USD. How was this possible?

Examination of the NET_CAD in addition to NET_USD variables quest the problem: they are non-zero. These variables quest the cyberspace flows inwards each currency. If they are anything other than zero, at that topographic point is an imbalance inwards unusual central transactions past times the objects inwards the model.

One interpretation is that a non-modelled entity has acted every bit a fiscal intermediary for the modelled sectors, in addition to so it ends upwards alongside cyberspace currency positions.

We tin exercise GoldStandardGovernment objects inwards both countries to ready this imbalance. These sectors automatically residual the unusual central market, implicitly next the Gold Standard rules described inwards this article.

The novel code is:

mod = Model()
ExternalSector(mod)
ca = Country(mod, 'CA', currency='CAD')
us = Country(mod, 'US', currency='USD')
gov_ca = GoldStandardGovernment(ca, 'GOV')
gov_us = GoldStandardGovernment(us, 'GOV')
# The call for for the side past times side measuring may last fixed...
gov_ca.AddVariable('T', 'Taxes', '0.')
gov_us.AddVariable('T', 'Taxes', '0.')


hh_ca = Sector(ca, 'HH', has_F=True)
hh_ca.AddVariable('GIFT', 'Sending money..', '5.')
hh_us = Sector(us, 'HH', has_F=True)
mod.RegisterCashFlow(hh_ca, hh_us, 'GIFT')
mod.main()
mod.TimeSeriesCutoff=1
series_list = ('CA_HH__F', 'US_HH__F', 'EXT_FX__NET_CAD', 'EXT_FX__NET_USD')
print('Net residual fixed')
for s inwards series_list:
    print(s, mod.GetTimeSeries(s)[1])

series_list = ('CA_GOV__GOLDPURCHASES', 'US_GOV__GOLDPURCHASES', )
print('Net residual fixed')
for s inwards series_list:
    print(s, mod.GetTimeSeries(s)[1])

The output is:

Net residual fixed
CA_HH__F -5.0
US_HH__F 5.0
EXT_FX__NET_CAD 8.93918681035e-05
EXT_FX__NET_USD -4.46959340517e-05
Net residual fixed
CA_GOV__GOLDPURCHASES -4.99995530407
US_GOV__GOLDPURCHASES 4.99991060813

We come across that the cyberspace positions inwards CAD in addition to USD are effectively null (there is a small-scale residual mistake inwards the model solution). This is achieved past times the Canadian primal banking enterprise selling 5 units of gilded (PURCHASES are -5, that is, sales of gold) to the US (PURCHASES are +5).

With this background cloth inwards place, it is at nowadays easier to explicate the divergence inwards the handling of gilded sales betwixt Godley in addition to Lavoie’s Monetary Economics in addition to sfc_models.

If nosotros accept a non-intermediated current betwixt 2 sectors that prevarication inwards dissimilar currency zones, at that topographic point are 2 imbalances inwards aggregate residual sheets created.
  1. The cyberspace current fiscal assets across the currency zone is no longer zero, every bit 1 currency zone is losing fiscal assets, in addition to the other gaining.
  2. The cyberspace flows inwards currencies are unbalanced.
The strategy inwards Monetary Economics is to fighting that cyberspace flows inwards currencies are ever null past times definition, in addition to so non model them. Instead, the primal banking enterprise buys or sells gilded inwards monastic enjoin to choke along the stock of fiscal assets balanced. (Since the primal banking enterprise is the supplier of money, this is explained inwards terms of stocks of coin in addition to bills.) The fact that gilded sales in addition to purchases are balanced is an implicit final result of accounting identities.

The strategy inwards sfc_models is for the gilded measure governments to utilisation gilded sales to residual currency flows, in addition to ignoring the domestic fiscal assets, every bit the unusual central transactions volition implicitly crusade the cyberspace flows of fiscal assets to cyberspace to zero.

The strategy of explicitly modelling the unusual central flows reflects the nature of the sfc_models package. As discussed inwards Chapter 7, sfc_models is meant to last used past times researchers who volition extend its capabilities. This requires flexibility, including the powerfulness to modify whatever equation directly. As a result, it is to last expected that residual sheets identities volition last violated, peculiarly during the evolution cycle. If the researcher causes fiscal assets to disappear from a domestic sector, that volition present upwards inwards an imbalance inwards cyberspace fiscal assets. Effectively, at that topographic point is a fictitious mistake current implicitly created inside the model. However, if the primal banking enterprise automatically intervenes to residual domestic flows, at that topographic point volition last an imbalance created inwards the unusual central markets (since at that topographic point was no international counterpart to the fictitious mistake flow). The researcher could in addition to so lose considerable fourth dimension debugging the external components of the model they are building, non realising that it was a põrnikas inwards the domestic sector structure that caused the problem.

(c) Brian Romanchuk 2017

No comments