# \donttest{
#### the basic overlapping generations (inefficient) exchange model
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"
)
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("payoff1", "payoff2"),
names.agent = c("age1", "age2"),
numeraire = "payoff1",
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 # c(1, 3 / 2 + sqrt(13) / 2)
ge$S
ge$D
ge$DV
#### another calculation method for the first economy
n <- 18 # the number of agents. The number of payoff types is n+2.
payoff.age2 <- 1
payoff.age3 <- 1e-10
S <- diag(1, n + 2, n)
S <- S + rbind(0, diag(payoff.age2, n + 1, n)) + rbind(0, 0, diag(payoff.age3, n, n))
dstl <- list()
for (k in 1:n) {
dstl[[k]] <- node_new(
"util",
type = "CD", alpha = 1,
beta = c(1 / 3, 1 / 3, 1 / 3),
paste0("payoff", k), paste0("payoff", k + 1), paste0("payoff", k + 2)
)
}
ge <- sdm2(
A = dstl,
B = matrix(0, n + 2, n, TRUE),
S0Exg = S,
names.commodity = paste0("payoff", 1:(n + 2)),
numeraire = "payoff1"
)
growth_rate(ge$p) + 1 # 3 / 2 + sqrt(13) / 2
ge$D
# }
Run the code above in your browser using DataLab