load(draw)$ 
set_draw_defaults(draw_realpart=false)$
kill(all)$ fpprintprec:5$ ratprint:false$

# Time

This chapter considers two aspects of time. The first involves the analysis
of decisions whose effects have implications over time for costs or revenues.
The second involves processes that play out over time, in a dynamic fashion.

## Introduction

## Intertemporal Decisions

## Investment

## Harvest Rotation

## A Simple Dynamic Model

This section considers the Cobweb Model, a simple model that takes 
time into account. A linear supply curve and a linear demand curve
illustrate this model: Xs[t] = A + a*p[t - 1] and Xd[t] = B + b*p[t].
The bracketed terms indicate period number. Thus, the quantity supplied 
in the current period is a function of the price in the preceding period, 
and the quantity demanded is a function of the current price.

The first cell creates the functions for the supply and demand
curves. Moving the market forward one period in time allows the 
value of price in an initial period (t = 0) to be specified.

Solving this system requires loading solve_rec, a module for solving
recursive systems like this one. The initial price, p[0], is named
p0. The solution shows that p[t] is a function of the parameters of 
the supply and demand curves, p0, and t.

load(solve_rec)$ Xs(p, A, a):=A+a*p[t];
Xd(p, B, b) := B + b*p[t+1];
solnp1 : solve(Xs(p,A,a)-Xd(p,B,b),p[t+1]);
solnrec : solve_rec(solnp1[1], p[t], p[0]=p0);
p(p0, t, A, a, B, b) := ''(rhs(solnrec));

The term (a/b) is negative. If (a/b) > -1, then the first and last
terms become small as t increases, but if (a/b) < -1, these terms become
larger, switching signs each period. Thus stability requires (a/b) > -1. 

The next cell specifies values for X[0], named X0, and for p[0],
named p00 because p0 was used above. It also specifies slope values.
Then it derives intercept values consistent with those specified values.

[X0,p00]:[1000.0,20.0]$  [a0, b0]:[40.0,-50.0]$
matrix(["A0","B0"],[A0: X0 - a0*p00,     B0: X0 - b0*p00]);

TeX:
Next, we create a list of 11 time periods and apply the
equation for price, given the preceding parameter values.
The third input line below defines the quantity demanded
in each period, given the period's price. 

Then we create a list of the first 10 prices and determine
the quantity supplied for each period. This quantity supplied
must equal the quantity demaned in the next period; that is 
how the next-period price is determined. We create 10-period
lists for the period number and for the price, by deleting 
the intitial period ($t = 0$). 

The table below shows that the quantity demanded equals 
the quantity supplied for each period and the price that
yield this result. It also shows the lagged price, which
determines the current quantity.

/* Construct a time list, a price list, and a quantity
  demanded list */
tlist: makelist(i, i, 0, 10)$
plist : p(p00, tlist, A0, a0, 1.5*B0, b0)$
Xdlist : 1.5*B0 + b0*plist$

/*Delete the last price from the price list. Use the new
 list to create 10 quantity supplied and quantity demanded values*/
plistshort : delete(plist[11], plist)$
Xslist10: A0 + a0*plistshort$
Xdlist10: delete(Xdlist[1], Xdlist)$

/*Removed the period 0 values for price and time */
plist10 : delete(plist[1], plist)$
tlist10: delete(tlist[1], tlist)$

/*Create a matrix with 10 rows that contain the values for 
 periods 1 through 10 */
numbers: transpose(matrix(tlist10, Xdlist10, 
Xslist10, plist10, plistshort))$

/*Create a vector of names and add it to the numbers matrix */

names : matrix(["Time", "Xdemand", "Xsupply","Price","LagPrice"])$
addrow(names, numbers);

Graph the movement of price and quantity through time.

prices: gr2d(xrange = [0, 10], 
 ylabel = "$ per unit", points_joined = true, 
 points(tlist, plist))$

quantities: gr2d(xrange=[0,10],points_joined=true, 
xlabel = "time", ylabel = "Units per time period",
ytics=250,points(tlist10, Xslist10))$     

wxdraw(prices, quantities,dimensions=[480,540])$

Place the values above in a traditional graph of a competitive 
market. Map the ten quantities supplied on the lagged price, which 
determines the current period's quantity. Likewise,map the quantities 
demanded on the current prices. 

Xspdata : map("[", Xslist10, plistshort)$
Xdpdata : map("[", Xdlist10, plist10)$
transpose(matrix(Xspdata, Xdpdata));

The next step is not required, but it illustrates a
potentially useful command, join( ), which creates a
single data table that can be passed to draw2d( ).

datalist: join(Xspdata, Xdpdata);

The graph below shows the data points generated above,
along with the demand and supply curves. The cobweb shape
becomes apparent.

Xsorted : sort(Xdlist)$ 
Xmax: Xsorted[11]$ Xmin: Xsorted[1]$
wxdraw2d( user_preamble = "set key bottom left",
xlabel = "X", ylabel = "$ per unit", 
key = "Initial Demand",
explicit((X - A0)/a0 , X, .9*Xmin, 1.1*Xmax),
line_width = 2, key = "New Demand",
explicit((X - 1.5*B0)/b0, X, 0.9*Xmin, 1.1*Xmax),
line_width = 1, color = black, key = "Supply",
explicit((X - B0)/b0, X, 0.9*Xmin, 1.1*Xmax),
point_type=13,points_joined=true,line_type=dots,
key = "path", points(datalist))$  
kill(Xsorted, Xmax, Xmin)$

Maxima's dynamics module can produce representations in a direct manner. 
This module's evolution( ) command produces and set of prices,
and its staircase command produces a cobweb representation.

The expression for p[t+1] in terms of  p[t] is 36 - 0.8*p.

solnp1;
path: -(B0-A0-a0*p)/b0;

The command evolution(expression, initial value, number of 
periods, [option]) generates a path of p(t) for t ranging from 0 to the 
indicated number of time periods, t = 10 here. The initial value can be
any value other then the equilibrium value. the [styles,lines] option
is required if the points are to be joined. The styles options are those
used in plot2d( ).

This command and the next one produce an image outside of wxMaxima. This
image can be edited and saved for use in documents or presentations.

load(dynamics)$
evolution(path,30,10,[style,lines])$

The staircase( ) command produces a graph that looks much like the cobweb
model above. The two are quite different, however, in that staircase( )
generate a graph of p[t+1] against p[t] and does not show quantities.

staircase(path,30,10)$

### Adaptive Expectations

The expressions below are the same as above, except that the price 
in the supply curve is now an expected price. In the simple Cobweb 
model, the expectation is that the previous period's price will 
persist in this period, that is pe[t] = p[t-1].

kill(all)$    load(solve_rec)$
Xs(p, A, a) := A + a*pe[t];
Xd(p, B, b) := B + b*p[t];

Given that markets clear, the following condition must hold. Full
equilibrium requires the additional condition pe = p, yielding a
result that we have encountered before: p = (A - B)/(b - a).

A + a*pe = B + b*p$
solve(%, pe);
/*Added material: For equilibrium */
solve(subst(pe=p,%),p);

A simple adaptive expectations model treats expectations as 
a linear combination of expectation for the preceding period and the 
deviation from that expectation, with 0 <= e <= 1.

expectations:pe[t]=pe[t-1]+e*(p[t-1]-pe[t-1]);

Determine the functional relationship between p and t: p[t] is 
a difference equation. The 
next two lines solve this difference equation, extract
the expression for that solution and state price as 
a function with that expression on the right-hand side.
The last two steps are not printed.

/* Express p[t] in terms of pe[t] */
solve(Xs(p, A, a) = Xd(p, B, b), p[t]);

/* Insert the expression for pe[t] */
subst(expectations,%[1]);

/* Insert this expression again, this time for pe[t-1] */
subst(pe[t-1] = (B - A + b*p[t-1])/a,%);

/* Solve the difference equation */
solnrec2 : solve_rec(%, p[t], p[0] = p0);

/* Create the functional expression for price */
p(t, p0, A, a, B, b, e):=''(rhs(%))$

We assign values as in the case of the Cobweb model, adding a specified
value for e.

[X0, p00] : [1000.0, 20.0]$  
[a0, b0, e0] : [40.0, -50.0, 0.9]$
[A0: X0 - a0*p00,     B0: X0 - b0*p00];

The resulting expression results in convergence, for
the term raised to the t power is between -1 and zero.

p(t, p00, A0, a0, B0, b0, e0);

To trace the dynamic pattern, shift the supply curve, 
reducing the intercept term to 0.25*A0.

float([solve(.25*A0 + a0*p = B0 + b0*p, p),
solve(A0 + a0*p = B0 + b0*p, p)]);

We use that fact that e = 1 generates the Cobweb model results,
and compare those results to the price paths for two other values,
e = 0.9 and e = 0.4.

tlist: makelist(i, i, 0, 10)$
cobweblist:  p(tlist, p00, .25*A0, a0, B0, b0, 1)$
p1list : p(tlist, p00, .25*A0, a0, B0, b0, .9)$
p2list : p(tlist,p00, .25*A0, a0, B0, b0, .4)$
names : matrix(["Time", "Cobweb Path", "Price Path 1", 
"Price Path 2"])$ numbers: transpose(matrix(
 tlist,cobweblist, p1list,p2list) )$
addrow(names, numbers);

The graph shows the path that p takes as it converges on 
the new, higher price level for each e value. 

wxdraw2d(xlabel="Time",ylabel="$ per unit",
 points_joined=true,
 key="Cobweb",points(tlist,cobweblist), 
 color=red,line_type = dots, 
 key = "e = 0.9",points(tlist,p1list),
 color = black, point_type=4,  
 key = "e = 0.4", points(tlist, p2list)     )$