diff --git a/vega_query/service/utils/party.py b/vega_query/service/utils/party.py index ae56324db..b70be259c 100644 --- a/vega_query/service/utils/party.py +++ b/vega_query/service/utils/party.py @@ -8,6 +8,8 @@ import pandas as pd +from vega_query.utils import timestamp_to_datetime + logger = getLogger(__name__) @@ -42,7 +44,9 @@ def historic_positions( data = defaultdict(lambda: defaultdict(int)) for trade in trades: position_after_trade = positions.get(trade.market_id, 0) - data[trade.timestamp][trade.market_id] = position_after_trade + data[timestamp_to_datetime(trade.timestamp)][ + trade.market_id + ] = position_after_trade match party_id: case trade.buyer: positions[trade.market_id] -= trade.size @@ -92,7 +96,7 @@ def historic_balances( ) if aggregated_balance.market_id is not "": account_key += f" | {aggregated_balance.market_id[:7]}" - data[aggregated_balance.timestamp][account_key] = int( + data[timestamp_to_datetime(aggregated_balance.timestamp)][account_key] = int( aggregated_balance.balance ) diff --git a/vega_query/visualisations/plots/amm.py b/vega_query/visualisations/plots/amm.py index 05551b325..3c1511d22 100644 --- a/vega_query/visualisations/plots/amm.py +++ b/vega_query/visualisations/plots/amm.py @@ -65,13 +65,7 @@ def create( # Set unique colors for each party and request party specific information amms = service.api.data.list_amms(market_id=market.id) if party_ids is None: - # party_ids = __party_defaults_old(market_data_history=market_data_history) party_ids = __party_defaults(amms=amms) - # party_ids = __party_defaults(amms=amms) + __party_defaults_old( - # market_data_history=market_data_history - # ) - - print(party_ids) party_colors = __party_colors(party_ids) @@ -139,17 +133,13 @@ def create( ax11.get_lines()[-1].set_label(amm_party_id[:7]) # Reconstruct the AMMs aggregated balance from balance changes - aggregated_balances = service.api.data.list_balance_changes( - party_ids=[amm_party_id], + df = service.utils.party.historic_balances( + party_id=amm_party_id, + asset_id=asset.id, date_range_start_timestamp=start_timestamp, date_range_end_timestamp=end_timestamp, ) - overlay_aggregated_balances( - ax=ax21, - aggregated_balances=aggregated_balances, - asset_decimals=asset.details.decimals, - ) - ax21.get_lines()[-1].set_label(amm_party_id[:7]) + ax21.step(df.index, df.total, where="post", label="total") ax11.legend() ax21.legend() diff --git a/vega_sim/scenario/amm/registry.py b/vega_sim/scenario/amm/registry.py index df4a56d12..ba9d17598 100644 --- a/vega_sim/scenario/amm/registry.py +++ b/vega_sim/scenario/amm/registry.py @@ -11,16 +11,17 @@ BenchmarkConfig( market_config=configs.mainnet.BTCUSDT.CONFIG, initial_price=70000, - annualised_volatility=0.5, + annualised_volatility=1, notional_trade_volume=100, - process_theta=0.02, - process_drift=-0.1, + process_theta=0.05, + process_drift=-10, ), ], - amm_liquidity_fee=0.001, + amm_liquidity_fee=0.0001, amm_update_frequency=0, initial_network_parameters={ "validators.epoch.length": "1h", + "market.fee.factors.makerFee": "0", }, ), } diff --git a/vega_sim/scenario/amm/scenario.py b/vega_sim/scenario/amm/scenario.py index 76eea7b51..4b668ea46 100644 --- a/vega_sim/scenario/amm/scenario.py +++ b/vega_sim/scenario/amm/scenario.py @@ -67,13 +67,13 @@ def configure_agents( wallet_name="AutomatedMarketMaker", key_name=f"AutomatedMarketMaker_{benchmark_config.market_config.instrument.code}_{str(i_agent).zfill(3)}", market_name=benchmark_config.market_config.instrument.name, - initial_asset_mint=2e6, - commitment_amount=1e5, + initial_asset_mint=1e6, + commitment_amount=10_000, slippage_tolerance=0.05, proposed_fee=self.amm_liquidity_fee, price_process=iter(benchmark_config.price_process), - lower_bound_scaling=1 - 0.05, - upper_bound_scaling=1 + 0.05, + lower_bound_scaling=1 - 0.02, + upper_bound_scaling=1 + 0.02, leverage_at_lower_bound=20, leverage_at_upper_bound=20, update_bias=self.amm_update_frequency, diff --git a/vega_sim/scenario/benchmark/configs.py b/vega_sim/scenario/benchmark/configs.py index e5cc65581..6ee3329f4 100644 --- a/vega_sim/scenario/benchmark/configs.py +++ b/vega_sim/scenario/benchmark/configs.py @@ -9,7 +9,7 @@ def __init__( initial_price: float, annualised_volatility: float, notional_trade_volume: int, - risky_trader_funds: int = 100_000, + risky_trader_funds: int = 10_000, process_theta: float = 0, process_drift: float = 0, ): diff --git a/vega_sim/scenario/common/utils/price_process.py b/vega_sim/scenario/common/utils/price_process.py index b6ae763cc..39e72b29b 100644 --- a/vega_sim/scenario/common/utils/price_process.py +++ b/vega_sim/scenario/common/utils/price_process.py @@ -336,9 +336,8 @@ def ou_price_process(n, theta=0.15, mu=0.0, sigma=0.2, x0=1.0, drift=0.0): x[0] = x0 for t in range(1, n): dx = ( - theta * (mu - x[t - 1]) * dt + theta * ((mu + t * drift) - x[t - 1]) * dt + sigma * np.sqrt(dt) * np.random.normal() - + drift * dt ) x[t] = x[t - 1] + dx return x