# \donttest{
#### an example with a Cobb-Douglas intertemporal utility function
np <- 5 # the number of internal periods
y1 <- 150
S <- matrix(NA, 2 * np - 1, np)
S[(np + 1):(2 * np - 1), np] <- 100
S[1, np] <- y1
B <- matrix(0, 2 * np - 1, np)
B[2:np, 1:(np - 1)] <- diag(np - 1)
dstl.firm <- list()
for (k in 1:(np - 1)) {
dstl.firm[[k]] <- node_new(
"prod",
type = "CD",
alpha = 2, beta = c(0.5, 0.5),
paste0("prod", k), paste0("lab", k)
)
}
dst.consumer.CD <- node_new(
"util",
type = "CD",
alpha = 1, beta = prop.table(rep(1, np)),
paste0("prod", 1:np)
)
f <- function(dstl) {
sdm2(
A = dstl,
B = B,
S0Exg = S,
names.commodity = c(paste0("prod", 1:np), paste0("lab", 1:(np - 1))),
names.agent = c(paste0("firm", 1:(np - 1)), "consumer"),
numeraire = "prod1",
ts = TRUE
)
}
ge <- f(c(dstl.firm, dst.consumer.CD))
ge$p
ge$z
ge$D
ge$S
ge$DV
ge$SV
## an example with a Leontief intertemporal utility function
dst.consumer.Leontief <- node_new(
"util",
type = "Leontief",
a = rep(1, np),
paste0("prod", 1:np)
)
ge2 <- f(c(dstl.firm, dst.consumer.Leontief))
ge2$p
ge2$z
ge2$D
ge2$S
ge2$DV
ge2$SV
# }
Run the code above in your browser using DataLab