diff --git a/vega_query/visualisations/overlay.py b/vega_query/visualisations/overlay.py index 9b299454..15c07a41 100644 --- a/vega_query/visualisations/overlay.py +++ b/vega_query/visualisations/overlay.py @@ -30,7 +30,7 @@ def overlay_mark_price( ax: Axes, market_data_history: List[protos.vega.vega.MarketData], price_decimals: int, -): +)-> pd.DataFrame: x = [] y = [] for market_data in market_data_history: @@ -39,13 +39,19 @@ def overlay_mark_price( y.append(price if price != 0 else np.nan) ax.step(x, y, label="mark_price", where="post") + # Create a DataFrame from the extracted data + df_mark_price = pd.DataFrame({'timestamp': x, 'last_traded_price': y}) + + # Return the DataFrame + return df_mark_price + def overlay_last_traded_price( ax: Axes, market_data_history: List[protos.vega.vega.MarketData], price_decimals: int, **kwargs, -): +) : x = [] y = [] for market_data in market_data_history: diff --git a/vega_query/visualisations/plots/amm.py b/vega_query/visualisations/plots/amm.py index 506f03d6..4301864e 100644 --- a/vega_query/visualisations/plots/amm.py +++ b/vega_query/visualisations/plots/amm.py @@ -77,11 +77,10 @@ def create( axn0l = fig.add_subplot(gs[0, 0]) axn0r: Axes = axn0l.twinx() if market_data_history is not None: - overlay_mark_price(axn0l, market_data_history, market.decimal_places) + df_markPrice=overlay_mark_price(axn0l, market_data_history, market.decimal_places) + df_markPrice.to_csv("mark_price_data.csv", index=False) 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( @@ -155,6 +154,8 @@ def create( asset_decimals=asset.details.decimals, ) ax21.step(df.index, df.total, where="post", label="AMM portfolio") + df.to_csv("AMM_Portfolio_data.csv", index=False) + ax11.legend() ax21.legend() diff --git a/vega_sim/scenario/common/utils/price_process.py b/vega_sim/scenario/common/utils/price_process.py index 39e72b29..aec39437 100644 --- a/vega_sim/scenario/common/utils/price_process.py +++ b/vega_sim/scenario/common/utils/price_process.py @@ -62,7 +62,7 @@ def random_walk( S = np.round(S, decimal_precision) # If random state is passed then error if it generates a negative price - # Otherwise retry with a new seed + # Otherwise retry with a new if trim_to_min is not None: S[S < trim_to_min] = trim_to_min @@ -315,7 +315,7 @@ def get_live_price( return _live_prices[feed_key] -def ou_price_process(n, theta=0.15, mu=0.0, sigma=0.2, x0=1.0, drift=0.0): +def ou_price_process(n, theta=0.15, mu=0.0, sigma=0.2, x0=1.0, drift=0.0, seed=42): """ Generates a mean-reverting price series using the Ornstein–Uhlenbeck process with an optional drift term. @@ -331,6 +331,8 @@ def ou_price_process(n, theta=0.15, mu=0.0, sigma=0.2, x0=1.0, drift=0.0): Returns: np.ndarray: Mean-reverting price series of length n. """ + if seed is not None: + np.random.seed(seed) # Set the random seed for reproducibility dt = 1.0 # Assuming a time step of 1 x = np.zeros(n) x[0] = x0