bbgo icon indicating copy to clipboard operation
bbgo copied to clipboard

Help understand the PNL report

Open arthurwolf opened this issue 2 years ago • 9 comments

Hello!

I need help with understanding the "Profit and Loss Report" that is displayed at the end of a backtesting run.

Most of the fields I am not certain what they mean. If I get help understanding, I will provide a Pull Request to improve the current documentation.

Let's imagine a scenario, with dummy/simple values so we can better understand what is going on:

  • We grid trade ETH over 7 days. We start with 10000 USDT and 0 ETH.
  • The initial ETH-USDT rate is 5000 USD per ETH, and the final rate is 15000.
  • In the beginning, the grid buys all of the trades that are above the current rate at the best price, so 1000 USDT worth of ETH is bought at 5000 USDT per ETH (that is, 0.2 ETH)
  • Over the 7 days, the grid does 10 trades, each time buying 100 USDT worth ETH at a 10000 rate, and selling at a 11000 rate.
  • The fee is 1% for all transactions.
  • In the end, all ETH is sold for USDT (the bots I have used so far do this, but I do not know if the current code does this, or just presumes the bot ends with both ETH and USDT) at the end rate of 15000.

Now I need to calculate the profit for each of the grid trades above:

First off, the "buy/hold" value is the value we would have earned if we did not do grid trading, but just purchased 10000 USDT worth of ETH at the beginning, and sold it at the end. This is helpful to compare the grid profit with not just a stable USDT, but also with the increase in value in ETH, so we can later take out that profit (we would have made anyway) from the grid profit. Here we start with 10000 USDT, at 5000 that is 2 ETH in the beginning. At the end we sell the 2 ETH for 15000 each, so we have 30000 USDT. This means we did a 300% profit. Where in the PNL report would this 300% value be found? «ETH BASE ASSET PERFORMANCE»? «ETH PERFORMANCE»? And if it is one of these two, what does the other one mean?

Let's calculate the profit of the grid trades. We do 10 times a purchase of 100 UST worth of ETH at a 10000 rate, and sell 10 times at a 11000 rate. That means we purchase 0.1 ETH at 10000, and sell 0.1 ETH at 11000, so we start with 1000 USDT and end with 1100 USDT. That means we make a profit of 100 USDT. Where is that profit written in the report? Is it the "PROFIT" line? Or does that line include other profits/values, such as buy/hold profits for example? How is the fee calculated in relation to all of this? What is "UNREALIZED PROFIT" in this context, or in any context?? What is "STOCK" ??

In the report bellow, and based on the scenario above, how would you fill in the values correctly?

[0022]  INFO ETHUSDT PROFIT AND LOSS REPORT
[0022]  INFO ===============================================
[0022]  INFO TRADES SINCE: ...
[0022]  INFO NUMBER OF TRADES: ...
[0022]  INFO AVERAGE COST: $ ...
[0022]  INFO TOTAL BUY VOLUME: ...
[0022]  INFO TOTAL SELL VOLUME: ...
[0022]  INFO STOCK: ...
[0022]  INFO FEE (USD): ...
[0022]  INFO CURRENT PRICE: $ ...
[0022]  INFO CURRENCY FEES:
[0022]  INFO  - ETH: ...
[0022]  INFO  - USDT: ...
[0022]  INFO PROFIT: $ ...
[0022]  INFO UNREALIZED PROFIT: $ ...
[0022]  INFO INITIAL BALANCES:
[0022]  INFO  USDT: ...
[0022]  INFO FINAL BALANCES:
[0022]  INFO  ETH: ...
[0022]  INFO  USDT: ...
[0022]  INFO INITIAL ASSET ~= ... ETH (1 ETH = ...)
[0022]  INFO FINAL ASSET ~= ... ETH (1 ETH = ...)
[0022]  INFO ETH BASE ASSET PERFORMANCE: ...% (= (... - ...) / ...)
[0022]  INFO ETH PERFORMANCE: ...% (= (... - ...) / ...)

Any help would be extremely welcome. I can not really make proper use of Bbgo until I understand what these numbers mean...

Thanks again!

arthurwolf avatar Dec 04 '21 16:12 arthurwolf

Comments on telegram from @c9s :

unrealized profit - you hold some assets, and these assets are not sold, if you sell them, you will made these profit. if you set long: true, you will hold the profit in the base currency (e.g., BTC), so these BTC become your unrealized profit.

arthurwolf avatar Dec 04 '21 16:12 arthurwolf

Arthur Wolg, [04/12/2021 18:04] if my grid buys 0.1 ETH at 10000 USDT/ETH, and sells 0.1 ETH at 11000 USDT/ETH, what is my profit, what is my unrealized profit ?

c9s, [04/12/2021 18:15] unrealized profit = 0 because you have sold all ETH you just bought. profit will be 0.1 * (11000 - 10000) = 100 USDT

Arthur Wolg, [04/12/2021 18:17] so if I buy 2 ETH at 1000 USDT/ETH, and sell 1ETH at 1100 USDT/ETH, my profit in USDT is 1100, and my unrealized profit in ETH is 1 ETH (which is valued currently at 1100 also) correct?

c9s, [04/12/2021 18:20] [In reply to Arthur Wolg] you sold 1 ETH at 1100, so your profit is 1 * (1100 - 1000) = 100 and the unrealized profit is 1 * (1100 - 1000) = 100

c9s, [04/12/2021 18:20]

(which is valued currently at 1100 also) yes

c9s, [04/12/2021 18:20] so if the price goes up later

c9s, [04/12/2021 18:20] ETH is at 2100,

c9s, [04/12/2021 18:21] then your unrealized profit is 1 * (2100 - 1000) = 1100

arthurwolf avatar Dec 04 '21 17:12 arthurwolf

Screenshot from 2021-12-04 18-58-20

arthurwolf avatar Dec 04 '21 18:12 arthurwolf

c9s, [04/12/2021 19:06] [In reply to Arthur Wolg] initial asset - if you convert your initial balances into the base asset, e.g. BTC, how much did it equal to

final asset - if you convert your final balances into the base asset, e,g. BTC, how mush does it equal to now

base asset performance: use the initial asset and final asset to calcualte the base line performance.

performance: the price change percentage (close price - open price) / open price

arthurwolf avatar Dec 04 '21 18:12 arthurwolf

Screenshot from 2021-12-04 19-15-55

arthurwolf avatar Dec 04 '21 18:12 arthurwolf

Note on fees:

Screenshot from 2021-12-06 10-50-54

arthurwolf avatar Dec 06 '21 09:12 arthurwolf

Some more info on the amount:

Screenshot from 2021-12-06 16-03-51

arthurwolf avatar Dec 06 '21 15:12 arthurwolf

Screenshot from 2021-12-06 16-34-40

arthurwolf avatar Dec 06 '21 15:12 arthurwolf

Screenshot from 2021-12-07 13-59-22

arthurwolf avatar Dec 07 '21 12:12 arthurwolf