# \donttest{
#### an OLGF pure exchange economy with two-period-lived consumers.
## Suppose each consumer has one unit of labor in her first period
## and she has a C-D intertemporal utility function
## (1 - beta) * log(c1) + beta * log(c2) and a constant saving rate beta.
beta <- 0.5
ratio.saving.consumption <- beta / (1 - beta)
dst.age1 <- node_new(
"util",
type = "FIN",
rate = c(1, ratio.saving.consumption),
"lab", "secy" # security, the financial instrument
)
dst.age2 <- node_new(
"util",
type = "Leontief", a = 1,
"lab"
)
ge <- sdm2(
A = list(
dst.age1, dst.age2
),
B = matrix(0, 2, 2, TRUE),
S0Exg = matrix(c(
1, NA,
NA, 1
), 2, 2, TRUE),
names.commodity = c("lab", "secy"),
names.agent = c("age1", "age2"),
numeraire = "secy"
)
ge$p
ge$D
ge$DV
ge$S
#### population growth and demographic dividend.
## Suppose each consumer has a SCES intertemporal utility function.
pgr <- 0.03 # population growth rate
beta2 <- 0.4 # share parameters of the SCES function
beta1 <- 1 - beta2
es <- 0.5 # the elasticity of substitution in the SCES function
dst.age1 <- node_new(
"util",
type = "FIN",
rate = c(1, ratio.saving.consumption = 0.1),
"lab", "secy", # security, the financial instrument
p.lab.last = 1,
p.lab.ratio.predicted.last = 1,
ts.saving.rate = numeric(0)
)
dst.age2 <- node_new(
"util",
type = "Leontief", a = 1,
"lab"
)
ge <- sdm2(
A = list(
dst.age1, dst.age2
),
B = matrix(0, 2, 2, TRUE),
S0Exg = matrix(c(
1, NA,
NA, 1
), 2, 2, TRUE),
names.commodity = c("lab", "secy"),
names.agent = c("age1", "age2"),
numeraire = "secy",
policy = list(function(time, A, state) {
state$S[1, 1] <- (1 + pgr)^time
p.lab.current <- state$p[1] / state$p[2]
lambda <- 0.6
p.lab.ratio.predicted <- p.lab.current / A[[1]]$p.lab.last * lambda +
A[[1]]$p.lab.ratio.predicted.last * (1 - lambda)
A[[1]]$p.lab.last <- p.lab.current
A[[1]]$p.lab.ratio.predicted.last <- p.lab.ratio.predicted
ratio.saving.consumption <- beta2 / beta1 * (p.lab.ratio.predicted)^(1 - es)
A[[1]]$rate <- c(1, ratio.saving.consumption)
A[[1]]$ts.saving.rate <- c(A[[1]]$ts.saving.rate, ratio.saving.consumption /
(1 + ratio.saving.consumption))
state
}, policyMarketClearingPrice),
maxIteration = 1,
numberOfPeriods = 50,
ts = TRUE
)
matplot(growth_rate(ge$ts.p), type = "o", pch = 20)
matplot(growth_rate(ge$ts.z), type = "o", pch = 20)
ge$p
dst.age1$rate[2] # beta2 / beta1 * (1 + pgr)^(es - 1)
dst.age1$p.lab.ratio.predicted.last
plot(dst.age1$ts.saving.rate, type = "o", pch = 20)
tail(dst.age1$ts.saving.rate,1) # beta2 / (beta2 + beta1 * (1 + pgr)^(1 - es))
#### the basic overlapping generations (inefficient) exchange model.
## Here the lab2 is regarded as a financial instrument (saving instrument).
## See gemOLGPureExchange_2_2.
dst.age1 <- node_new(
"util",
type = "FIN",
rate = c(1, ratio.totalSaving.consumption = 2),
"lab1", "lab2"
)
dst.age2 <- node_new(
"util",
type = "FIN",
rate = c(1, ratio.saving.consumption = 1),
"lab1", "lab2"
)
ge <- sdm2(
A = list(dst.age1, dst.age2),
B = matrix(0, 2, 2),
S0Exg = matrix(c(
1, 1,
1, 0
), 2, 2, TRUE),
names.commodity = c("lab1", "lab2"),
names.agent = c("age1", "age2"),
numeraire = "lab1",
policy = function(time, state) {
pension <- (state$last.A[, 2] * state$last.z[2])[2]
if (time > 1) state$S[1, 2] <- 1 - pension
state
}
)
ge$p
ge$S
ge$D
ge$DV
#### the basic financial overlapping generations exchange model (see Samuelson, 1958).
## Suppose each consumer has a utility function log(c1) + log(c2) + log(c3).
GRExg <- 0.03 # the population growth rate
rho <- 1 / (1 + GRExg)
dst.age1 <- node_new(
"util",
type = "FIN",
rate = {
saving.rate <- (2 - rho) / 3
c(1, ratio.saving.consumption = saving.rate / (1 - saving.rate))
},
"lab", "secy"
)
dst.age2 <- node_new(
"util",
type = "FIN",
rate = c(1, ratio.saving.consumption = 1),
"lab", "secy"
)
dst.age3 <- node_new(
"util",
type = "Leontief", a = 1,
"lab"
)
ge <- sdm2(
A = list(dst.age1, dst.age2, dst.age3),
B = matrix(0, 2, 3),
S0Exg = matrix(c(
1 + GRExg, 1, 0,
0, 0.5, 0.5
), 2, 3, TRUE),
names.commodity = c("lab", "secy"),
names.agent = c("age1", "age2", "age3"),
numeraire = "lab",
policy = function(time, state) {
# Assume that unsold security will be void.
last.Demand <- state$last.A %*% dg(state$last.z)
secy.holding <- prop.table(last.Demand[2, ])
if (time > 1) {
state$S[2, 2:3] <- secy.holding[1:2]
}
state
}
)
ge$p
ge$S
ge$D
#### a pure exchange economy with three-period-lived consumers.
## Suppose each consumer has a Leontief-type utility function min(c1, c2, c3).
GRExg <- 0.03 # the population growth rate
igr <- 1 + GRExg
dst.age1 <- node_new(
"util",
type = "FIN",
rate = {
saving.rate <- 1 / (1 + igr + igr^2)
c(1, ratio.saving.consumption = saving.rate / (1 - saving.rate))
},
"lab", "secy"
)
dst.age2 <- node_new(
"util",
type = "FIN",
rate = {
saving.rate <- 1 / (1 + igr)
c(1, ratio.saving.consumption = saving.rate / (1 - saving.rate))
},
"lab", "secy"
)
dst.age3 <- node_new(
"util",
type = "Leontief", a = 1,
"lab"
)
ge <- sdm2(
A = list(dst.age1, dst.age2, dst.age3),
B = matrix(0, 2, 3),
S0Exg = matrix(c(
1 + GRExg, 1, 0,
0, 0.5, 0.5
), 2, 3, TRUE),
names.commodity = c("lab", "secy"),
names.agent = c("age1", "age2", "age3"),
numeraire = "lab",
policy = function(time, state) {
# Assume that unsold security will be void.
last.Demand <- state$last.A %*% dg(state$last.z)
secy.holding <- prop.table(last.Demand[2, ])
if (time > 1) {
state$S[2, 2:3] <- secy.holding[1:2]
}
state
}
)
ge$p
ge$S
ge$D
## Assume that the unsold security of age3 will be void.
## The calculation results are the same as above.
ge <- sdm2(
A = list(dst.age1, dst.age2, dst.age3),
B = matrix(0, 2, 3),
S0Exg = matrix(c(
1 + GRExg, 1, 0,
0, 0.5, 0.5
), 2, 3, TRUE),
names.commodity = c("lab", "secy"),
names.agent = c("age1", "age2", "age3"),
numeraire = "lab",
policy = function(time, state, state.history) {
secy.unsold <- state.history$S[2, , time - 1] * (1 - state.history$q[time - 1, 2])
last.Demand <- state$last.A %*% dg(state$last.z)
secy.purchased <- last.Demand[2, ]
if (time > 1) {
# Assume that the unsold security of age3 will be void.
state$S[2, 2:3] <- prop.table(secy.purchased[1:2] + secy.unsold[1:2])
}
state
},
maxIteration = 1
)
ge$p
ge$S
ge$D
# }
Run the code above in your browser using DataLab