Recent Posts

Thursday, October 20, 2016

SFC Model Update

I have been doing some writing (dealing with the silliness that is Helicopter Money), and working on my Stock-Flow Consistent (SFC) modelling tools for Python. The progress on that package has been quite good.

UPDATE (2016-10-21): A first version is built, and I have an installer. See notes below.



I have managed to build a solver for the simplest SFC model ("model SIM") again. The useful thing is that the model is now put together by high-level functions, and there is essentially no manual intervention into the equations. Unfortunately, I messed up my household sector accounting definitions, and had to patch them.

In addition to needing to fix my accounting, I will need to make some functions more general (sector definitions were made as simple as possible). I will give a full update when the package is ready for prime time.

However, one interesting thing I found is that I needed to unlearn some ideas that I picked up from economics.

I wanted to write:

  1. SUPPLY = f(x),
  2. DEMAND = g(x),
  3. SUPPLY = DEMAND.
That does not work in an algorithm, as we are attempting to define the variable SUPPLY twice. (It works mathematically.) The temptation is to solve for SUPPLY and DEMAND separately, and then somehow find a way to put the two values into "equilibrium" (equation #3). Instead, I had to think like a post-Keynesian, and break the idea of "equilibrium."

I have a methodology that works, but it remains to be seen whether it survives more complicated economic systems. If it does work, I will eventually write up an explanation.

[Update 2016-10-21] The module is now capable of generating the equations for the simplest classes of models. I have cleaned up the accounting issues, and the code is clean. I have built an install package, and the code works on Python 2.7 (and possibly earlier versions), as well as version 3.

The installation procedure consists of:

  1. Install Python. 
  2. On the command line ("cmd" in Windows), run: pip install sfc_models
(It is likely that you might need to supply the full path to the pip executable, which is found in the "Scripts" directory below your installation of Python.) If you are having difficulties, there are tons of web pages explaining how to install packages via "pip".

If the installation worked, if you run Python, the commands will work:

import sfc_models
help(sfc_models)

(The "help" command only works after you import the module.)

I will be posting examples of how to use it later.

(c) Brian Romanchuk 2016

8 comments:

  1. I’m not an economist. My background is in business and government. However, I’ve been reading about economics for many years. Here’s how I would model supply and demand as perceived by businesses and other participants in the real economy. I’d be interested in understanding whether you think it would be practical to implement this type of model at a macro level.

    The principles are:

    a) Recognise that participants in the economy think in terms of forecasts, plans and actuals

    b) Recognise the importance of inventory in business decision making.

    The planning cycle starts with forecast demand. At a basic level, this is a function of historical demand and seasonality factors. At a micro level, marketing and other factors are important as well e.g. a marketing campaign has the objective of increasing demand over historical periods. However, that’s probably too complex for macro level modelling.

    Forecast Demand (t) = f (Historical Demand, Seasonality)

    The next stage in the planning cycle is planned supply. At a basic level, planned supply needs to meet forecast demand, but it also needs to consider optimal levels of inventory. Businesses don’t like inventory as it represents sunk costs and potential wastage. Sophisticated businesses run with inventory of zero. However, a more general case would be to define an optimal level of inventory. Now suppose that the demand forcecast is for 50 units of product (either physical units or financial valuation). Suppose also that the optimal level of inventory is 10 units but that actual inventory at the end of the previous period is 25. The business needs to meet the demand of 50 but, at the same time, get its inventory back down from 25 to 10. It will develop a supply plan to create a further 35 units.

    Planned Supply (t) = Forecast Demand (t) + Optimal Inventory – Actual Inventory (t – 1)

    The next stage in the planning cycle is actual supply. Actual supply can vary from planned supply for any number of reasons but they are probably too complex to include in a macro model, so we might assume a random fluctuation from planned supply.

    Actual Supply (t) = f (Planned Supply, Random Fluctuation)

    The next stage is actual demand. Unless the business is clairvoyant, actual demand will also vary from forecast demand by a random fluctuation.

    Actual Demand (t) = f (Forecast Demand, Random Fluctuation)

    Finally, we can calculate actual inventory to feed into the planning for the next period.

    Actual Inventory (t) = Actual Inventory (t - 1) + Actual Supply (t) – Actual Demand (t).

    It feels to me that it would be possible to program this type of model. It would have the advantage of making sense to businesses and other participants in the economy. This would be a huge step forward from the simple-minded “supply = demand” narrative as it allows for real world conditions where forecasts and actuals are not the same. Also, the inventory element feeds back into subsequent periods as demand forecasting errors manifest themselves as deviations from optimal inventory which then impact on supply plans for subsequent periods.

    What do you think?

    ReplyDelete
    Replies
    1. You are pinning down another side of the supply and demand issue for modelling. We need to distinguish between the actual outcome and what people plan (or hope for). What I was discussing was a rather narrow technical point about equation specification.

      This is a standard distinction in post-Keynesian economics. It is handled in a number of ways in the theory.

      My current framework is being built up, and I need to add in that distinction. At present, I only have what you call "actual supply" (demand), which I denote SUP (DEM), and I need to create the "planned" versions. (My first models are based on recreating model SIM from a text by Godley and Lavoie, which I describe elsewhere here. In that model, supply is open-ended, so supply always equals demand.)

      I will need to name the variables, which is tricky, as my variable names are already long. For example, the full name for the household labour supply for the Canadian household sector (in a multi country model) is CA_HH_SUP_LAB, which is quite long (but readable). Sticking "PLANSUP" in there makes it even longer.

      Delete
  2. Here are two short videos demonstrating conventional analysis for simply supply and demand models.

    Deriving Demand and Supply Equations from Data:
    https://www.youtube.com/watch?v=ViHxHtavrO4

    Solving for Equilibrium Price and Quantity:
    https://www.youtube.com/watch?v=vPRqJwjG8-Y

    ReplyDelete
    Replies
    1. From what I saw of the video, it does not really help for the systematic creation of the equations. Remember that I am attempting to develop an algorithm that can write down equations that can be solved numerically; we cannot use human intuition as part of this.

      Delete
  3. I can wait to see your further comments. However, to give feedback into my confusion, it seems to me that generated curves for supply and demand either intersect at one or more prices or do not intersect. The solution for where the curves intersect is considered an equilibrium. This does not require a third equation supply = demand it requires a procedure to find one or more prices where supply = demand.

    ReplyDelete
    Replies
    1. If you look back at model SIM (I wrote about here earlier), there are no prices in the model. Therefore, that technique is dead in the water for such a model.

      Even if we have access to the price equation, I do not see an obvious way of finding a solution in a general way that can be coded as a fixed algorithm. Note that we have to solve for at least two markets simultaneously (labour market and the goods market). Admittedly, I have not thought about how to deal with prices yet, but I do not believe that they make it any easier. If I attempted to take the classical approach, I think I would have to do a brute force search over the space of possible price vectors. I think that's do-able, but would not be able to deal with a large number of markets.

      Delete
    2. I think the Minsky idea is that prices of assets and consumption goods are set by the finance deals among bankers, firms, and consumers. In aggregate supply and demand are set by investment decisions with price markups over old prices and finance of the markup, or if new finance does not support the old markup assumptions, prices begin to fall and defaults on old cash flow obligations ripple through the system. The result is a drastic reduction of supply and demand due to changes in the financial decision process.

      Delete
  4. Some Simple, Consistent Models of the Monetary Circuit (16 pages):

    http://www.levyinstitute.org/pubs/wp405.pdf

    The paper under the above link uses The Monetary Circuit (TMC) model as a starting point for models in which the supply of consumption goods, supply of investment goods, and wage bills are determined by decisions to finance production and decisions to allocate savings.

    Minsky goes beyond these models in Stabilizing an Unstable Economy. He describes a system with investment asset prices and take out finance. A system with take out finance (loans to consumers) can support a bubble in asset prices and overshoot and collapse patterns in economic populations of goods, services, and financial instruments.

    ReplyDelete

Note: Posts may be moderated, and there may be a considerable delay before they appear.

Although I welcome people who disagree with me, please be civil.

Please note that my spam comment filter appears to dislike long "anonymous" posts. I get no warning about this, and only go through my "spambox" infrequently. The best bet it to keep comments short, and if you think the spam filter struck, let me know with a short comment.