## ----setup, include = FALSE---------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(capn)

## ----example------------------------------------------------------------------
## Example (industrial classite 3) from Hashida and Fenichel (2022)
data("forest")

param   <- forest$param
simData <- forest$simData

Aspace <- aproxdef(param$order,param$lowerK,param$upperK,param$delta)

vCsplit <- vaprox.split(Aspace, simData$vol, simData$growth, 
                        simData$profit, param$crit.vol, 
                        param$margp, param$splittime)

vsimsplit <- vsim(vCsplit, simData[,1])

## harvest node and its time
hnode <- min(which(simData$vol > param$crit.vol)) 
m <- hnode -1

## plot data generation
plotdata <- data.frame(stock = vsimsplit$stock[1:m],
            price = exp(-(simData$times[1:m]-simData$times[1])*param$delta)*vsimsplit$shadowp[1:m],
            vfun = exp(-(simData$times[1:m]-simData$times[1])*param$delta)*vsimsplit$vfun[1:m])

## plot shadow (accounting) prices
## 3p of Figure 4 in Hashida and Fenichel (2022)
plot(plotdata$stock,plotdata$price,type='l',col='blue',
     xlab = 'Forest Volume (MBF)',
     ylab = 'Shadow Price ($/MBF)')

## plot value function
plot(plotdata$stock,plotdata$vfun,type='l',
     xlab = 'Forest Volume (MBF)',
     ylab = 'Value Function ($)')

