Questions Week 12
Questions Week 12
Tutorial : 12
Topics : Simulation Analysis
1. [If-else statement]
(a) Suppose x=c(3,-1,5,-2,7,-2,-2,5,10). How can we use the if-else statement to instruct R to print
“the sample mean is positive” when the sample mean is indeed positive, and print “the
sample mean is non positive” otherwise?
(b) Simulate a continuous uniform RV from -0.1 to 1. Use an if-else statement to print “x is positive”
if it is true.
(c) Following (a), let Y=1 if sample mean of x > sample median of x ,and Y=0 otherwise.
2. If you invest in one portfolio and the annual return is estimated to follow the continuous
uniform distribution between -3% and 7%, which is realized at the beginning of each year. The
positive return, in the form of a dividend, will be reinvested.
(1) Assume you invest $1000 at the beginning of the first year. Can you simulate one single
instance of the value of the investment at the beginning of the 6th year? (set the seed as 200)
1
Nanyang Business School
(2) Building on (1), please simulate 100 instances of problem Q2(1). That is, we want to obtain
100 possible values of the investment at the beginning of the 6th year. What is the average
value of the investment, out of these 100 iterations? (set the seed as 200)
(3) Now suppose you invest $1000 at the beginning of each of the next five years. Can you
simulate one single instance of the value of the investment at the beginning of the 6th year?
(set the seed as 200)
(4) Now suppose you invest $1000, $2000, $3000, $4000, $5000, respectively at the beginning of
each of the next five years. Can you simulate one single instance of the investment value at
the beginning of the 6th year? (set the seed as 200)
(5) You invest $1000 at the beginning of the next five years. Now your bank gives you a new deal:
If the dividend for a year is positive, instead of reinvesting it, the dividend will be withdrawn
immediately and be used to purchase NTUC vouchers. Calculate the average value from 100
simulation runs of the total value of the investment, and the total value of the vouchers
obtained, at the beginning of 6th policy year? (set the seed as 200)
(6) Calculate a 95% confidence interval for the total voucher value of (5)
3. A juice stall in the canteen starts its business every morning with 50 litres of juice with no
possibility of replenishment during the day. The owner expects to sell X litres during every
business hour, where X follows a uniform distribution between 3 and 5. Suppose the store is
open for 10 hours per day.
(1) Evaluate the sample mean (in litres) of the unsold juice at the end of a business day based on
a sample size of 1000 (set the seed value as 200).
2
Nanyang Business School
(2) The owner adjusts his prediction of X to a normal distribution of mean 4.5 litres and standard
deviation of 1.5 litres. Estimate the number of days in which stall will “stockout” in 100
business days (set the seed value as 200). *Stock-out meaning “not enough stock to sell to
customers.”