File size: 2,026 Bytes
e51ae04 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
import pandas as pd
from profitability import DATA_DIR, DEFAULT_MECH_FEE, summary_analyse
from tqdm import tqdm
def update_roi(row: pd.DataFrame) -> float:
new_value = row.net_earnings / (
row.collateral_amount
+ row.trade_fee_amount
+ row.num_mech_calls * DEFAULT_MECH_FEE
)
return new_value
def update_trade_nr_mech_calls(non_agents: bool = False):
try:
all_trades_df = pd.read_parquet(DATA_DIR / "all_trades_profitability.parquet")
tools = pd.read_parquet(DATA_DIR / "tools.parquet")
except Exception as e:
print(f"Error reading the profitability and tools parquet files")
traders = list(all_trades_df.trader_address.unique())
if non_agents:
traders = list(
all_trades_df.loc[
all_trades_df["staking"] == "non_agent"
].trader_address.unique()
)
print("before updating")
print(
all_trades_df.loc[
all_trades_df["staking"] == "non_agent"
].num_mech_calls.describe()
)
for trader in tqdm(traders, desc=f"Updating Traders mech calls", unit="traders"):
tools_usage = tools[tools["trader_address"] == trader]
if len(tools_usage) == 0:
tqdm.write(f"trader with no tools usage found {trader}")
all_trades_df.loc[
all_trades_df["trader_address"] == trader, "nr_mech_calls"
] = 0
# update roi
all_trades_df["roi"] = all_trades_df.apply(lambda x: update_roi(x), axis=1)
print("after updating")
print(
all_trades_df.loc[
all_trades_df["staking"] == "non_agent"
].num_mech_calls.describe()
)
# saving
all_trades_df.to_parquet(DATA_DIR / "all_trades_profitability.parquet", index=False)
print("Summarising trades...")
summary_df = summary_analyse(all_trades_df)
summary_df.to_parquet(DATA_DIR / "summary_profitability.parquet", index=False)
if __name__ == "__main__":
update_trade_nr_mech_calls(non_agents=True)
|