schema comput
TRANSCRIPT
8/3/2019 Schema comput
http://slidepdf.com/reader/full/schema-comput 1/13
Chapter 1
Useful to use excel when we have a small enough model
Using a one-sector growth model (Ramsey)
Brief description:Trade off b/w consumpion and investment
Finite horizon, terminal capital stock constraint
Key elements of the model: Production fn w/ capital as output, capital accumulation relationship
(using investment to create new capital), utility function resulting from consumption
More consumption in a time period means more utility in that time period but less
investment and therefore less capital stock and less production in future time periods.
Aggregate prod fn: Yt = Ɵ K tα Cobb-douglas Fn w/ just one variable
Where is a technology parameter and α is the exponent of capital in the prod fnƟ
Capital accumulation relationship: K t+1 = K t + Yt – Ct = K t + Ɵ K tα – Ct
If Yt – Ct is positive then it is investment, if it is negative then it is saving
Then there's an initial condition, that initial capital K 0 is given
Terminal condition that fixes a min amount of K: K N ≤ K *
Criterion fn: U(Ct) =1
1−τ* Ct
(1- τ) where τ is a parameter of the utility fn
The sum of discounted utilities will be: J = ∑t =1
N −1
βt ⋅U (C t ) Discounted value for the
utility obtained from consumption over all of the periods covered by the model, where the
discount factor β=1
1+ρand ρ is the discount rate.
Substituting the utility fn, we obtain: J = ∑t =1
N −1
βt ⋅
1
1−τ⋅C t
(1−τ)
So, summing up all this stuff, the problem should be stated as follows:
Find (C1, C2, C3, …, C N-1) in order to maximize J = ∑t =1
N −1
βt ⋅
1
1−τ⋅C t
(1−τ)
Subject to K t+1 = K t + Ɵ K tα – Ct
K 0 given
K N ≤ K *
This model is NON-LINEAR because of the criterion function J and of the capital accumulation
equation.
Remember also that when the discount rate ρ is higher, future utility is discounted more heavily,
that is given less weight in the criterion fn (see table)
8/3/2019 Schema comput
http://slidepdf.com/reader/full/schema-comput 2/13
The graph above illustrates how consumption changes over time wrt beta. (The higher the beta,
the higher will be consumption in future years)
Modifying theta, the efficiency of the production process changes in a directly proportional way.
Modifying tau instead, we affect the curvature of the utility function or its degree of MU.
Chapter 2
In the neural networks model, we begin from observed behaviour and attempt to find parameters which
permit to find the specified relationships to most closely fit the data. These models are suitable to deal
with problem in which relationships between variables are not well-known and with data sets whose
underlying non-linearities and not known in advance.
Here we will apply the to finance, specifically to best predict future price of stocks.
The central notion of neural net analysis is that we can use a set of observations from the past to predict
future relationships. To predict a future company's stock price we will use stock prices of relatedcompanies: suppliers and competitors.
Brief description:
Neural networks are composed by three main elements: processing elements (called nodes or neurons),
an interconnection topology and a learning scheme. It processes data through multiple parallel
processing elements, which do not store any data or decision result. The network processing fn “learn”
or “adapt” assuming specific patterns which reflect the nature of those inputs. We can see now the
typical structure of a neural network:
8/3/2019 Schema comput
http://slidepdf.com/reader/full/schema-comput 3/13
The neuron, an elementary processing unit that generates output given inputs, is composed by two parts:a combination fn and an activation fn.
The combination fn usually compute the net input as a weighted sum of the inputs, the activation fn
computes output given the net input. The output is usually ranged from 0 to 1 using different functional
form al logistic and sigmoid fns.
Input layer neurons receive data (“signals”) from outside and in general transmit them to the next layer
without processing them. Output layer neurons return data to the outside, and are sometimes set to apply
their combination functions only.
The learning process consist of choosing weights and this is doing by giving the model some inputs,
comparing the output to a known target and then finding the right weights by computing the error and
minimizing it.
Specific example: The automobile stock market
We begin by specifying the combination fn for the output layer:
Y t =θ0+∑ j=1
q
θ j⋅a tj where Yt is the output in period t, q is the number of hidden nodes, the atj
are the hidden nodes values in period t and the θ's are the parameters we are looking for.
The atj are given by the expression:
a tj=1
1+ e− z z =∑i=1
q j
w ji⋅ x it we have to find also the parameters w ji, the xit are the inputs at node i
It follows the shape of the function providing the atj: we can see that its range is from 0 to 1.
8/3/2019 Schema comput
http://slidepdf.com/reader/full/schema-comput 4/13
The objective fn of this model is the squared deviations from the predicted output and the actual output
(where in this case the output is the automotive company stock price):
This function in to be minimized by changing the parameters descibed before.
∑t =1
n
(γt − yt )2
Where γ is the actual value of stock price and n is the n° of observations
Chapter 4
Here the problem is about finding the most efficient place and manner of producing goods and shipping
them to customers minimizing the transportation costs.
We will use GAMS to find the pattern of shipments from 2 plants to 3 mkts. which will have the least
transportation cost while satisfying the fixed demand at the markets without shipping more from any
plant than its’ capacity.
Math representation:
We have 2 sets: I (plants) and J (mkts). We have to find the shipments from plants to mkts x ij, such that
the transportation cost z is minimized.
Z= ∑i∈ I
∑ j∈ J
cij⋅ x ij where cij is the transportation cost per unit prom plant I to mkt j.
We have two constraints: the first relating to max capacities and the second relating to satisfying mkts'
demands.
(1) ∑ j∈ J
x ij⩽ aij
(2) ∑i∈ I
xij⩽ bij
And of course all shipments must be non-negative.
8/3/2019 Schema comput
http://slidepdf.com/reader/full/schema-comput 5/13
GAMS representation:
Here follow the code used in GAMS for the transportation model:
SETS
I canning plants / SEATTLE, SAN-DIEGO /
J markets / NEW-YORK, CHICAGO, TOPEKA / ;
PARAMETERS
A(I) capacity of plant i in cases
/ SEATTLE 350
SAN-DIEGO 600 /
B(J) demand at market j in cases
/ NEW-YORK 325
CHICAGO 300
TOPEKA 275 / ;
TABLE D(I,J) distance in thousands of miles
NEW-YORK CHICAGO TOPEKASEATTLE 2.5 1.7 1.8
SAN-DIEGO 2.5 1.8 1.4 ;
SCALAR F freight in dollars per case per thousand miles /90/ ;
PARAMETER C(I,J) transport cost in thousands of dollars per case ;
C(I,J) = F * D(I,J) / 1000 ;
VARIABLES
X(I,J) shipment quantities in cases
Z total transportation costs in thousands of dollars ;
POSITIVE VARIABLE X ;
EQUATIONS
COST define objective function
SUPPLY(I) observe supply limit at plant i
DEMAND(J) satisfy demand at market j ;
COST .. Z =E= SUM((I,J), C(I,J)*X(I,J)) ;
SUPPLY(I) .. SUM(J, X(I,J)) =L= A(I) ;
DEMAND(J) .. SUM(I, X(I,J)) =G= B(J) ;
MODEL TRANSPORT /ALL/ ;
SOLVE TRANSPORT USING LP MINIMIZING Z ;
DISPLAY X.L, X.M ;
Rememer the order in which things must be put into:
Set
Parameters
VariablesEquations
Model
Solve.
8/3/2019 Schema comput
http://slidepdf.com/reader/full/schema-comput 6/13
One should first locate the Solve Summary part of the output. To do this search in the editor for the
string "SOLVER STATUS".
S O L V E S U M M A R Y
MODEL TRANSPORT OBJECTIVE Z
TYPE LP DIRECTION MINIMIZE
SOLVER BDMLP FROM LINE 70**** SOLVER STATUS 1 NORMAL COMPLETION
**** MODEL STATUS 1 OPTIMAL
**** OBJECTIVE VALUE 153.6750
Each time after you solve a GAMS model you should check this section of the output to be sure that the
model was solved successfully. The words NORMAL COMPLETION here indicate that is the case. If the
solution procedure was not successful you will find words like INFEASIBLE or UNBOUNDED. Be on
guard against the fact that the GAMS output will provide a solution to the model even when that
solution is infeasible. However, the solution provided would not be the optimal solution but rather the
last one tried before it was determined that the solution was infeasible.
Chapter 6
This model helps us to simulate a student's personal financial situation. We will use GAMS to solve the
problem of minimizing the squared separations b/w the desired paths of savings and consumption and
the optimal paths.
Mathematics of the model:
Let's first define the assets and liability account by denoting the states, the x's:
xt = [SbSe
Sc
Scc
Ssl ]
Where the Sb is the stock of bonds, Se of equity, Sc of the checking account, Scc of the credit card, Ssl
of the student loan.
Then we have the control variables, the u's, that indicate the transfers from one a/c to another and can be
positive or negative depending on the direction of the transfer.
We can find also the exogenous variables: Wa (wages), Le (living expenses) and Sh (scolarship).
Here follows the GAMS code, where we can see all the formulas used and the mechanics of the
problem.
Sets n states / Sb, Se, Sc, Scc, Ssl /
m controls / Xbe, Xbc, Xbcc, Xbsl, Xec, Xecc, Xesl, Xcacc, Xcsl,
Xccsl /
k exogenous / Wa, Le, Sh /
t horizon / 2000, 2001, 2002, 2003, 2004 /
tu(t) control horizon
ti(t) initial period
tz(t) terminal period ;
8/3/2019 Schema comput
http://slidepdf.com/reader/full/schema-comput 7/13
Alias (n,np), (m,mp) ;
tu(t) = yes$(ord(t) lt card(t));
ti(t) = yes$(ord(t) eq 1);
tz(t) = not tu(t);
Display t, ti, tz, tu;
Table a(n,np) state vector matrix
Sb Se Sc Scc Ssl
Sb 1.05
Se 1.10
Sc 1.01
Scc 1.13
Ssl 1.04
Table b(n,m) control vector matrix
Xbe Xbc Xbcc Xbsl Xec Xecc Xesl
Sb -1 -1 -1 -1
Se 1 -1 -1 -1Sc 1 1
Scc -1 -1
Ssl -1 -1
+
Xcacc Xcsl Xccsl
Sb
Se
Sc -1 -1
Scc -1 1
Ssl -1 -1
Table c(n,k) exogenous vector matrix
Wa Le Sh
Sb
Se
Sc 1 -1 1
Scc
Ssl
Table w(n,np) state vector matrix penalty matrix
Sb Se Sc Scc Ssl
Sb 100Se 100
Sc 400
Scc 200
Ssl 0
Table wn(n,np) terminal state vector matrix penalty matrix
Sb Se Sc Scc Ssl
Sb 200
Se 200
Sc 800
Scc 200
Ssl 1
Table lambda(m,mp) lambda matrix
8/3/2019 Schema comput
http://slidepdf.com/reader/full/schema-comput 8/13
Xbe Xbc Xbcc Xbsl Xec Xecc Xesl
Xbe 20
Xbc 1
Xbcc 20
Xbsl 20
Xec 20
Xecc 20
Xesl 20
+
Xcacc Xcsl Xccsl
Xcacc 1
Xcsl 1
Xccsl 20
Table xtilde(n,t) state vector desired paths
2000 2001 2002 2003 2004
Sb
Se
Sc 1000 1000 1000 1000 1000
Scc 2000 2000 2000 2000 2000Ssl
Table utilde(m,t) control vector desired paths
2000 2001 2002 2003
Xbe
Xbc
Xbcc
Xbsl
Xec
Xecc
Xesl
XcaccXcsl
Xccsl
Parameter
xinit(n) initial value /
Sb 4000
Se 0
Sc 1000
Scc 0
Ssl 0 /
Table z(k,t) exogenous variables
2000 2001 2002 2003 2004
Wa 15000 15000 15000 15000 15000
Le 20000 20000 20000 20000 20000
Sh 0 0 0 0 0
Variables u(m,t) control variable
j criterion ;
Positive Variables x(n,t) state variable ;
Equations
criterion criterion definition
stateq(n,t) state equation ;
criterion..
8/3/2019 Schema comput
http://slidepdf.com/reader/full/schema-comput 9/13
j =e= .5*sum( (tz,n,np),(x(n,tz) - xtilde(n,tz))*wn(n,np)*(x(np,tz) -
xtilde(np,tz)) ) +
.5*sum( (tu,n,np),(x(n,tu) - xtilde(n,tu))*w(n,np)*(x(np,tu) -
xtilde(np,tu)) ) +
.5*sum( (tu,m,mp),(u(m,tu) - utilde(m,tu))*lambda(m,mp)*(u(mp,tu) -
utilde(mp,tu)) ) ;
stateq(n,t+1)..
x(n,t+1) =e= sum(np, (a(n,np)*x(np,t))) + sum(m, (b(n,m)*u(m,t))) + sum(k,
(c(n,k)*z(k,t)));
Model track /all/;
x.fx(n,ti) = xinit(n);
Solve track minimizing j using nlp;
Display x.l, u.l;
Chapter 8
Input-Output model
In this model we consider an economy with three industries (1, 2 and 3). Each of them produces a single
output, using as inputs part of its own production as well as part of the output from the other. Each
industry plays a dual role since it is both a supplier of inputs and a user of outputs. Imagine that each
product in this economy is also used to satisfy external demand.
The economy can be represented by the following linear system of equations:
x1=a
11⋅ x
1+ a
12⋅ x
2+ a
13⋅ x
3+ d
1 Where the x's are the production levels for each industry, the aij
x
2=a
21⋅ x
1+a
22⋅ x
2+a
23⋅ x
3+d
2 are the input-output coefficients (the intermediate requirement x
3=a
31⋅ x
1+ a
32⋅ x
2+ a
33⋅ x
3+ d
3 from industry I per unit of output of industry j) and the d's are the
final demand
It can also be written more simply in matrix notation:
x= A⋅ x+ d
Here it is the GAMS statement:
SCALARS
d1 final demand for x1 /4/
d2 final demand for x2 /5/d3 final demand for x3 /3/;
VARIABLES
x1 production level industry 1
x2 production level industry 2
x3 production level industry 3
j performance index used to set upe the fake optimazation problem;
EQUATIONS
eqx1
eqx2
eqx3
jd performance index definition always a fake;
jd.. j =E= 0;
eqx1.. x1 =E= 0.3*x1 + 0.2*x2 + 0.2*x3 + d1;
8/3/2019 Schema comput
http://slidepdf.com/reader/full/schema-comput 10/13
eqx2.. x2 =E= 0.1*x1 + 0.4*x2 + 0.5*x3 + d2;
eqx3.. x3 =E= 0.4*x1 + 0.1*x2 + 0.2*x3 + d3;
MODEL IO /jd, eqx1, eqx2, eqx3/;
SOLVE IO MAXIMIZING J USING LP;
DISPLAY x1.l, x2.l, x3.l;
As we can see we had to add a fake criterion function, j, because GAMS optimize but has not
procedures to solve the model by solving simultaneous equations. We thus “cheat”, by inserting a
function that has to be maximized but it actually has nothing to do with the model itself, just to make
GAMS capable to solve the linear system.
Production prices model
This model is a non-linear model in which prices have to be determined given technology and a
distributive variable. One of the main goals is to study issues of income distribution b/w wages and
profits. We define as:
v = value of intermediate inputs
π = profits
w = wage cost
p = price
So that: v + π + w = p.
We also assume that profits are equal to a profit rate, r, times v: π = v*r
And we obtain: v*(1+r) + w = p.
We then use the input-output coefficients for intermediate inputs and for wages:
(a11⋅ p1+ a21⋅ p2+ a31⋅ p3)⋅(1+ r )+ l 1⋅w= p1
(a12⋅ p1+ a22⋅ p2+ a32⋅ p3)⋅(1+ r )+ l 2⋅w= p2
(a13⋅ p1+ a23⋅ p2+ a33⋅ p3)⋅(1+ r )+ l 3⋅w= p3
The a's have the subscripts reversed wrt the previous model because they're the transposed matrix A
because here we determine prices given technology and in the input-Output model we determined
quantities given technology. The l's are also input-Output coefficients indicating the quantity of labor
required for the production of one unit of product. W is assumed to be uniform for the whole economy
and r is the same for every industry otherwise there would be capital movement from industries where r
is tow to industries where the rate is higher. Since all prices are relative we need to choose one in order
to express al the others in terms of it. We can do this by fixing one price and to deal with the degree of freedom wrt w and r we should fix w, for example, too.
Here is the model in GAMS:
SCALARS
L1 /0.2/
L2 /0.5/
L3 /0.3/;
VARIABLES
p1
p2p3
w
r
8/3/2019 Schema comput
http://slidepdf.com/reader/full/schema-comput 11/13
j performance index;
EQUATIONS
eqp1
eqp2
eqp3
jd performance index definition;
jd.. j =E= 0;
eqp1.. (0.3*p1 + 0.1*p2 + 0.4*p3) * (1+r) + L1 * w =E= p1;
eqp2.. (0.2*p1 + 0.4*p2 + 0.1*p3) * (1+r) + L2 * w =E= p2;
eqp3.. (0.2*p1 + 0.5*p2 + 0.2*p3) * (1+r) + L3 * w =E= p3;
r.fx = 0;
p1.fx = 1;
MODEL PP1 /all/;
SOLVE PP1 MAXIMIZING J USING NLP;
DISPLAY p1.l, p2.l, p3.l, w.l, r.l;
It is interesting to see what happen as r changes:
We can note that there is an inverse relationship b/w w and r.
In this example, not only wages, but also prices go up as r decreases. However, in general, prices can go
either way - some may go up, others down. However, if we choose w as the numeraire, we will observe
that as r increases, all prices increase, indicating that he real wage will decrease no matter the weights
used to compute the corresponding wage deflator.. (The wage deflator is the wage divided by the price
of 1 good).
General equilibrium model
Here we move to a model in which quantities and prices are determined simultaneously. One of the
main goals is to study the change in prices and quantities when technology, preferences or endowments
changes.
We have a very simple economy with just one production sector, two factors of production and a single
household. The prod sector produces a single good qs, with a Cobb-Douglas constant returns to scale
prod technology using two inputs: labor and capital. Technical progress (b) can affect total factor
productivity. The labor and capital demand function ld and k d are derived combining the prod fn with the
assumption of profit max behaviour. Labor and capital supplies ls and k s are given exogenously. The
household provides labor and capital in exchange for the corresponding wage w and profit r, spending
all his income y, in the demand for the single good qd.
Three mkts (labor, capital and good) and supply=demand.
8/3/2019 Schema comput
http://slidepdf.com/reader/full/schema-comput 12/13
Equations:
q s=b⋅(l d )a⋅(k d )
(1−a)prod fn;
l d =(a⋅q s⋅ p)
wlabor demand;
l s= l s labor supply;
l s=l d market clearing condition.
*** To obtain the expressions for ld and k d :
Max π= p⋅q s−w⋅l d −r ⋅k d
s.t q s=b⋅l d a⋅k d
(1−a)
---> π= p⋅(b⋅l d
a⋅k d
(1−a))−w⋅l d −r ⋅k d
The first order conditions are:
(δπ)(δl d )
= p⋅a⋅b⋅l d (a−1 )⋅k d
(1−a )−w = 0
(δπ)(δk d )
= p⋅(1−a )⋅b⋅l d a⋅k d
−a−r = 0
Substituting the production function into I and II and rearranging terms we obtain, respectively, thelabor and capital demand functions ld and k d.****
K d =((1−a )q s p)
r capital demand
k s=k s capital supply
k s = k d Market clearing condition
y = wld + rk d household income
qd = y
pgood demand
qd = qs good market clearing condition
This simple model has 10 variables and 10 equations .However, one of them is redundant, since “Walras
law” establishes that for n-markets we need n-1 equilibrium conditions only. We thus choose one price
as the numeraire in order to express all other prices in terms of it. Plus we delete the good market
clearing condition.
Here follows the GAMS code:
SCALARS
a labor share / 0.7 /
8/3/2019 Schema comput
http://slidepdf.com/reader/full/schema-comput 13/13
b technology parameter / 1.2 /;
POSITIVE VARIABLES
qs good supply
qd good demand
ld labor demand
ls labor supply
kd capital demand
ks capital supply
p price
w wage
r profit
y income;
VARIABLES
j performance index;
EQUATIONS
eqs good supply equation (production funcion)
eqd good demand equation
eld labor demand equation
els labor supply equationekd capital demand equation
eks capital supply equation
ey income equation
eml labor market clearing
emk capital market clearing
jd performance index definition;
jd.. j =E= 0;
eqs.. qs =E= b * ld**a * kd**(1-a);
eld.. ld =E= a * qs * p / w;
els.. ls =E= 2;
eml.. ld =E= ls;ekd.. kd =E= (1-a)* qs * p / r;
eks.. ks =E= 1;
emk.. kd =E= ks;
ey.. y =E= w * ld + r * kd;
eqd.. qd =E= y / p;
*lower bounds to avoid division by zero
p.lo = 0.001; w.lo = 0.001; r.lo = 0.001;
*numeraire
p.fx = 1;
MODEL SIMPLEGE /all/;SOLVE SIMPLEGE MAXIMIZING J USING NLP;
DISPLAY qs.l, qd.l, ld.l, ls.l, kd.l, ks.l, p.l, w.l, r.l, y.l;
We have to verify that supply=demand in each market.
We can note also that when the value of the numeraire increase, all quantity vars should remain the same
while nominal vars (price and income) should increase proportionally.
Money in this model is not explicited, so we can consider it as a model of the “real” side of the
economy: the result of the change in the numeraire can be interpreted as money to be neutral in this
model.