From b65510da4d9c7ec9e8832199a1bb3d0b1302aa7a Mon Sep 17 00:00:00 2001 From: Lel2PouxLait <84011642+Lel2PouxLait@users.noreply.github.com> Date: Sun, 24 Nov 2024 14:55:49 +0100 Subject: [PATCH] Patch wrong usage of trades fees Trades fees were added to the portfolio_purchase_price instead of removed which led to an overestimated portfolio_purchase_price. Easily testable with : BUY BTC 1 1000 EUR,1000 10 SELL BTC 0.375 1200 EUR 450.0 3 SELL BTC 0.625 2080 EUR 1300 7 Without the patch : [portfolio_purchase_price_net] = 1010 With the patch : [portfolio_purchase_price_net] = 990 --- coin2086/pnl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coin2086/pnl.py b/coin2086/pnl.py index 26ea129..376aef1 100644 --- a/coin2086/pnl.py +++ b/coin2086/pnl.py @@ -10,7 +10,7 @@ def add_portfolio_purchase_price(trades, initial_purchase_price): trades["portfolio_purchase_price"] = 0 trades.loc[trades["trade_side"] == "BUY", "portfolio_purchase_price"] = ( - trades["amount"] + trades["fee"] + trades["amount"] - trades["fee"] ) trades["portfolio_purchase_price"] = trades["portfolio_purchase_price"].cumsum() trades["portfolio_purchase_price"] += initial_purchase_price