Activity: Static Simulation
Monte Carlo Methods Activities
We write this program together: the instructor types the code, and you type along. Before each run, write down a prediction; then run and check it.
The question. A company is considering an item for sale. A year’s profit is
\[\text{profit} = (\text{unit price} - \text{unit cost}) \times (\text{quantity sold}) - \text{fixed cost}.\]
The quantity sold in a year, in thousands of units, has a geometric distribution on \(\{0, 1, 2, \ldots\}\) with a mean of 4 (4000 units).
The suppliers are unreliable, so the unit cost varies:
Unit cost $80 $90 $100 $110 Probability 0.20 0.40 0.30 0.10 The fixed cost is \(Y = 65000 + 10000X\), where \(X\) has a triangular distribution with minimum \(-1\), mode 0, and maximum 1.
Find the smallest unit price for which the probability that the profit exceeds $150,000 is at least 0.75. At that price, how many years must we simulate to estimate the expected profit within ±$6,000 with 95% confidence? Start at a unit price of $200 with 1000 simulated years. Use stream 1 for the quantity sold, stream 2 for the unit cost, and stream 3 for the fixed cost.
Setup. Get the starter file ProfitSimulation.kt from the code/ folder beside this activity. Put it in src/main/kotlin/student/activities in your KSL project, the package the file declares; create the folder if you do not have it. Run its main. It compiles and runs, but the statistics are NaN: the function marked TODO is what we write.
1. Model the inputs
The KSL’s
GeometricRV(probOfSuccess)counts the failures before the first success, on \(\{0, 1, 2, \ldots\}\), with mean \((1 - p)/p\). What value of \(p\) gives a mean of 4?The KSL’s
DEmpiricalRV(values, cdf)takes the cumulative probabilities. What arrays do we pass for the unit cost?What is the range of the fixed cost? Its mean?
Write the pseudo-code for one simulated year, and for the experiment at one price.
2. Predict
Compute the expected profit at a unit price of $200. (The quantity sold, the unit cost, and the fixed cost are independent.)
What is the probability that the company sells nothing in a year? What does that say about how large the probability of a profit above $150,000 can ever be, at any price?
3. One price
We write simulateProfit (TODO) together.
Run at $200. Does the 95% confidence interval for the expected profit contain your answer to 2a?
Is $200 high enough? Is the probability’s half-width small enough to be sure?
The program also prints the number of years needed for a half-width of ±$6,000 at this price. Why is it so large, compared with the 1000 we ran?
4. Search the prices
simulateProfitcreates new random variables on streams 1, 2, and 3 for each price. Predict: does each price then see the same 1000 years, or new ones? Why does it matter when we compare prices?Change
lastPriceto 340 and run, $5 apart. What is the smallest price with a probability of at least 0.75?Between $225 and $285 the probability hardly changes. Why? (Think about the years with a quantity sold of 1 and of 2 thousand.)
The half-width on each probability is about 0.027. Is your answer to 4b the true smallest price? How could you be more certain?
At your price, how many years are needed for ±$6,000? Run with that many years at the prices near your answer. Does the answer to 4b change?