You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
What to build
Extract the inline
calcStatsclosure fromrChartsinto a standalone pure functioncalcPremiumStatsin a new filesrc/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 incomputePnl.The dead fields (
assignmentLoss,callAwayCredit,netPnl) are not rendered anywhere in the current UI and should be dropped entirely.rChartsinsrc/js/07-render-charts.jscallscalcPremiumStats(displayRows)in both the Total and Monthly tab paths. The inlinecalcStatsdefinition is deleted.The new function is dual-exported (browser global +
module.exports) following the same pattern ascomputePnlandlotEngine.Acceptance criteria
src/js/05d-calc-stats.jsexists withcalcPremiumStats(rows)returning{ totalPrem, totalNotional, totalCount, otmCount, itmCount, openCount, settled, returnRate, portfolioAPR }calcPremiumStatsis dual-exportedrChartsno longer contains an inlinecalcStatsdefinitiontest/unit/calc-stats.test.jsadded 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 countspython3 build.py --checkpassesnpm testpassesdocs/architecture.mdcore data flow diagram is accurate — it already shows05d-calc-stats.jswithcalcPremiumStats. Confirm the node's signature matches the implemented function and adjust if needed.Blocked by
None — can start immediately.