Add account performance analysis dialog#44
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting
| const totalPnl = (endValue + totalWithdrawals) - (startValue + totalContributions); | ||
| const investedBase = startValue + totalContributions; | ||
| const totalReturn = investedBase > 0 ? totalPnl / investedBase : null; |
There was a problem hiding this comment.
Avoid double-counting contributions in P&L totals
The totals calculation treats the first timeline value as already-invested capital (startValue) and then subtracts the same trades again through totalContributions. Because the earliest timeline entry is computed after the first day’s executions, any buys that created that position are counted twice in (endValue + totalWithdrawals) - (startValue + totalContributions), which can yield negative P&L for an otherwise profitable account. The function needs either an initial zero-value entry before the first trade or to exclude cash flows occurring on/before that first timeline date when building totalContributions/totalWithdrawals.
Useful? React with 👍 / 👎.
c5378fa to
3c6855b
Compare
c7f2145 to
c8636e3
Compare
Summary
Testing
https://chatgpt.com/codex/tasks/task_e_68dd2361fda0832db4de7e463e57af49