Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions CONTEXT.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,28 @@ read **Term**. Never label a frozen original-DTE column "DTE" — the
ambiguity historically led to three identically-labelled columns showing two
different numbers.

### Premium Statistics
A gross-premium-income view over a set of Trade rows. Distinct from Realised
P&L (which is a cash-flow lens): Premium Statistics treats premium collected as
the primary signal and derives:

- **Total premium** — sum of net premiums across all trades in the set
- **Total notional** — Σ strike × size (capital at risk)
- **Portfolio APR** — notional-weighted average APR of settled options:
`(netPrem / collateral) / DTE × 365`, weighted by notional
- **Return rate** — share of settled options that expired OTM (premium kept)
- **OTM / ITM counts** — settled outcome breakdown

Lives in `src/js/05d-calc-stats.js` as the pure function
`calcPremiumStats(rows) → { totalPrem, totalNotional, portfolioAPR, returnRate,
otmCount, itmCount, openCount, settled, totalCount }`. Dual-exported. Consumed
by `rCharts` for the Premium P&L Total and Monthly tabs.

Intentionally does **not** include Realised P&L or Unrealised P&L — those live
in `computePnl`. The two functions answer different questions: `computePnl`
answers *"what did this position earn under cash-flow accounting?"*;
`calcPremiumStats` answers *"how is the premium-income engine performing?"*

### Trade accounting snapshot
A per-trade record of the lot state **at the moment that trade was processed**
by the engine: `{ lotNum, lotSize, lotPremiums, lotCostBasis }`. Captured
Expand Down
8 changes: 4 additions & 4 deletions src/js/06-render-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,15 +214,15 @@ function renderExpiryTable() {
const rows = enriched.map(e => {
const t = e.t;
return '<tr>'
+ '<td style="color:var(--' + e.col + ');font-weight:700">' + t.asset + '</td>'
+ '<td>' + t.type + '</td>'
+ '<td><span class="badge b' + e.col + '">' + t.asset + '</span></td>'
+ '<td>' + e.platBadge + '</td>'
+ '<td><span class="badge b' + t.type.toLowerCase() + '">' + t.type + '</span></td>'
+ '<td>$' + fmt(t.strike) + '</td>'
+ '<td>' + fmt(t.size) + '</td>'
+ '<td>' + e.dteLabel + '</td>'
+ '<td>$' + fmt(t.premium) + '</td>'
+ '<td>' + e.aprHtml + '</td>'
+ '<td>' + e.statusHtml + '</td>'
+ '<td>' + e.platBadge + '</td>'
+ '<td class="td-act">' + e.actionsHtml + '</td>'
+ '</tr>';
}).join('');
Expand All @@ -248,7 +248,7 @@ function renderExpiryTable() {
}).join('');

wrap.innerHTML = '<table class="expiry-tbl">'
+ '<thead><tr><th>Asset</th><th>Strategy</th><th>Strike</th><th>Size</th><th>DTE</th><th>Premium</th><th>APR</th><th>Status</th><th>Platform</th><th></th></tr></thead>'
+ '<thead><tr><th>Asset</th><th>Platform</th><th>Type</th><th>Strike</th><th>Size</th><th>DTE</th><th>Premium</th><th>APR</th><th>Status</th><th></th></tr></thead>'
+ '<tbody>' + rows + '</tbody>'
+ '</table>'
+ '<div class="exp-cards">' + cards + '</div>';
Expand Down
Loading