Skip to content

Instantly share code, notes, and snippets.

@ikatsov
Last active February 13, 2020 04:16
Show Gist options
  • Select an option

  • Save ikatsov/91bccbb863e317d9990182a1ea70098b to your computer and use it in GitHub Desktop.

Select an option

Save ikatsov/91bccbb863e317d9990182a1ea70098b to your computer and use it in GitHub Desktop.
def find_optimal_price_t(p_baseline, price_grid, t): # evalutes all possible price schedules
p_grid = np.tile(p_baseline, (len(price_grid), 1)) # derived from the baseline by
p_grid[:, t] = price_grid # changing the price at time t
profit_grid = np.array([ profit_response(p) for p in p_grid ])
return price_grid[ np.argmax(profit_grid) ]
p_opt = np.repeat(price_opt_const, T) # start with the constant price schedule
for t in range(T): # and optimize one price at a time
price_t = find_optimal_price_t(p_opt, price_grid, t)
p_opt[t] = price_t
print(f'Achieved profit is {profit_response(p_opt)}')
plt.plot(range(len(p_opt)), p_opt, c='red')
#> Achieved profit is 2903637.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment