All,
Below is an R-lab problem from Ch2 of Statistics and Data Analysis for
Financial Engineering (Ruppert, 2010). The R code runs okay but the answer
seems strange. Any hints much appreciated.
Cheers,
David
David Afshartous, Ph.D.
Research Associate Professor
PSTATĀ®: ASA Accredited Professional Statistician
Department of Biostatistics
Vanderbilt University Medical Center
## suppose Hedge fund owns $1,000,000 of stock and used $50,000 capital and
## $950,000 borrowed money for the purchase.
## Daily log returns on the stock have a mean of 0.05/year and SD of 0.23/year,
## which can be converted to per trading day by dividing by 253 and sqrt(253)
## the hedge fund will sell the stock for a profit of at least $100,000 if the
value
## of the stock rises to at least $1,100,000 at the end of one of the first 100
trading days,
## sell it for a loss if the value falls below $950,000 at the end of one of
the first
## 100 trading days, or sell after 100 trading days if the closing price has
stayed between
## $950,000 and $1,1000,000.
## PROBLEM 7: What is the expected return? When answering this question,
remember
## that only $50,000 was invested. Also, the units of return are time, e.g.,
## one can express a return as a daily return or a weekly return. Therefore,
## one must keep track of how long the hedge fund holds its position before
selling
The code below simulates whether value falls below 950,000, goes above
1,1000,000, or stays between. The amount lost/gained in the 1st/2nd scenario is
a constant, whereas the amount lost/gained in the third scenario is random.
### simulation code; written for readability as opposed to speed
niter = 10000 ## number of iterations
below = rep(0, niter) ## set up storage
above = rep(0, niter)
between = rep(0, niter)
between.ending.value = NULL
below.ending.day = NULL
above.ending.day = NULL
set.seed(2009)
for (i in 1:niter) {
r = rnorm(100, mean = .05/253, sd = .23/sqrt(253))
logPrice = log(1e6) + cumsum(r) ## 1e6 = initial price
minLogP = min(logPrice) ## min price over next 45 days
maxLogP = max(logPrice) ## min price over next 45 days
crossBelowLogP.day = ifelse( minLogP < log(950000), min(which(logPrice <
log(950000))), 101) ## 101 means doesn't cross
crossAboveLogP.day = ifelse( maxLogP > log(1100000), min(which(logPrice >
log(1100000))), 101)
if ( (minLogP >= log(950000)) & (maxLogP <= log(1100000)) ) { ## Neither
cross boundary
between[i] = 1
between.ending.value = append(between.ending.value, exp(logPrice[100]))
}
if ( (minLogP < log(950000)) & (maxLogP > log(1100000))) { ## Both cross
ifelse (crossBelowLogP.day < crossAboveLogP.day, below[i] <- 1,
above[i] <-1)
ifelse (crossBelowLogP.day < crossAboveLogP.day, below.ending.day
<- append(below.ending.day, crossBelowLogP.day),
above.ending.day <-
append(above.ending.day, crossAboveLogP.day))
}
if ( (minLogP < log(950000)) & (maxLogP <= log(1100000)) ) { ## Only
cross below
below[i] = 1
below.ending.day = append(below.ending.day, crossBelowLogP.day)
}
if ( (minLogP >= log(950000)) & (maxLogP > log(1100000)) ) { ## Only
cross above
above[i] = 1
above.ending.day = append(above.ending.day, crossAboveLogP.day)
}
}
mean(above) ## this will give the probability of the value crossing the above
threshold
When annualizing returns, the day in which a boundary needs to be accounted
for. The following code calculates the overall expected return by
conditioning on each scenario:
# cross above: always make constant 100,000 based on initial investment of
50,000
# P_t/P_t-1 = 100,000/50,000 = 2 = gross return --> net return = 2 - 1 = 1
ret.above = (1 + 1)^(365/(above.ending.day)) - 1 ### annualized
# cross below: always lose constant 50,000 based on initial investment of 50,000
# P_t/P_t-1 = 50,000/50,000 = 1 = gross return --> net return = 1 - 1 = 0
ret.below = 0
## betwen: final value depends on realized value on 100th day
# P_t/P_t-1 = between.ending.value/50,000 = --> net return = gross return - 1
net = ifelse(between.ending.value < 1000000,
(1000000 - between.ending.value)/50000 - 1, ## net return,
gain
(between.ending.value - 1000000)/50000 - 1) ## net
return, loss
ret.between = (1 + net)^(365/100) - 1
exp.return = mean(above)*mean(ret.above) + mean(below)*mean(ret.below) +
mean(between) * mean(ret.between)
8.669104e+50???
_______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should
go.