Skip to content

Fix MWR calculation, align TWR/MWR conventions, add portfolio Markdown export for AI - #20

Merged
ascatox merged 1 commit into
mainfrom
claude/mwr-calculation-check-a2ahci
Jul 13, 2026
Merged

Fix MWR calculation, align TWR/MWR conventions, add portfolio Markdown export for AI#20
ascatox merged 1 commit into
mainfrom
claude/mwr-calculation-check-a2ahci

Conversation

@ascatox

@ascatox ascatox commented Jul 13, 2026

Copy link
Copy Markdown
Owner

Summary

Nato da una verifica di correttezza del calcolo MWR, questo PR contiene tre blocchi di lavoro:

1. Fix del calcolo MWR (performance_service.py)

  • Doppio conteggio dei cashflow nel giorno di inizio periodo: calculate_mwr includeva come flusso a t=0 anche i movimenti datati start, già compresi in start_value → MWR sottostimato. Ora esclusi, coerentemente con calculate_twr e get_mwr_timeseries.
  • Rettifiche cash errate nel fallback buy/sell: get_portfolio_value_at_date non attribuisce alcun impatto cash ai trade, quindi le sottrazioni cash_before/cash_in_period toglievano denaro mai presente nel valore (es. buy 1000 → 1200 dava MWR ≈ −93% invece di ≈ +20%). Rimosse.
  • Dividendi/interessi/fee trattati come movimenti interni: restano nel cash del portafoglio, quindi sono rendimento, non contributi dell'investitore. I flussi esterni per TWR/MWR sono ora solo deposit/withdrawal (o buy/sell nel fallback, contati come flussi reali anche per il TWR).

2. Allineamento convenzioni TWR ↔ MWR

  • MWRResult.mwr_pct è ora il rendimento di periodo come twr_pct; il tasso annuo è esposto nel nuovo campo mwr_annualized_pct solo per periodi ≥ 365 giorni (specchio di twr_annualized_pct).
  • I punti di get_mwr_timeseries riportano il rendimento cumulato da inizio periodo: grafico confrontabile con la serie TWR e stabile nei primi giorni.
  • Frontend: nuovo campo nel tipo MWRResult, tooltip MWR aggiornato.

3. Export Markdown del portafoglio per AI esterne

  • Nuovo servizio portfolio_markdown_export.py: renderizza lo snapshot del Copilot (riepilogo, posizioni, salute Doctor, Monte Carlo, target drift, PAC) più una tabella performance TWR/MWR in Markdown puro.
  • Nuovo endpoint GET /portfolios/{id}/export/markdown (text/markdown, filename di download, 404 uniforme).
  • Bottone "Esporta per AI" nella testata della pagina Portfolio: copia negli appunti o download .md, pronto da incollare in ChatGPT/Claude/Gemini.

Test

  • 13 nuovi test unitari/integrazione (double counting giorno start, fallback buy/sell, dividendi interni, coerenza timeseries↔puntuale, periodo breve vs annualizzato, renderer Markdown, endpoint export).
  • Suite backend completa: 126/126 verdi. Type-check frontend (tsc --noEmit) pulito.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Dfocvsn4D46Kk3WRMeEeWY


Generated by Claude Code

- New portfolio_markdown_export service: renders the Copilot portfolio
  snapshot (summary, positions, Doctor health, Monte Carlo, target
  drift, PAC) plus a TWR/MWR performance table as plain Markdown.
- New GET /portfolios/{id}/export/markdown endpoint returning
  text/markdown with a Content-Disposition attachment filename.
- Frontend: 'Esporta per AI' menu in the Portfolio page header with
  copy-to-clipboard and .md download actions.
- Unit tests for the renderer and integration tests for the endpoint.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Dfocvsn4D46Kk3WRMeEeWY
@vercel

vercel Bot commented Jul 13, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
valore365 Ready Ready Preview, Comment Jul 13, 2026 4:05pm

@ascatox
ascatox merged commit 47dfad1 into main Jul 13, 2026
3 checks passed
@ascatox
ascatox deleted the claude/mwr-calculation-check-a2ahci branch July 13, 2026 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants