Untitled
unknown
plain_text
a year ago
2.0 kB
6
Indexable
import pandas as pd import numpy as np # Load data bidding_df = pd.read_csv('./players_L1.csv', index_col=0)[['Q_n', 'P_n']] bidding_df['P_n'] = bidding_df['P_n'] / 100 # Function to calculate market price for order book def get_orderbook_price(bids, asks): if not bids.empty and not asks.empty: highest_bid = bids['P_n'].iloc[0] lowest_ask = asks['P_n'].iloc[0] if highest_bid >= lowest_ask: return (highest_bid + lowest_ask) / 2 else: return lowest_ask # Return the highest bid when there's no overlap return None # Function to calculate market price using price function def get_function_price(bids, asks): Y = asks.Q_n.sum() X = np.sum((bids.Q_n.abs() * (bids.P_n))) x = Y/X return price_function_sigmoid(x, L=0.10, K=0.23, X_0=optimal_theta, B=optimal_B) # Original market prices bids = bidding_df[bidding_df['Q_n'] < 0].sort_values(by='P_n', ascending=False) asks = bidding_df[bidding_df['Q_n'] > 0].sort_values(by='P_n') bids['Q_n'] = bids['Q_n'].abs() original_orderbook_price = get_orderbook_price(bids, asks) original_function_price = get_function_price(bids, asks) # Introduce a market buy order (e.g., a buy order of volume 100 at a price 10% higher than the highest bid) market_buy_order_volume = 2 market_buy_order_price = 0.23 #bids['P_n'].iloc[0] * 1.5 new_bid = pd.DataFrame([{'Q_n': market_buy_order_volume, 'P_n': market_buy_order_price}]) bids = pd.concat([bids, new_bid], ignore_index=True) bids = bids.sort_values(by='P_n', ascending=False) # New market prices after introducing market buy order new_orderbook_price = get_orderbook_price(bids, asks) new_function_price = get_function_price(bids, asks) # Compare robustness orderbook_change = new_orderbook_price - original_orderbook_price function_change = new_function_price - original_function_price print("Change in Order Book Price:", orderbook_change) print("Change in Price Function Price:", function_change)
Editor is loading...