动态优化

时间:2018-09-23 01:20:29

标签: optimization dynamic utility economics consumption

我正在尝试设定一个问题,该问题会随着财富(x t + 1 -x t < / sub> = -c t ),其中x 0 = 1000。我试图解决它,但无法在初始参数处评估功能。另外,最终条件是:x 10 > = 0和u 10 > =0。这是我正在使用的代码:

library('optimx')

# Parameters
t <- seq(0,10) # time
desc <- 0.1 # tax
beta <- 1/(1+desc) # parameter of function
alpha <- 0.8 # function
xo = 1000 # wealth in t=0

# Variables
x <- rep(xo, length(t)) # wealth in time

# Function
utilidade_total <- function(u, npar=TRUE, print=TRUE){
  for (i in lenght(t)){
    obj[i]=(beta^i)*(u[i]^alpha)
    x[i]=x[i-1]-u[i-1]
  }
  result <- sum(obj)
  return(result)
}

maxuti <- optimx(par=u,fn= utilidade_total,
                 control = list(maximize=TRUE))

umax <- coef(maxuti)

for (i in 2:lenght(t)){
   print(obj[i]=(beta^i)*(u^alpha))
    print(stock[i]=x[i-1]-umax[i-1])
}

# Result
for (i in 2:lenght(t)){
  obj[i]=(beta^i)*(u^alpha)
  x[i]=x[i-1]-u[i-1]
}

plot(t, x, type='b')
plot(t, u, type='b')

0 个答案:

没有答案