dpsolve: General Discrete-Time Bellman Equation Solver

Description Usage Author(s) References Examples

View source: R/dpsolve.R

Description

DPSOLVE uses the method of collocation to solve finite- and infinite-horizon discrete-time stochastic dynamic optimization models with discrete, continuous, or mixed states and actions of arbitrary dimension. Usage of DPSOLVE is fully documented in the pdf file:

Usage

1
2
3
dpsolve(model, basis, guess = list(x = array(0, c(prod(basis@n), model@dx,
  model@ni, model@nj)), v = array(0, c(prod(basis@n), model@ni, model@nj))),
  options = new(Class = "dpsolve.options"))

Author(s)

Randall Romero-Aguilar, based on Miranda & Fackler's CompEcon toolbox

References

Miranda, Fackler 2002 Applied Computational Economics and Finance

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# dummy model for testing the library

require("CompEconR")

params <- list(r=0.02)


myfunc <- function(flag,s,x,i,j,e,params){
  R <- 1+params$r

  ns <- nrow(s)
  ds <- ncol(s)
  dx <- if(hasArg(x)) ncol(x)

  out <- switch(
    flag,
    f = list(
      f   =  log(s-x/R),
      fx  =  1/(x-R*s),
      fxx = array(-1/(x-R*s)^2,c(ns,dx,dx))
    ),
    g = list(
      g   = x,
      gx  = array(1,c(ns,ds,dx)),
      gxx = array(0,c(ns,ds,dx,dx))
    ),
    b = list(lower=matrix(0,ns),upper=R*s)
  )
  return(out)
}


# mymodel <- new("dynamic.model",
#                horizon=Inf,
#                func=myfunc,
#                discount=0.95,
#                params = params,
#                X=matrix(seq(0,8,by=0.1)))


mymodel <- new("dynamic.model",
               horizon=Inf,
               func=myfunc,
               discount=0.95,
               params = params
               )



mybasis <- fundefn(type='cheb',n=7,a=0.5,b=2)
#mybasis2 <- fundefn(type='cheb',n=c(4,5),a=c(-1,0),b=c(1,3))

myoptions <- new("dpsolve.options",algorithm="newton")
#myoptions <- new("dpsolve.options",algorithm="newton")


#myfunc(flag='b',s=mybasis@nodes,i=1,j=1,params=params)
solution <- dpsolve(model=mymodel,basis=as.ref(mybasis),options=myoptions)




#basis.getPhi(as.ref(mybasis),order=2)
#print(basis.getPhi(as.ref(mybasis),order=-2))

#sprintf('%10s %2d\n','hola',6)

randall-romero/CompEconR documentation built on May 26, 2019, 10:56 p.m.