Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- from scipy.optimize import linear_sum_assignment
- def maximize_profit(buy_prices, sell_prices):
- diff = np.triu(m=(-buy_prices[:, None] + sell_prices[None, :]), k=0)
- diff[diff < 0] = 0
- with np.printoptions(precision=2, suppress=True, linewidth=256):
- print(diff)
- row_idx, col_idx = linear_sum_assignment(-diff)
- print(f"Rows: {row_idx}")
- print(f"Cols: {col_idx}")
- profits = diff[row_idx, col_idx]
- return profits.sum()
- if __name__ == "__main__":
- import pandas as pd
- df = pd.read_excel(io="data.xlsx", header=0)
- b_prices = df["2024 FCR-N Down"].to_numpy()
- s_prices = df["2024 FCR-N Up"].to_numpy()
- print(f"Profit: {maximize_profit(b_prices, s_prices)}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement