amberdata / amberdata-cefi-defi-arbitrage-strategy

26 stars 11 forks source link

Super jupyternb for backtesting! #2

Open unclecharliecrypto opened 2 years ago

unclecharliecrypto commented 2 years ago

Great visualization for potential arb opps.

(1) I have verified a total of 19 trades placed over 28 days where trades submitted on 9 days (syntax "Entry:TRUE")

(2) There were an additional 10 trades (syntax "Entry: FALSE") which occurred shortly after the above trades. The python code (drop duplicates) excludes these trades which is fine. However - if you check the pnl graphs both Entry TRUE & FALSE trades are being included. For example, pnl on 30May22 is $3.6k (TRUE) however the pnl chart is showing > $4k due to combining both TRUE&FALSE trades. Sharpe ratio impacted as well.

(3) The article mentions "holding period was no more than 5 minutes per trade". Unsure how to interpret this? Screenpic of 19 trade timestamps attached.

Screen Shot 2022-10-01 at 13 34 40

(4)May I confirm what are cex_price & dex_price in the csv? Mid prices?

FunnyBlue commented 2 years ago

Hi @unclecharliecrypto

Thank you so much for the time reading this report and code carefully. I will try to answer your questions here.

q2 if you check the pnl graphs both Entry TRUE & FALSE trades are being included:

A: I think the chart should exclude those trades (Entry sets as False) as this line of code will ensure that it only counts those (Entry sets as True) trades when making the chart for cumulative PnL. If you check the PnL chart for May 30, the red line is the cumulative amount, it jumps from 10k to ~14k, which aligns to the output.

df['cum_pnl'] = df.apply(lambda x: x['pnl'] if x['entry'] else 0, axis=1) df['cum_pnl'] = df['cum_pnl'].cumsum()

**q3: The article mentions "holding period was no more than 5 minutes per trade".

A: just using Entry = True condition will not show the holding period, you have to set your logic to either entry is True or Exit is True. I have included the code and screenshot here for you to check later.

From the picture, you can see the whole trade holding period (from entry = True to exit = True)

historical_data_strategy_concise[ (historical_data_strategy_concise['entry']==True )|( historical_data_strategy_concise['exit']==True) ]

Screen Shot 2022-10-07 at 11 41 02 PM

**q4: May I confirm what are cex_price & dex_price in the csv? Mid prices?".

A: cex price is the close price per minute, dex price is the snapshot of the pool price ( for every mint/burn/swap) event.

Hope this explanation clarifies the questions and am happy to answer if you have any.

unclecharliecrypto commented 2 years ago

Thank you so much for the insights! Much appreciated. Let me review.

unclecharliecrypto commented 2 years ago
Screen Shot 2022-10-17 at 16 52 25

For Q2 - apologies I should have specified - it was the pnl bar chart I was referring to. Attached screenpic on left is from article where 30May22 pnl > $4k vs. actual pnl $3.614k (I adjusted to show only Entry: TRUE on right). Agreed - the Cumulative PnL chart (red line) looks fine. The Sharpe Ratio also is impacted by inclusion of Entry: FALSE trades fyi. @FunnyBlue

FunnyBlue commented 2 years ago

Hi @unclecharliecrypto I have checked the code and indeed it includes both Entry TRUE & FALSE trades which should only consider entry is True trade for PnL charting.

Add this line of code under the function groupby_date_data(df) will solve the issue and the chart for both PnL sum/avg and the Sharp will be updated accordingly. Thanks for pointing this out!

df['pnl'] = df.apply(lambda x: x['pnl'] if x['entry'] else None, axis=1)

Screen Shot 2022-10-17 at 2 38 10 PM
unclecharliecrypto commented 2 years ago

@FunnyBlue Thanks FunnyBlue!

FunnyBlue commented 1 year ago

@unclecharliecrypto happy to collaborate/discuss if you have some interesting strategy ideas to explore together.

grantbelford commented 1 year ago

https://github.com/hummingbot/hummingbot/issues/5677

@FunnyBlue fyi. Been live testing several of the hummingbot.io strats in a personal capacity. In particular working through the code for the Avellaneda MM strat. It has gone through several hummingbot version modeling interations.