# NOT RUN {
#### 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 constant saving rate (i.e. a log instantaneous utility
## function, a C-D type intertemporal utility function).
saving.rate <- 0.5
ratio.saving.consumption <- saving.rate / (1 - saving.rate)
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 = "lab"
)
ge$p
ge$D
ge$DV
ge$S
#### 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
R <- 1 + GRExg
dst.age1 <- node_new(
"util",
type = "FIN",
rate = {
saving.rate <- 1 / (1 + R + R^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 + R)
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
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab