inst/doc/dtd.R

### R code from vignette source 'dtd.Rnw'

###################################################
### code chunk number 1: dtd.Rnw:207-209
###################################################
library(ifrogs)
str(dtd)


###################################################
### code chunk number 2: dtd.Rnw:239-240
###################################################
dtd(mcap=10000, debt=5000, vol=0.4, r=0.1)


###################################################
### code chunk number 3: dtd.Rnw:252-254
###################################################
data(dtd_reliance)
head(dtd_reliance)


###################################################
### code chunk number 4: dtd.Rnw:260-266
###################################################
ans <- apply(X=dtd_reliance[ , -1], MARGIN=1,
                     FUN=function (i) dtd(mcap=i[["E"]],
                       vol=i[["sE"]], debt=i[["F"]], r=0.05))

ans <- data.frame(date=dtd_reliance[ , "date"], t(ans))
head(ans)


###################################################
### code chunk number 5: dtd.Rnw:275-276
###################################################
plot(ans[,"date"], ans[,"dtd.v"], ylab="DtD", xlab="", type="l")


###################################################
### code chunk number 6: dtd.Rnw:295-311
###################################################
# Simulation
compute_time <- system.time(simulate <- lapply(1:1000, function(i){ 
  set.seed(i)
  E <- rnorm(1, mean=56700, sd=200)
  F <- rnorm(1, mean=25000, sd=400)
  sE = rnorm(1, mean=0.25, sd=0.02)
  ans <- dtd(mcap=E, vol=sE,
             debt=F,  r=0.05)
  simulate_dtd <- ans["dtd.v"]
  simulate_v <- ans["asset.v"]
  simulate_sv <-ans["sigma.v"]
  return(c(E=E, sE=sE, F=F, simulate_dtd, simulate_v,
           simulate_sv))
}))
simulate_results <- do.call(rbind, simulate)
head(simulate_results)


###################################################
### code chunk number 7: dtd.Rnw:318-328
###################################################
library(fOptions)
Estimated.E <- GBSOption("c", S=simulate_results[,"asset.v"],
                         X=simulate_results[,"F"],
                         Time=1, r=0.05, b=0.05,
                         sigma=
                         simulate_results[,"sigma.v"])
compare_results <- data.frame(simulate_results,
                              Estimated.E=Estimated.E@price)
head(compare_results)
all.equal(compare_results$E, compare_results$Estimated.E)


###################################################
### code chunk number 8: dtd.Rnw:343-344
###################################################
compute_time

Try the ifrogs package in your browser

Any scripts or data that you put into this service are public.

ifrogs documentation built on May 31, 2017, 2:27 a.m.