Account report total cash divergence with manually calculated equity #2657
-
While trying to calculate final equity encountered strange behavior: Engine Logsaccount = engine.trader.generate_account_report(BINANCE)
tmp = pd.DataFrame(account['total'])
tmp['total'] = (tmp['total'].astype('float') - 1e6) # Example strategy works with initial 1e6 USD
tmp.plot() We see here reduce of total cash, but the engine logs states that we have positive PnL:
Engine get_result()Furthermore, If we try to regenerate report: tmp = engine.get_result()
tmp.stats_pnls We get
That looks nothing like we've seen above in strategy logs. Manual PnL calculationreport = engine.trader.generate_positions_report()
report = report.set_index('ts_closed')
sns.lineplot(report["realized_pnl"].apply(lambda s: float(s.split()[0])).cumsum())
plt.xticks(rotation=45)
plt.show() And this result seems the most reliable. So the question is: Why all these seemingly similar operations give such drastically divergent results? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @Egisess Thanks for reaching out with the detailed report. I managed to track it down to position flip scenarios for margin accounts. Now fixed from d3abd99 which adds tests to confirm position PnL exactly matches account PnL, including your example inputs. Please confirm the fix on your end what you have the chance. |
Beta Was this translation helpful? Give feedback.
Hi @Egisess
Thanks for reaching out with the detailed report.
I managed to track it down to position flip scenarios for margin accounts.
Now fixed from d3abd99 which adds tests to confirm position PnL exactly matches account PnL, including your example inputs.
Please confirm the fix on your end what you have the chance.