Q1
# Define n
n <- 1000
# Set seed
##set.seed(123)
# Empty data frame for 1000 simulated days
data <- data.frame(day = seq(1:n),
demand = sample(c(0, 1000, 2000, 3000, 4000, 5000, 6000), n, replace = TRUE, prob = c(0.02, 0.03, 0.05, 0.08, 0.33, 0.29, 0.2)),
quantity_gloucester = NA,
quantity_rockport = NA,
price_gloucester = 3.25,
price_rockport = NA,
cost = 10000, # Cost of daily operations
earnings_gloucester = NA,
earnings_rockport = NA)
# Simulate earnings for both locations
for (i in 1:n) {
# Simulate price in Rockport
suppressWarnings(data$price_rockport[i] <- rnorm(1, mean = 3.65, sd = 0.2))
# Calculate quantity sold based on demand for both locations
suppressWarnings(data$quantity_gloucester[i] <- pmin(data$demand[i], 3500))
suppressWarnings(data$quantity_rockport[i] <- pmin(data$demand[i], 3500))
# Calculate earnings for each location
suppressWarnings(data$earnings_gloucester[i] <- data$price_gloucester * data$quantity_gloucester[i] - data$cost)
suppressWarnings(data$earnings_rockport[i] <- data$price_rockport[i] * data$quantity_rockport[i] - data$cost)
}
# Calculate cumulative earnings for both locations
data$cumulative_earnings_gloucester <- cumsum(data$earnings_gloucester)
data$cumulative_earnings_rockport <- cumsum(data$earnings_rockport)
# Plot the simulated cumulative earnings for both locations
plot(data$day, data$cumulative_earnings_gloucester, type = 'l', xlab = 'Day', ylab = 'Cumulative Earnings', col = 'blue', main = 'Simulated Daily Earnings Over Time')
lines(data$day, data$cumulative_earnings_rockport, type = 'l', col = 'red')
legend('topright', legend = c('Gloucester', 'Rockport'), col = c('blue', 'red'), lty = 1)

# Create a data frame with days and earnings for each location
##earnings_table <- data.frame(
## Day = data$day,
## Earnings_Gloucester = data$cumulative_earnings_gloucester,
## Earnings_Rockport = data$cumulative_earnings_rockport
## )
# Display the table
##print(earnings_table)
Q2
# Calculate the probability that earnings are greater than 1375 in Gloucester
probability_greater_than_1375_gloucester <- mean(data$earnings_gloucester > 1375)
# Calculate the probability that earnings are greater than 1375 in Rockport
probability_greater_than_1375_rockport <- mean(data$earnings_rockport > 1375)
# Print the results
cat("Probability of earning more than $1375 in Gloucester:", probability_greater_than_1375_gloucester, "\n")
## Probability of earning more than $1375 in Gloucester: 0
cat("Probability of earning more than $1375 in Rockport:", probability_greater_than_1375_rockport, "\n")
## Probability of earning more than $1375 in Rockport: 0.826
Q3
# Calculate the probability that earnings are less than 0 in Gloucester
probability_less_than_0_gloucester <- mean(data$earnings_gloucester < 0)
# Calculate the probability that earnings are less than 0 in Rockport
probability_less_than_0_rockport <- mean(data$earnings_rockport < 0)
# Print the results
cat("Probability of earning less than $0 in Gloucester:", probability_less_than_0_gloucester, "\n")
## Probability of earning less than $0 in Gloucester: 0.173
cat("Probability of earning less than $0 in Rockport:", probability_less_than_0_rockport, "\n")
## Probability of earning less than $0 in Rockport: 0.098
Q4
# Calculate the expected value (mean) of F in Gloucester
expected_value_gloucester <- mean(data$earnings_gloucester)
# Calculate the expected value (mean) of F in Rockport
expected_value_rockport <- mean(data$earnings_rockport)
# Print the results
cat("Expected value (mean) of F in Gloucester:", expected_value_gloucester, "\n")
## Expected value (mean) of F in Gloucester: 593.375
cat("Expected value (mean) of F in Rockport:", expected_value_rockport, "\n")
## Expected value (mean) of F in Rockport: 1842.929
Q5
What is your advice to Mr. Conley? Write one paragraph in which you
argue a position. In your answer please incorporate the quantitative
details from your simulation, and consider in particular the trade-off
between risk and reward.
## My advice to Mr. Conley is to sell his fish in Rockport. It is evident from my particular simulation that Rockport has the highest potential for more sales and increase in expected returns. The graph, and answers from each question showing expected values are shocking from this simulation and show the potential reward of operating in this marketplace. Specifically, there's an 0.819 probability of making >1375 in Rockport, in addition to a smaller probability than Gloucester of making less than $0. We also found that the expected value of F (mean value) is substantially greater in Rockport. There is a significant risk, yet obvious payoff to selling all of his catch in Rockport. Due to the high standard deviation in price, these simulations are not to be as expected as the Gloucester projections. Those price points and projected earning are likely far more reliable because of the uncertainty that lies in Rockport's pricing. This risk-reward, however, is one that I believe Mr. Conley should take. There is far too much potential for a huge payoff, and even if the projections are not exactly accurate, the margin between the two locations is so great that it would need to be a massive decrease in the expected price of the catch at Rockport for the two values to even be similar.