Alberto Einstein, an analytics PhD student at Harrisburg University, has been having problems balancing his checkbook which creates some potential financial risks. His monthly income is derived from a graduate research grant; however, he also makes extra money in most months by tutoring undergraduates in their introductory math course. The probabilities of various income levels are shown below (assume that this income is received at the beginning of each month):
Monthly income 850 900 950 1000
Probability 0.35 0.27 0.22 0.16
Einstein has expenditures that vary from month to month, and he estimates that they will follow this distribution:
Monthly expense 800 900 1000 1100
Probability 0.05 0.23 0.42 0.3
Alberto begins his final year with 1,650 dollars in his checking account. Simulate the cash flow for 12 months and replicate your model N times to identify Einstein’s
#income
mincome <- c(850,900,950,1000)
prob <- c(0.35, 0.27 , 0.22, 0.16)
eincome= data.frame(mincome,prob)
eincome$ulc <- cumsum(eincome[,2])
eincome$llc <- eincome$ulc-eincome$prob
eincome## mincome prob ulc llc
## 1 850 0.35 0.35 0.00
## 2 900 0.27 0.62 0.35
## 3 950 0.22 0.84 0.62
## 4 1000 0.16 1.00 0.84
#expense
mex <- c(800,900,1000,1100)
prob <- c(0.05, 0.23 , 0.42, 0.3)
eex= data.frame(mex,prob)
eex$ulc <- cumsum(eex[,2])
eex$llc <- eex$ulc-eex$prob
eex## mex prob ulc llc
## 1 800 0.05 0.05 0.00
## 2 900 0.23 0.28 0.05
## 3 1000 0.42 0.70 0.28
## 4 1100 0.30 1.00 0.70
#simulate income & expense for 12 month
set.seed(666)
rand <- runif(600)
eincome1 = data.frame(rand)
eincome1$num <- ifelse(eincome1$rand < 0.35 , 850,
ifelse(eincome1$rand <0.62 & eincome1$rand >=0.35, 900, ifelse(eincome1$rand <0.84 & eincome1$rand >=0.62, 950, 1000)))
eincome1$num1 <- ifelse(eincome1$rand < 0.05 , 800,
ifelse(eincome1$rand <0.28 & eincome1$rand >=0.05, 900, ifelse(eincome1$rand <0.7 & eincome1$rand >=0.28, 1000, 1100)))
eincome1$n <-as.numeric(row.names(eincome1))
eincome1$sort <- ceiling(eincome1$n/12)
eincome1$balance <- eincome1$num- eincome1$num1
eincome2 <- group_by(eincome1, sort)
eincome3 <- summarise(eincome2, count=n(),
tbalance= sum(balance))
mean(eincome3$tbalance)## [1] -1074
we will use \[( 1- non-negative \; balance )= negative \; balance\]
probalitynegative <- 1- (0.35*0.05 +0.27*0.28 +0.22*0.28 +0.16*0.7)
probalitynegative ## [1] 0.7333
Lisa Simpson sells lemonades on Saturdays at Bart’s baseball games. Demand for the lemonades is distributed as shown in the following table: Monthly income 50 75 100 125 150 175
Probability 0.05 0.1 0.25 0.3 0.2 0.1
Lisa has decided to prepare 100 lemonades on Friday. Lisa pays 0.5 dollars for each lemonade made and sells each lemonade for 1.25. Unsold lemonades are sold at the end of the game for 0.75 dollars (assume they are all sold).
We use \[ (Demand-100) * (Lemon \; price(1.25) - production \; price(0.5)) + leftover* sale \; price(0.75) = Profit \]
then we acculumate the profit for 15 weekends and re-do the process 40 times to take the average of the seasonal profit, which is 1434 dollars.
#lemonade probability table
demand <- c(50, 75 , 100, 125 , 150, 175)
prob <- c(0.05, 0.1 , 0.25, 0.3 , 0.2 ,0.1)
lemon= data.frame(demand,prob)
lemon$ulc <- cumsum(lemon[,2])
lemon$llc <- lemon$ulc-lemon$prob
lemon## demand prob ulc llc
## 1 50 0.05 0.05 0.00
## 2 75 0.10 0.15 0.05
## 3 100 0.25 0.40 0.15
## 4 125 0.30 0.70 0.40
## 5 150 0.20 0.90 0.70
## 6 175 0.10 1.00 0.90
#simulation
set.seed(8)
randm <- runif(750)
lemon1 = data.frame(randm)
lemon1$num <- ifelse(lemon1$randm < 0.05 , 50,
ifelse(lemon1$randm <0.15 & lemon1$rand >=0.05, 75, ifelse(lemon1$randm <0.40 & lemon1$randm >=0.15, 100, ifelse(lemon1$randm <0.7 & lemon1$randm >=0.40, 125, ifelse(lemon1$randm <0.9 & lemon1$randm >=0.8,150, 175)))))
#leftover lemon
lemon1$left <- ifelse(100-lemon1$num> 0, 100-lemon1$num,0)
lemon1$n <-as.numeric(row.names(lemon1))
lemon1$sort <- ceiling(lemon1$n/15)
lemon1$profit<- lemon1$num*(1.25-0.5) + lemon1$left*0.75
lemon2 <- group_by(lemon1, sort)
lemon3 <- summarise(lemon2, count=n(),
tprofit= sum(profit))
mean(lemon3$tprofit)## [1] 1434
we recommend making 100 lemonade, because it will max our profit to be 102 dollars per day.
# investing 50
# we can sell 50 in all kinds of scenario
profit50 <- 50*(1.25-0.5)
profit50## [1] 37.5
# investing 100
profit100 <- 100*(0.85)*(1.25-0.05) + 50*0.15*0.05*0.75 + 25*0.15*0.1*0.75
profit100## [1] 102.5625
# investing 150
profit150 <- 150*(0.3)*(1.25-0.05) + 100*0.7*0.05*0.75 + 75*0.7*0.1*0.75 + 50*0.7*0.3*0.75+25*0.7*0.2*0.75
profit150## [1] 71.0625
# investing 175
profit175 <- 175*(0.1)*(1.25-0.05) + 125*0.9*0.05*0.75 + 100*0.9*0.1*0.75 + 75*0.9*0.25*0.75+50*0.9*0.3*0.75+25*0.9*0.2*0.75
profit175## [1] 58.125