Last active
December 8, 2021 17:55
-
-
Save jdmoore7/43efddbde9a8cbd0495a019371daffca to your computer and use it in GitHub Desktop.
Revenue & Profit Posterior
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def rev_posterior(samples=100, size=len(X)): | |
for s in range(samples): | |
idx = random.choice(range(size)) | |
m = trace.get_values('m')[idx] | |
b = trace.get_values('b')[idx] | |
rev = X * np.exp(m*X +b) | |
plt.plot(X, rev) | |
return | |
# rev_posterior() | |
import numpy as np | |
@np.vectorize | |
def cost(X): | |
return 1.5*X + 50 | |
def prof_posterior(samples=100, size=len(X)): | |
prices = [] | |
profits = [] | |
for s in range(samples): | |
idx = random.choice(range(size)) | |
m = trace.get_values('m')[idx] | |
b = trace.get_values('b')[idx] | |
demand = np.exp(m*X +b) | |
rev = X * demand | |
prof = rev - cost(demand) | |
plt.plot(X, prof) | |
best_price = X[np.argmax(prof)] | |
best_prof = np.max(prof) | |
prices.append(best_price) | |
profits.append(best_prof) | |
return prices,profits | |
prices, profits = prof_posterior(samples=1000) | |
import seaborn as sns | |
sns.kdeplot(x=prices, y=profits, cmap='inferno', fill=True, thresh=0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment