-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR reworks the chainsync data to dashboard pipeline to move computation away from the dashboard and into a separate process. Major Changes: - New `run_data_analysis.py` process to run analysis after `acquire_data` that focuses on computation. - This stage currently computes spot price, fixed rate, base buffer, wallet positions, pnl, and the ticker. - Adding new tables (and interface) to support output of data analysis. - Simplifying dashboard frontend to query output of data analysis. Minor Changes: - Adding drop argument to sqlalchemy `initialize_session` to drop existing tables if set to True for debugging. - Adding in create table retries due to race condition between acquire data and data analysis both trying to create tables. - Removing obsolete agent positions data class. - Renames WalletInfo schema to be WalletInfoFromChain. - Removing chainsync scripts for calculating leaderboards from previous trading competition. - Renaming table names to be snake case. - Adding in a rerun of bots + acquire data + data analysis in system test to test data pipeline restarts. - Splitting out system tests to different files. Breaking Change: - postgres db interface getter functions no longer return blockNumber as an index. This is to keep the getter functions consistent, as not every table stores the block number. Bug Fixes: - `smart_contract_preview_transaction` now takes in a block number argument to query the mock trade at that exact block. This helps solve a race condition where the preview could be mocking a position that's no longer there. TODO: - More plots in dashboard.
- Loading branch information
Showing
36 changed files
with
1,186 additions
and
1,011 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
"""Script to format on-chain hyperdrive pool, config, and transaction data post-processing.""" | ||
from __future__ import annotations | ||
|
||
from chainsync.exec import data_analysis | ||
from elfpy.utils import logs as log_utils | ||
|
||
if __name__ == "__main__": | ||
log_utils.setup_logging(".logging/data_analysis.log", log_stdout=True) | ||
data_analysis() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
"""Analysis for trading.""" | ||
from .calc_fixed_rate import calc_fixed_rate | ||
from .calc_ohlcv import calc_ohlcv | ||
from .calc_pnl import calc_closeout_pnl, calc_single_closeout, calc_total_returns | ||
from .calc_spot_price import calculate_spot_price, calculate_spot_price_for_position | ||
from .calc_pnl import calc_closeout_pnl, calc_single_closeout | ||
from .calc_spot_price import calc_spot_price, calculate_spot_price_for_position | ||
from .calc_ticker import calc_ticker | ||
from .data_to_analysis import data_to_analysis |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
"""Calculates the amount of base set aside that can't be withdrawn""" | ||
from decimal import Decimal | ||
|
||
import pandas as pd | ||
|
||
|
||
def calc_base_buffer( | ||
longs_outstanding: pd.Series, share_price: pd.Series, minimum_share_reserves: Decimal | ||
) -> pd.Series: | ||
"""Calculates the amount of base set aside that can't be withdrawn | ||
Arguments | ||
--------- | ||
longs_outstanding: pd.Series | ||
The number of longs outstanding from the pool info | ||
share_price: pd.Series | ||
The share price from the pool info | ||
minimum_share_reserves: Decimal | ||
The minimum share reserves from the pool config | ||
""" | ||
# Pandas is smart enough to be able to broadcast with internal Decimal types at runtime | ||
return longs_outstanding / share_price + minimum_share_reserves # type: ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,13 @@ | ||
"""Calculate the fixed interest rate.""" | ||
from decimal import Decimal | ||
|
||
import numpy as np | ||
import pandas as pd | ||
|
||
from .calc_spot_price import calculate_spot_price | ||
|
||
|
||
def calc_fixed_rate(trade_data, config_data): | ||
def calc_fixed_rate(spot_price: pd.Series, position_duration: Decimal): | ||
"""Calculates the fixed rate given trade data.""" | ||
trade_data["rate"] = np.nan | ||
annualized_time = config_data["positionDuration"] / Decimal(60 * 60 * 24 * 365) | ||
spot_price = calculate_spot_price( | ||
trade_data["share_reserves"], | ||
trade_data["bond_reserves"], | ||
config_data["initialSharePrice"], | ||
config_data["invTimeStretch"], | ||
) | ||
fixed_rate = (Decimal(1) - spot_price) / (spot_price * annualized_time) | ||
x_data = trade_data["timestamp"] | ||
y_data = fixed_rate | ||
return (x_data, y_data) | ||
# Position duration (in seconds) in terms of fraction of year | ||
annualized_time = position_duration / Decimal(60 * 60 * 24 * 365) | ||
# Pandas is smart enough to be able to broadcast with internal Decimal types at runtime | ||
fixed_rate = (1 - spot_price) / (spot_price * annualized_time) # type: ignore | ||
return fixed_rate |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
f11ad66
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
elf-simulations – ./
elf-simulations-delvtech.vercel.app
elf-simulations.vercel.app
elf-simulations-git-main-delvtech.vercel.app
elfpy.element.fi
elfpy.delv.tech