Blog Topics...

3D plotting (1) Academic Life (2) ACE (18) Adaptive Behavior (2) Agglomeration (1) Aggregation Problems (1) Asset Pricing (1) Asymmetric Information (2) Behavioral Economics (1) Breakfast (4) Business Cycles (8) Business Theory (4) China (1) Cities (2) Clustering (1) Collective Intelligence (1) Community Structure (1) Complex Systems (42) Computational Complexity (1) Consumption (1) Contracting (1) Credit constraints (1) Credit Cycles (6) Daydreaming (2) Decision Making (1) Deflation (1) Diffusion (2) Disequilibrium Dynamics (6) DSGE (3) Dynamic Programming (6) Dynamical Systems (9) Econometrics (2) Economic Growth (5) Economic Policy (5) Economic Theory (1) Education (4) Emacs (1) Ergodic Theory (6) Euro Zone (1) Evolutionary Biology (1) EVT (1) Externalities (1) Finance (29) Fitness (6) Game Theory (3) General Equilibrium (8) Geopolitics (1) GitHub (1) Graph of the Day (11) Greatest Hits (1) Healthcare Economics (1) Heterogenous Agent Models (2) Heteroskedasticity (1) HFT (1) Housing Market (2) Income Inequality (2) Inflation (2) Institutions (2) Interesting reading material (2) IPython (1) IS-LM (1) Jerusalem (7) Keynes (1) Kronecker Graphs (3) Krussel-Smith (1) Labor Economics (1) Leverage (2) Liquidity (11) Logistics (6) Lucas Critique (2) Machine Learning (2) Macroeconomics (45) Macroprudential Regulation (1) Mathematics (23) matplotlib (10) Mayavi (1) Micro-foundations (10) Microeconomic of Banking (1) Modeling (8) Monetary Policy (4) Mountaineering (9) MSD (1) My Daily Show (3) NASA (1) Networks (46) Non-parametric Estimation (5) NumPy (2) Old Jaffa (9) Online Gaming (1) Optimal Growth (1) Oxford (4) Pakistan (1) Pandas (8) Penn World Tables (1) Physics (2) Pigouvian taxes (1) Politics (6) Power Laws (10) Prediction Markets (1) Prices (3) Prisoner's Dilemma (2) Producer Theory (2) Python (29) Quant (4) Quote of the Day (21) Ramsey model (1) Rational Expectations (1) RBC Models (2) Research Agenda (36) Santa Fe (6) SciPy (1) Shakshuka (1) Shiller (1) Social Dynamics (1) St. Andrews (1) Statistics (1) Stocks (2) Sugarscape (2) Summer Plans (2) Systemic Risk (13) Teaching (16) Theory of the Firm (4) Trade (4) Travel (3) Unemployment (9) Value iteration (2) Visualizations (1) wbdata (2) Web 2.0 (1) Yale (1)
Showing posts with label Dynamical Systems. Show all posts
Showing posts with label Dynamical Systems. Show all posts

Thursday, June 7, 2012

5-6 June 2012 at the 2012 CSSS...

For the past two days the focus has been on tools for analyzing non-linear dynamical (and specifically chaotic) systems.   We have been using a program called TISEAN to do most of the analysis.  There also seem to be a number of R packages for doing non-linear times series analysis: RTisean, tsDyn, tseriesChaos, etc.

Henon Map:  

Our first task was to simply use TISEAN to generate some trajectories of the Henon map, plot them using our favorite plotting tool (at the moment I am working on improving my Python coding so I am using matplotlib) and then analyze the power spectrum (sometimes called spectral density).  TISEAN's version of the Henon map is:

xt+1 = 1 - Axt2 + Byt
yt+1 = xt

For A=0.8 and B=0, the attractor is a simple 2-cycle which means that a plot of the trajectory of the map in state space will yield two points:
 However, for A=1.4 and B=0.3, the Henon map displays chaotic dynamics:
Power Spectrum: A good place to start the analysis of times series data is to examine the power spectrum (or spectral density) of the data.   For the Henon map with A=0.8 and B=0, the attractor is a 2-cycle which implies that the dominant frequency should be 1/2.  
Note the above plot has a single "spike" at a frequency of 0.5.  What other frequencies are present in the times series generated by the Henon map?  Given that the map is a 2-cycle, in theory, there should be only a single frequency present in the data.  Although my computer can represent much smaller numbers, the smallest number that my computer can distinguish as being distinct (i.e., my machine ε) is 2.2204460492503131e-16.  The other "spikes" in the above plot are thus non-sensical results of my computer doing calculations with numbers that are too small for it to handle properly.  This is a good example of arithmetic underflow.

Given that the Henon map with A=1.4 and B=0.3 exhibits chaotic dynamics we expect that the power spectrum should exhibit spikes at all frequencies.

The Lorenz System: 

Next we want to plot some trajectories the Lorenz System and then analyze the resulting power spectrums.  Classic model of chaos developed by Edward Lorenz to model weather/climate systems.  For parameter values R=15, S=16, B=4 the system exhibits a unique fixed point attractor...
...or in 3D if you prefer:
The power spectrum for the unique fixed point attractor looks as follows:
One gets much more interesting dynamics out of the Lorenz system simply by changing R.  For parameter values R=45, S=16, B=4 the system exhibits chaos:
For R=45, the power spectrum exhibits power at all frequencies:

Python code (and the data files if you do not have TISEAN installed) for replicating the above can be found here.

Monday, June 4, 2012

Monday 4 June 2012 at the 2012 CSSS...

Today's lecture, given by Prof. Liz Bradley, focused on the basics of non-linear (mostly chaotic) dynamics in both discrete and continuous time.  Much (all?) of the material in the lecture I had already encountered before in my own reading, but it was nice to get a refresher.  What follows is my summary of our discussion of the dynamical properties of that classic example of chaotic dynamics in discrete time, the logistic map.  The seminal reference for the logistic map is probably the 1976 Nature paper by Robert May.

The Logistic Map is an innocent looking non-linear equation:

Xt+1 = r Xt (1 - Xt)

where the state space of the model is the unit interval [0, 1] and r is a parameter that varies on (0, 4].  

Some trajectories of the logistic map for various values of r:
If  0 < r ≤ 1, then the dynamics are trivial: the model will converge to X = 0 no matter the initial condition.  Suppose the r = 2.  In this case, the dynamics of the model are also pretty boring: convergence to a unique fixed point.  No matter the initial condition, if r = 2, all trajectories of the logistic map will converge (quite quickly) on a unique steady state value of 1/2.

Now suppose that r = 2.919149.  In this case, the result is still convergence to a unique fixed point, however the dynamics are more interesting: the trajectories now exhibit dampened oscillations.
For values of r satisfying 3 < r < 3.45 (roughly!), you get a 2-cycle:
For r = 3.8285, one gets the famous 3-cycle which is one of the generally accepted indicators of chaotic dynamics (note I have changed the initial condition from 0.2 to 0.5 to eliminate the transient and thus making the cobweb diagram a bit cleaner):
Finally, for r = 4 we get an example of chaotic dynamics.  Note that the deterministic trajectory for the logistic map looks incredibly "random."
3D plot of the phase space for the logistic map:
One of the reasons why models with chaotic dynamics, such as the logistic map, exhibit sensitive dependence to initial conditions, is that such maps repeatedly "stretch and fold" the state space over which they are defined.  While 2D phase plots give a sense of how the logistic map "stretches" the state space,  a 3D phase plot is a really cool way to see how the logistic map "folds" the state space.
If you are interested, the Python code to replicate the above graphics can be found here.  I am still working on the code for the bifurcation diagram, estimating Feigenbaum's constant, and for calculating Lyapunov exponents.  

Monday, January 31, 2011

An oldie but goodie ftom Axel Leijonhufvud...

Here is a snippet from an old blog post by one of my favourite economists, Axel Leijonhufvud:
"Systemic problems
The currently pressing problems all concern instabilities that have been neglected in stable-with-frictions macro theory. They constitute three themes I discussed in more detail in previous Vox columns (Leijonhufvud, June 2007, January 2009, and July 2009).
  • Instability of leverage. Competing to achieve rates of return several times higher than returns in industry, financial institutions were at historically high levels of leverage towards the end of the boom, earning historically minimal risk spreads – and carrying large volumes of assets soon to be revealed as “toxic.”
  • Connectivity. In the US, under the Glass-Steagall regulations, the financial system had been segmented into distinct industries each characterized by the type of assets they could invest in and liabilities they could issue. Firms in different industry segments were not in direct competition with each other. Deregulation has dramatically increased connectivity in the global network of financial institutions. The crisis of the American savings and loan industry in the 1980s, although costly enough, was confined to that market segment. The present crisis also started in American home finance but has spread and amplified across the world."
The whole post (plus all the linked materials) is well worth reading.  The above snippet gets at the heart of what I am trying to show with my first year PhD paper.  Increasing connectivity in the financial sector (which I am modelling as increasing network density), increases the leverage of financial institutions (either because increasing connectivity lowers borrowing costs, financial institutions are risk averse, etc).  Increased leverage makes the financial system fragile and vulnerable to idiosyncratic shocks despite the increased diversification brought about by the additional connectivity.

Saturday, January 29, 2011

Calculating the Walrasian Auctioneer...

Attention conservation notice: Longish post on the details of a stochastic speculative pricing model from Economic Dynamics.  It is my hope that working through this model will help me find a way forward in implementing a computational solution to the Kiyotaki-Moore (1997) model which will inform my extension of that model.
Suppose that we live in world where there is a single commodity called wheat, whose price at date t is pt.  Due to global warming, weather patterns in this world are quite volatile and as a result the harvest of wheat each period (i.e., production of wheat), Wt, is IID random and drawn from a common density function φ.  

Harvests take values in S≡[a,∞), where a>0.  The demand for wheat is made up by two groups: gatherers, and farmers.  Gatherers' quantity demanded is QG=D(p), where p is the price of fruit.  It is assumed that the inverse demand function, D-1(QG)=p(QG), exists, is strictly decreasing and continuous, and satisfies p(QG)→∞, as QG→0.

Farmers are risk neutral and have a special technology, called a barn, where they can store wheat between periods.  If farmers purchase It units of wheat on date t, then they will be left with αIt, where α ∈ (0,1), next period.  Risk-free interest rate is taken to be zero, so we can write the farmers' expected profits on It units of wheat as:
Et(pt+1)αIt - ptIt = (αEt(pt+1) - pt)It
No-arbitrage requires that :
αEt(pt+1) - pt ≤ 0     (1)

There is also a logical constraint that tells us that if our farmers are maximizing expected profits, then if
αEt(pt+1) - pt < 0 implies that It = 0   (2)
 Finally, market clearing condition requires that supply of wheat equal demand for wheat.  Supply of wheat, Xt, is sum of carryover from farmers, αIt-1, and the current harvest Wt, while demand is D(pt) + It. Thus we get:
αIt-1 + Wt = Xt= D(pt) + It     (3) 
Take the initial condition for supply of wheat, X0 ∈ S as given.

The question now becomes, how does one construct a system (It, pt, Xt)t ≥ 0 for investment, prices, and supply of wheat that satisfies (1-3)?  The idea is to find a price function p:S→(0,∞) that depends only on the current state Xt (i.e., pt=p(Xt) for every t).  The vector  (It, pt, Xt)t ≥ 0 for investment, prices, and supply of wheat would then evolve according to:
pt=p(Xt), It = Xt - D(pt), and Xt+1 = αIt + Wt+1      (4)
For a given initial condition for supply of wheat, X0 ∈ S and a exogenous shock process (Wt)t ≥ 1, the system (4) determines the time path of our vector (It, pt, Xt)t ≥ 0 as a sequence of random variables.   The idea then is to find a pricing function p such that (1) and (2) hold for the system (4).  

I skip over the theory related to solving this system (the solution makes heavy use of Banach's fixed point theorem, consult Economic Dynamics for the details), and jump straight to the numerical solution.

Here is a plot of the pricing function when gatherers' inverse demand function is assumed to follow D-1(QG)=p(QG)=1/QG and the random harvests Wt = a + cBt where the Bt are drawn from a beta distribution Beta(5,5).
This figure reproduces Figure 6.13 from Economic Dynamics.  Once the pricing function has been calculated, it can be used to define a stochastic dynamical system as follows:
  Xt+1 = αI(Xt)+ Wt+1
where I(x) = x - D(P*(x)).

I have simulated several trajectories, and marginal densities from this stochastic process.
In addition to marginal densities, I also plotted the density of the random harvest.  The fact that the marginal densities of the supply of wheat converge to the density of the harvest process indicates that the farmers (who are wheat speculators) do not have any impact on the long-run supply of wheat.
For fun, I also reproduced the above analysis assuming that the harvest follows a Pareto distribution with α=2 (location and scale parameters are the same as those of the Beta distribution above).  I find the plots amusing...
Note that, in this case, the marginal densities seem to converge...but not to the density of the harvest process.  What does this mean?  Well for this parametrization the Pareto distribution has a well defined mean, which implies that there is an "average" harvest (about 10 units in this case), but the variance is infinite!  Thus while tomorrows harvest is likely to be close to 10, there is also a non-negligible probability that it could be 10,000.  The mean is very much influenced by these large harvests.  The median of the distribution, however, is about 7.5.  It is almost as if the speculators, because they wake up to below average harvests on most mornings, believe that the best thing to do is try to store wheat and sell it next period.

Any other interpretations?  The code is posted to my repository (you will want cpdynam.py and pSolve.py amongst other dependencies).

For those of you following my research...I am playing around with the idea of using the above methods to try to solve for the price of land in the Credit Cycles model.  The first thing I will need to endogenize the production side of the above economy.  Any strong beliefs about whether this would be a useful way to proceed?

Friday, January 28, 2011

More on the Solow Model...

In working through the material on the version of the Solow model from Chapter 6 of Economic Dynamics (if you want details of the model see previous posts) I began to wonder how an agent living in this world would go about choosing an optimal policy.  Here is the answer using U(c) = 1 - exp(-θc):

Iterations of the Value Function:

Note the jump up in the optimal savings policy.  

The Optimal Policy:
The plot of output above assumes that the shock takes its average value.  You can clearly see the two steady-state levels of output (they occur where the blue line cuts the 45 degree line from above). 

I am not quite sure what to make of this...I wasn't expecting the output and the optimal policy lines to cross...maybe a bug in my code.  Thoughts and interpretations are welcome!  The code has been posted to my Google Code repository.  Try it with a different (bounded and continuous) utility function and let me know your results...

Tuesday, January 18, 2011

An ergodic model of economic growth?...

So, I am now thoroughly confused!  I now think that perhaps the version of the Solow model outlined in my previous post is actually an Ergodic model!  I think this despite the fact that the deterministic version of the same model is (I think) non-Ergodic because it has multiple steady-states and long-run outcomes are completely dependent on initial conditions of capital stock.

Below are estimates of the unique pdf and cdf of steady-state distribution of the Solow model from my previous post (with identical parameter values).  John Stachurksi, in his book Economic Dynamics proves that the model is globally stable and thus that the steady-state distribution is unique.  Global stability, I think, implies that a process is Ergodic.  The distribution was created by simulating the model for 100,000 periods and then estimating the pdf using non-parametric kernel density estimation. The cdf was estimated using an estimator based on the empirical cdf.

Threshold Solow PDF:
Note that the distribution is double-humped.  The reason that the left-hand hump (corresponding to the "poor" attractor) is small relative to the right-hand hump is that the threshold level of capital stock, kb, is such that once the economy moves into the "rich" attractor's basin it is unlikely to get shocked out.  If you where to raise the threshold kb, then the left-hand hump would get bigger.

Threshold Solow CDF:
 As promised, I will post a link to Github later today with the Python code...

Monday, January 17, 2011

A non-ergodic model of economic growth?...

As part of my ongoing quest to learn more about ergodic theory (and to apply a bit of the Python skills that I have been developing), I have been writing code to implement variations of the Solow model of economic growth using John Stachurski's Economic Dynamics: Theory and Computation as my guide.

Below are some plots of simulations from what I think is a non-Ergodic version of the Solow model.  The equation of motion of capital stock in the Solow model is:
Parameters are defined as follows: α is capital's share in production, s is the savings rate, δ is the rate of capital depreciation.  W are shocks which are assumed to be independently and identically log-normal.  The twist is that technology A follows a step function:
My choice of parameters was α=0.5, s=0.25, A1=15, A2=25, δ=1.0, kb=21.6,  the log-normal shocks have mean 0 and variance 0.2.  This parameter choice might seem very specific, but it simply matches with exercises from Stachurski's book.

Time Series Plots: Below is a plot of two time-series drawn from the above model.  The initial conditions are k0 = 1.0 (blue) and 80.0 (green).   Note the persistence...if you start with low levels of capital stock to begin with it can take a long while to get away from the low attractor.  If the system was deterministic, then if you started with low capital stock, you will always have low capital stock. Initial conditions would completely determine long-run outcomes, and we thus have an example of a poverty trap!
Marginal Distributions: Below is a plot of the empirical distribution function at t=100 time steps.  The left-hand plot is for k0 = 1.0 whilst the right-hand plot is for k0 = 80.0.  Note that the the distributions differ depending on the initial conditions.
I will update this post and make the Python code available via GitHub once I have finished working out the code to simulate and solve for the steady-state distribution of this model.  I know that it will be double-humped (b/c of the two attractors)...

But just to confirm, is this version of the Solow Model non-Ergodic?

Thursday, December 30, 2010

Multiple equilibria and multiple steady states in macro models...

There is an important distinction in economics (that admittedly I have only recently begun to appreciate) between macroeconomic models that exhibit multiple equilibria and those that exhibit multiple steady states.  Part of the reason for my confusion (which was recently cleared up by The Economy As An Evolving Complex System (Santa Fe Institute Series)) was that I held the ridiculous notion equilibrium and steady state meant the same thing.   Alas, at least within the economic sciences this fails to be true.  Economists like to use the term "equilibrium" in many different ways...some of which are very different than the way the term is used in physical and biological sciences.  When economists use the term equilibrium in macroeconomics, they are typically talking about some type of expectations equilibria (I think...some one please correct me if I am off base with this!).  

First an example of multiple steady states.  Multiple steady states can be used as an "explanation" of why some countries are poor and some countries are rich.  There is a variant of the Solow model of economic growth with threshold non-convexities in technology that exhibits this behavior.  This dynamical system has two steady states for the value of capital stock, but the steady state that the economy converges to in the long-run depends on the initial level of capital stock...if initial capital stock is low (i.e., below the threshold) then the economy ends of poor, while if the initial capital stock is high (i.e., above the threshold) then the economy ends of rich.  Economists tend to be more comfortable with the idea of multiple steady states, than with multiple equilibria...

Now to give a concrete example of multiple equilibria, suppose that we augment the above model by giving it "microfoundations."  Basically endogenize the savings rate by allowing it to be a rational representative consumer who seeks to maximize expected utility from consumption choose a savings policy.  This savings policy can be thought of as a function that the consumer uses to choose how much to save after observing the state of the world.  If the model exhibited multiple equilibria, then there would need to exist more than one optimal savings policy that our agent could choose.  Economists tend to be less comfortable with models that exhibit multiple equilibria because such models typically abstract from expectation related coordination issues (why should it be that all agents coordinate their expectations so as to select one of the optimal savings policies over the other?  This is the equilibrium selection problem.).

Hopefully the above two paragraphs capture the distinction between multiple steady states and multiple equilibria...

One last related comment about multiple equilibria in economic models.  I can see why economists are uncomfortable with models that exhibit multiple equilibria when the model itself says nothing about how agents coordinate expectations to select one equilibrium over others.  Most researchers seem to address the equilibrium selection problem by developing newer and more sophisticated versions of equilibrium (i.e., evolutionary stable, trembling-hand, stochastic-stable, etc).  I feel like this strategy is fundamentally flawed.  How are problems of equilibrium selection solved in the real world of heterogeneous, interacting agents?  One possible answer is that such problems are solved via socio-cultural norms and institutions...

Monday, December 27, 2010

Ergodicity and the Dobrushin Coefficient...

I am working my way through Chapter 4 of Economic Dynamics: Theory and Computation and wish to pose the following question related to theorem 4.3.18 on page 90:

Theorem 4.3.18: Let p be a stochastic kernel on some metric space S with markov operator M.  The following statements are equivalent:
  1. The dynamical system (P(S), M) is globally stable (note that P(S) is the set of probability distribution functions defined over S).
  2. There exists a natural number t such that the Dobrushin coefficient of the t th iterate of p is greater than zero.
Stachurski suggests a more intuitive phrasing of the above theorem: suppose we run two Markov chains from two different starting points x and x'.  The dynamical system is globally stable if and only if there is a positive probability that the two chains will meet.  To me this sounds suspiciously similar to the definition of an ergodic dynamical system.  However, am I correct to make this connection?  Is a dynamical system that has a positive Dobrushin coefficient necessarily ergodic?