financial data 课本上的一道题目,参考答案给出的code有几条看不懂,也不太确定解题思路…
用R解Binomial二项式分布问题
题目:Assume that McDonald's log returns are normally distributed with mean and standard deviation equal to their estimates and that you have been made the following proposition by a friend: If at any point within the next 20 trading days, the price of McDonald's falls below 85 dollars, you will be paid $100, but if it does not, you have to pay him $1. The current price of McDonald's is at the end of the sample data, $93.07. Are you willing to make the bet? (Use 10,000 iterations in your simulation and use the command set.seed(2015) to ensure your results are the same as the answer key)
参考解答给出的code是:
> niter = 10000
> value = matrix(niter)
> set.seed(2015)
> for (i in 1:niter)
+ {
+ logR = rnorm(20,mean = mean(logReturn),sd = sd(logReturn))
+ prices = 93.07 * exp(cumsum(logR))
+ ind = (min(prices) < 85)
+ value[i] = 100*ind - (1 - ind)
+ }
> mu = mean(value)
> mu
[1] 0.0605
> mu + c(-1,1)* sqrt(mu*(1-mu)/niter)*qnorm(0.975)
[1] 0.05583 0.06517
请问其中的prices = 93.07 * exp(cumsum(logR)), 这一步的含义是什么?(为什么用93.07*exp(cumsum(logR)?)
value[i]是在求期望值吗?
题目要求里的setseed.(2015)又是什么意思/作用?