# \donttest{
#### the basic overlapping generations (inefficient) exchange model in sequential form.
dst.age1 <- node_new(
"util",
type = "CD", alpha = 1, beta = c(1 / 3, 2 / 3),
"payoff1", "payoff2"
)
dst.age2 <- node_new(
"util",
type = "CD", alpha = 1, beta = c(1 / 2, 1 / 2),
"payoff1", "payoff2"
)
policy.supply <- function(time, state) {
pension <- (state$last.A[, 2] * state$last.z[2])[2]
if (time > 1) state$S[1, 2] <- 50 - pension
state
}
ge <- sdm2(
A = list(dst.age1, dst.age2),
B = matrix(0, 2, 2),
S0Exg = matrix(c(
50, 50,
50, 0
), 2, 2, TRUE),
names.commodity = c("payoff1", "payoff2"),
names.agent = c("age1", "age2"),
numeraire = "payoff1",
policy = list(policy.supply, policyMarketClearingPrice),
maxIteration = 1,
numberOfPeriods = 20,
ts = TRUE
)
ge$p # c(1, 3 / 2 + sqrt(13) / 2)
ge$ts.p
ge$S
ge$D
ge$DV
#### the basic overlapping generations exchange model in timeline form.
m <- 15 # the number of generations
n <- m + 1 # the number of commodity kinds
names.commodity <- paste0("payoff", 1:n)
names.agent <- paste0("gen", 1:m)
# the exogenous supply matrix.
S0Exg <- matrix(NA, n, m, dimnames = list(names.commodity, names.agent))
for (k in 1:m) {
S0Exg[k:(k + 1), k] <- 50
}
dstl.consumer <- list()
for (k in 1:(m - 1)) {
dstl.consumer[[k]] <- node_new(
"util",
type = "CD", alpha = 1,
beta = rep(1 / 3, 3),
paste0("payoff", k:(k + 2))
)
}
dstl.consumer[[m]] <- node_new(
"util",
type = "CD", alpha = 1,
beta = c(0.5, 0.5),
paste0("payoff", m:(m + 1))
)
ge <- sdm2(
A = dstl.consumer,
B = matrix(0, n, m),
S0Exg = S0Exg,
names.commodity = names.commodity,
names.agent = names.agent,
numeraire = "payoff1"
)
round(addmargins(ge$D, 2), 2)
round(addmargins(ge$S, 2), 2)
growth_rate(ge$p) + 1 # 3 / 2 + sqrt(13) / 2
#### Assume that in the timeline model, each consumer lives for four periods or more.
nl <- 4 # the number of life periods
payoff <- c(rep(100 / (nl - 1), nl - 1), 1e-10) # the lifetime payoffs
m <- 20 # the number of generations
n <- m + nl - 1 # the number of commodity kinds
names.commodity <- paste0("payoff", 1:n)
names.agent <- paste0("gen", 1:m)
# the exogenous supply matrix.
S0Exg <- matrix(NA, n, m, dimnames = list(names.commodity, names.agent))
for (k in 1:m) {
S0Exg[k:(k + nl - 1), k] <- payoff
}
dstl.consumer <- list()
for (k in 1:m) {
dstl.consumer[[k]] <- node_new(
"util",
type = "CD", alpha = 1,
beta = rep(1 / nl, nl),
paste0("payoff", k:(k + nl - 1))
)
}
ge <- sdm2(
A = dstl.consumer,
B = matrix(0, n, m),
S0Exg = S0Exg,
names.commodity = names.commodity,
names.agent = names.agent,
numeraire = "payoff1"
)
round(addmargins(ge$D, 2), 2)
round(addmargins(ge$S, 2), 2)
growth_rate(ge$p) + 1
# }
Run the code above in your browser using DataLab