Spaces:
Sleeping
Sleeping
Download src/pricing/pricing.py from ServandoTorres/Relu: direct link, hf CLI and curl.
- Browser
- Download file 2.69 kB
-
https://huggingface.co/spaces/ServandoTorres/Relu/resolve/main/src/pricing/pricing.py
- Command line
-
hf download hf://spaces/ServandoTorres/Relu/src/pricing/pricing.py
-
curl -L -o pricing.py https://huggingface.co/spaces/ServandoTorres/Relu/resolve/main/src/pricing/pricing.py
2.69 kB
| import numpy as np | |
| # Define demand curve function | |
| def demand_curve(price, prices, predicted_sales): | |
| return np.interp(price, prices, predicted_sales) | |
| # Define profit function | |
| def profit(gmv0, r_lambda, E_r_lambda, c, P0): | |
| return np.sum(gmv0 * E_r_lambda * (r_lambda - c)) - P0 | |
| # Run the pricing algorithm to find the optimal value of 位 | |
| def pricing_algorithm(P0, demand_curve, prices, predicted_sales, c, initial_lambda=5, delta_lambda=4): | |
| # Step 0: Select an initial value of 位 = 5. Select fixed global stability parameter D_\lambda = 4. | |
| lambda_value = initial_lambda | |
| while True: | |
| # Calculate prices with lambda | |
| prices_with_lambda = prices * lambda_value | |
| # Step 2: For current 位 calculate prices, and find out what a | |
| gmv0 = demand_curve(P0, prices, predicted_sales) | |
| # Use demand_curve function to calculate E_r_lambda | |
| E_r_lambda = demand_curve(prices_with_lambda, prices, predicted_sales) | |
| r_lambda = E_r_lambda + (gmv0 - E_r_lambda) / (1 + np.exp((prices - prices_with_lambda) / c)) | |
| current_profit = profit(gmv0, r_lambda, E_r_lambda, c, P0) | |
| # Step 3: If \mathrm{Profit}(\lambda)< P_0, slightly increase 位. | |
| # If \mathrm{Profit}(\lambda)> P_0, slightly decrease 位. | |
| # Change in 位 in a week should be no more than D_\lambdapercent. | |
| if current_profit < 0: | |
| lambda_value += delta_lambda | |
| elif current_profit > 0: | |
| lambda_value -= delta_lambda | |
| else: | |
| break | |
| # Step 1: Select/update value of P0 according to business needs and strategy. | |
| # Go to Step 2. | |
| # Return the optimal value of 位 | |
| return lambda_value | |
| # Define grid search lambda function | |
| def grid_search_lambda(P0, demand_curve, prices, predicted_sales, c, lambda_min=3, lambda_max=10, lambda_step=1): | |
| # Step 0: Select initial 位 = 5. Select fixed global stability parameter D_\lambda = 4. | |
| lambda_values = range(lambda_min, lambda_max + 1, lambda_step) | |
| best_prices = [] | |
| for lambda_multiplier in lambda_values: | |
| # Step 2: For current 位 calculate prices, and find out what a \mathrm{Profit}(\lambda)is. | |
| lambda_value = pricing_algorithm(P0, demand_curve, prices, predicted_sales, c, lambda_multiplier) | |
| prices_with_lambda = prices * lambda_value | |
| profits = profit(demand_curve(P0, prices_with_lambda, predicted_sales), 1, 1, c, P0) | |
| best_price = prices_with_lambda[np.argmax(profits)] | |
| best_prices.append(best_price) | |
| # Step 1: Select/update value of P0 according to business needs and strategy. | |
| # Go to Step 2. | |
| # Return the best prices | |
| return best_prices | |