Skip to content

Add unit tests for performance utilities - #43

Open
dbigham wants to merge 11 commits into
mainfrom
codex/add-total-pl-and-cagr-calculation-feature
Open

Add unit tests for performance utilities#43
dbigham wants to merge 11 commits into
mainfrom
codex/add-total-pl-and-cagr-calculation-feature

Conversation

@dbigham

@dbigham dbigham commented Sep 30, 2025

Copy link
Copy Markdown
Owner

Summary

  • add a vitest test script and configuration so the client bundle can run unit tests
  • cover the performance timeline helpers with unit tests to verify windowing, summaries, and chart point generation

Testing

  • npm run lint
  • npm test

https://chatgpt.com/codex/tasks/task_e_68dc4d0d3300832d89fe2ca52c655f09

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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

Comment on lines +145 to +178
export function computePerformanceSummary(timeline, period) {
const window = getTimelineWindow(timeline, period);
if (!window) {
return null;
}
const { startIndex, endIndex } = window;
if (startIndex > endIndex) {
return null;
}
const startValue = startIndex > 0 ? Number(timeline[startIndex - 1].value) || 0 : 0;
const endValue = Number(timeline[endIndex].value) || 0;
const { total: netFlows, positive: positiveFlows } = sumFlows(timeline, startIndex, endIndex);
const totalPnl = endValue - startValue - netFlows;
const invested = startValue + positiveFlows;
const percent = invested > 0 ? (totalPnl / invested) * 100 : startValue !== 0 ? (totalPnl / Math.abs(startValue)) * 100 : null;

const startDate = parseDate(timeline[startIndex].date);
const endDate = parseDate(timeline[endIndex].date);
let cagr = null;
if (startDate && endDate && endDate > startDate) {
const cashFlows = [];
cashFlows.push({ date: startDate, amount: -startValue });
for (let i = startIndex; i <= endIndex; i += 1) {
const flow = Number(timeline[i].netFlows);
if (!Number.isFinite(flow) || flow === 0) {
continue;
}
const flowDate = parseDate(timeline[i].date);
if (!flowDate) {
continue;
}
cashFlows.push({ date: flowDate, amount: -flow });
}
cashFlows.push({ date: endDate, amount: endValue });

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Start value calculated from wrong date

The performance summary uses timeline[startIndex - 1].value as the starting value while exposing timeline[startIndex].date as the period start and plotting points beginning at startIndex. As a result, the displayed "Starting value" and derived P&L/percent include gains or losses that happened before the visible range. For a sparse timeline, selecting “Last Month” will show a chart that starts on the first point inside that month but the metrics are still based on the previous earlier point, overstating returns for the chosen period. The starting value and cash‑flow baseline should line up with the same timeline index that defines the period, or the period should shift to include the baseline date.

Useful? React with 👍 / 👎.

@dbigham
dbigham force-pushed the codex/add-total-pl-and-cagr-calculation-feature branch from 7f0893f to d45d743 Compare October 4, 2025 12:06
@dbigham
dbigham force-pushed the main branch 3 times, most recently from c7f2145 to c8636e3 Compare November 15, 2025 21:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant