Skip to content

Commit

Permalink
feat: add convert to csv and random seed
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiajia-Cui committed Sep 30, 2024
1 parent 70013cd commit 8c9d763
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
10 changes: 8 additions & 2 deletions vega_query/visualisations/overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
7 changes: 4 additions & 3 deletions vega_query/visualisations/plots/amm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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()
Expand Down
6 changes: 4 additions & 2 deletions vega_sim/scenario/common/utils/price_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down

0 comments on commit 8c9d763

Please sign in to comment.