Modeling Profits
In the previous exercise, you built a model of corn production. For a small farm, you typically have no control over the price or demand for corn. Suppose that price is normally distributed with mean 40 and standard deviation 10. You are given a function corn_demanded()
, which takes the price and determines the demand for corn. This is reasonable because demand is usually determined by the market and is not in your control.
In this exercise, you will work on a function to calculate the profit by pulling together all the other simulated variables. The only input to this function will be the fixed cost of production. Upon completion, you'll have a function that gives one simulated profit outcome for a given cost. This function can then be used for planning your costs.
This exercise is part of the course
Statistical Simulation in Python
Exercise instructions
- Model the
price
as a normal random variable with mean 40 and standard deviation 10. - Get the corn
supply
by calling the functioncorn_produced(rain, cost)
, which you designed in the previous exercise. - Call the
corn_demanded()
function with inputprice
to getdemand
. - Profit \(=\) quantity \(\times\) price \(-\) cost. If more corn is produced than demanded (
supply > demand
), then quantity sold will bedemand
, else it will besupply
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Function to calculate profits
def profits(cost):
rain = np.random.normal(50, 15)
price = np.random.____
supply = ____
demand = ____
equil_short = supply <= demand
if equil_short == True:
tmp = ____*price - cost
return tmp
else:
tmp2 = ____*price - cost
return tmp2
result = profits(cost)
print("Simulated profit = {}".format(result))