Skip to content

Extract calcPremiumStats from rCharts into 05d-calc-stats.js #56

@heyitsStylez

Description

@heyitsStylez

What to build

Extract the inline calcStats closure from rCharts into a standalone pure function calcPremiumStats in a new file src/js/05d-calc-stats.js. This is a Premium Statistics function — a gross-premium-income view over a set of Trade rows, distinct from the cash-flow lens in computePnl.

The dead fields (assignmentLoss, callAwayCredit, netPnl) are not rendered anywhere in the current UI and should be dropped entirely.

rCharts in src/js/07-render-charts.js calls calcPremiumStats(displayRows) in both the Total and Monthly tab paths. The inline calcStats definition is deleted.

The new function is dual-exported (browser global + module.exports) following the same pattern as computePnl and lotEngine.

Acceptance criteria

  • src/js/05d-calc-stats.js exists with calcPremiumStats(rows) returning { totalPrem, totalNotional, totalCount, otmCount, itmCount, openCount, settled, returnRate, portfolioAPR }
  • calcPremiumStats is dual-exported
  • rCharts no longer contains an inline calcStats definition
  • Premium P&L Total tab and Monthly tab render correctly after the change
  • test/unit/calc-stats.test.js added with passing tests covering: portfolio APR is notional-weighted, return rate is null when no settled trades, return rate is 100% when all expired OTM, HOLDING trades excluded from all counts
  • python3 build.py --check passes
  • npm test passes
  • Verify docs/architecture.md core data flow diagram is accurate — it already shows 05d-calc-stats.js with calcPremiumStats. Confirm the node's signature matches the implemented function and adjust if needed.

Blocked by

None — can start immediately.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions