Skip to content Skip to sidebar Skip to footer

Utilizing Monte Carlo To Predict Revenue In Python

I am trying to implement a Monte Carlo simulation into my python code that will help me determine the odds that we achieve various thresholds related to revenue targets. For exampl

Solution 1:

This solution is not very efficient as nothing is done in parallel but you can see clearly how the simulations are performed.

num_samples = 10000
revenue_2018 = []
revenue_2019 = []

filter_2018 = (df['Fiscal Year'] == 2018)
filter_2019 = (df['Fiscal Year'] == 2019)

for _ in range(num_samples):
    sample = df['Revenue'] * ( np.random.rand(20) < df['Odds'] )
    revenue_2018.append(sample.loc[filter_2018].sum())
    revenue_2019.append(sample.loc[filter_2019].sum())

# Plot simulation results.
n_bins = 10
plt.hist([revenue_2018, revenue_2019], bins=n_bins, label=["Revenue 2018", "Revenue 2019"])
plt.legend()
plt.title("{} simulations of yearly revenue".format(num_samples))

# Print statistics.
print("Mean for 2018 is {}. Standard Deviation is {}".format(np.mean(revenue_2018), np.std(revenue_2018)))
print("Mean for 2019 is {}. Standard Deviation is {}".format(np.mean(revenue_2019), np.std(revenue_2019)))

Post a Comment for "Utilizing Monte Carlo To Predict Revenue In Python"