"""Illustrative arithmetic, not observed returns or a forecast. Python stdlib only."""
from pathlib import Path
from decimal import Decimal,localcontext
import json,csv
B=Path(__file__).parent
D=Decimal
with localcontext() as ctx:
 ctx.prec=40
 rows=[]
 for annual in ['0.0025','0.0095','0.015']:
  for years in [1,3,5,10]:
   retained=D(100)*(1-D(annual)/D(365))**(365*years)
   rows.append({'annual_fee_pct':str(D(annual)*100),'years':years,'retained_units':str(retained),'units_lost':str(100-retained)})
 premium_return=D('1.10')*D('.99')/D('1.02')-1
 quote={'asOf':'2026-09-29','marketPriceUSD':'16.39','navUSD':'16.44','reportedPremiumDiscountPct':'-0.28','source':'https://canaryetfs.com/ltcc/','roundedPriceArithmeticPct':str((D('16.39')/D('16.44')-1)*100),'roundingRangePct':[str((D('16.385')/D('16.445')-1)*100),str((D('16.395')/D('16.435')-1)*100)],'assumption':'Display values rounded to nearest cent. Range describes possible ratios of unrounded values; issuer exact calculation inputs were not obtained.'}
 assert D(quote['roundingRangePct'][0])<D('-.28')<D(quote['roundingRangePct'][1])
 assert all(D(r['retained_units'])<100 for r in rows)
 model={'feeModel':'100 normalized units * (1 - annual_rate/365) ** (365*years). Hypothetical constant rate, daily reduction and 365-day years; no asset price change, trading costs, tax, FX, extraordinary expenses or fee changes. This is not an exact projection of LTCC share holdings.','fees':rows,'premiumExample':{'underlyingReturnPct':'10','entryPremiumPct':'2','exitDiscountPct':'1','shareReturnBeforeFeesPct':str(premium_return*100)},'datedIssuerQuote':quote,'checks':{'roundingContainsReportedValue':True,'feesReduceUnits':True}}
(B/'etf-calculations.json').write_text(json.dumps(model,indent=2)+'\n',encoding='utf-8')
with (B/'etf-fees.csv').open('w',newline='',encoding='utf-8') as f:
 w=csv.DictWriter(f,fieldnames=rows[0]);w.writeheader();w.writerows(rows)
print(json.dumps({'fee_rows':len(rows),'premiumExamplePct':str(premium_return*100),'roundingRangePct':quote['roundingRangePct']}))
