diff --git a/vega_query/service/utils/party.py b/vega_query/service/utils/party.py index f1bb3d552..3db825148 100644 --- a/vega_query/service/utils/party.py +++ b/vega_query/service/utils/party.py @@ -60,6 +60,7 @@ def historic_balances( self, party_id: str, asset_id: str, + asset_decimals: int, market_id: Optional[str] = None, account_types: Optional[List[protos.vega.vega.AccountType.Value]] = None, date_range_start_timestamp: Optional[int] = None, @@ -102,4 +103,6 @@ def historic_balances( df = pd.DataFrame.from_dict(data, orient="index").sort_index().ffill() df["total"] = df.sum(axis=1) + df["total"] = df["total"]* 10**-asset_decimals return df + diff --git a/vega_query/visualisations/plots/amm.py b/vega_query/visualisations/plots/amm.py index 4fdddd5f4..506f03d6c 100644 --- a/vega_query/visualisations/plots/amm.py +++ b/vega_query/visualisations/plots/amm.py @@ -69,7 +69,7 @@ def create( party_colors = __party_colors(party_ids) - fig = plt.figure(figsize=(15, 8)) + fig = plt.figure(figsize=(16, 9)) gs = fig.add_gridspec(2, 2) ymin = ymax = 0 axes: List[Axes] = [] @@ -78,13 +78,15 @@ def create( axn0r: Axes = axn0l.twinx() if market_data_history is not None: overlay_mark_price(axn0l, market_data_history, market.decimal_places) + overlay_last_traded_price(axn0l, market_data_history, market.decimal_places) overlay_trading_mode(axn0r, market_data_history) # overlay_auction_starts(axn0r, market_data_history) # overlay_auction_ends(axn0r, market_data_history) axn0l.set_ylabel("USDT") axn0l.set_title( - "Market Price: Ornstein–Uhlenbeck ($\\theta=0.01$, $\\sigma=0.5$)", + # "Market Price: Ornstein–Uhlenbeck ($\\theta=0.01$, $\\sigma=0.5$)", + "Market Price: Ornstein–Uhlenbeck", loc="left", ) @@ -106,7 +108,7 @@ def create( axes.append(ax11) ax21 = fig.add_subplot(gs[1, 1]) ax21.set_title("AMM: Aggregated Account Balances [USDT]", loc="left") - ax21.set_ylabel("$\\Delta$ USDT") + ax21.set_ylabel("USDT") ax21.sharex(axn0l) axes.append(ax21) @@ -141,7 +143,8 @@ def create( party_id=amm_party_id, size_decimals=market.position_decimal_places, ) - ax11.get_lines()[-1].set_label(amm_party_id[:7]) + # ax11.get_lines()[-1].set_label(amm_party_id[:7]) + ax11.get_lines()[-1].set_label("AMM") # Reconstruct the AMMs aggregated balance from balance changes df = service.utils.party.historic_balances( @@ -149,8 +152,9 @@ def create( asset_id=asset.id, date_range_start_timestamp=start_timestamp, date_range_end_timestamp=end_timestamp, + asset_decimals=asset.details.decimals, ) - ax21.step(df.index, df.total, where="post", label="total") + ax21.step(df.index, df.total, where="post", label="AMM portfolio") ax11.legend() ax21.legend() diff --git a/vega_sim/scenario/amm/registry.py b/vega_sim/scenario/amm/registry.py index 14fb30436..fb043d933 100644 --- a/vega_sim/scenario/amm/registry.py +++ b/vega_sim/scenario/amm/registry.py @@ -10,11 +10,12 @@ benchmark_configs=[ BenchmarkConfig( market_config=configs.mainnet.BTCUSDT.CONFIG, - initial_price=70000, - annualised_volatility=0.5, - notional_trade_volume=100, - process_theta=0.01, - process_drift=-10, + initial_price=60000, + annualised_volatility=0.28, + notional_trade_volume=10, + process_theta=0.0001, + process_drift=-5, + risky_trader_funds=1, ), ], amm_liquidity_fee=0.0001, diff --git a/vega_sim/scenario/amm/scenario.py b/vega_sim/scenario/amm/scenario.py index 4f8925a6f..d6bc945ac 100644 --- a/vega_sim/scenario/amm/scenario.py +++ b/vega_sim/scenario/amm/scenario.py @@ -59,6 +59,22 @@ def configure_agents( # Set commitment amount to 0 to avoid benchmark market maker from # providing liquidity, they should only supply volume through orders. agent.fee_amount = self.amm_liquidity_fee + agent.commitment_amount = 0.000001 + agent.supplied_amount = 0 + + # if isinstance(agent, MarketOrderTrader): + # # Set commitment amount to 0 to avoid benchmark market maker from + # # providing liquidity, they should only supply volume through orders. + # agent.fee_amount = self.amm_liquidity_fee + # agent.commitment_amount =10 + # agent.supplied_amount = 50 + + # if isinstance(agent, LimitOrderTrader): + # # Set commitment amount to 0 to avoid benchmark market maker from + # # providing liquidity, they should only supply volume through orders. + # agent.spread = 0 + # agent.mean = -7.5 + # agent.sigma = 0.3 # For each market, add an AMM agent. for benchmark_config in self.benchmark_configs: @@ -83,34 +99,6 @@ def configure_agents( ) ) - for i_agent, benchmark_config in enumerate(self.benchmark_configs): - extra_agents.append( - MarketOrderTrader( - wallet_name="MarketOrderTrader", - key_name=f"MarketOrderTrader_{benchmark_config.market_config.instrument.code}_{str(i_agent).zfill(3)}", - market_name=benchmark_config.market_config.instrument.name, - initial_asset_mint=1e6, - buy_intensity=1.0, # Set buy intensity for the trader - sell_intensity=1.0, # Set sell intensity for the trader - base_order_size=1.0, # Set base order size for market orders - tag=f"MarketOrderTrader_{benchmark_config.market_config.instrument.code}_{str(i_agent).zfill(3)}", - random_state=self.random_state, - ) - ) - - extra_agents.append( - LimitOrderTrader( - wallet_name="LimitOrderTrader", - key_name=f"LimitOrderTrader_{benchmark_config.market_config.instrument.code}_{str(i_agent).zfill(3)}", - market_name=benchmark_config.market_config.instrument.name, - initial_asset_mint=1e6, - buy_intensity=1.0, # Set buy intensity for the trader - sell_intensity=1.0, # Set sell intensity for the trader - tag=f"LimitOrderTrader_{benchmark_config.market_config.instrument.code}_{str(i_agent).zfill(3)}", - random_state=self.random_state, - ) - ) - extra_agents = {agent.name(): agent for agent in extra_agents} agents.update(extra_agents) return agents diff --git a/vega_sim/scenario/benchmark/scenario.py b/vega_sim/scenario/benchmark/scenario.py index ffb33c6c3..bc97d2c06 100644 --- a/vega_sim/scenario/benchmark/scenario.py +++ b/vega_sim/scenario/benchmark/scenario.py @@ -154,8 +154,7 @@ def configure_agents( buy_intensity=100, sell_intensity=100, base_order_size=benchmark_config.notional_trade_volume - / benchmark_config.initial_price - / 100, + / (benchmark_config.initial_price*100), step_bias=1, initial_asset_mint=1e8, tag=f"{benchmark_config.market_config.instrument.code}_{str(i_agent).zfill(3)}", @@ -171,11 +170,9 @@ def configure_agents( market_name=market_name, time_in_force_opts={"TIME_IN_FORCE_GTT": 1}, buy_volume=benchmark_config.notional_trade_volume - / benchmark_config.initial_price - / 100, + / (benchmark_config.initial_price*100), sell_volume=benchmark_config.notional_trade_volume - / benchmark_config.initial_price - / 100, + / (benchmark_config.initial_price*100), buy_intensity=100, sell_intensity=100, submit_bias=1,