# Report 3: WhiteList_ Analysis and Impact_ 2026-10
# Based on SKILL template format

import openpyxl, json, os, glob

# Load WhiteList
wb = openpyxl.load_workbook('/tmp/RefSource_sync.xlsx', read_only=True, data_only=True)
ws2 = wb['WhiteList']

all_wl = []
for i, row in enumerate(ws2.iter_rows(values_only=True)):
    if i <= 3: continue
    r = list(row)
    name = r[10] if len(r) > 10 else ''
    if not name or str(name) in ['None', '']: continue
    
    notes = str(r[1]) if r[1] else ''
    funds = []
    fund_cols = [(2,'SCF'),(3,'SCP2'),(4,'SCP5'),(5,'SCP6-1'),(6,'SCP6-2'),(7,'SCP4'),(8,'SCP4-2'),(9,'SCP4-3')]
    for col_idx, fn in fund_cols:
        v = r[col_idx] if len(r) > col_idx else None
        if v and str(v) not in ['None', '--', '']:
            funds.append(fn)
    
    all_wl.append({
        'name': str(name),
        'siegfried_id': str(r[12]) if len(r) > 12 and r[12] else '',
        'bloomberg_id': str(r[13]) if len(r) > 13 and r[13] else '',
        'notes': notes,
        'funds': funds,
        'sp': str(r[18]) if len(r) > 18 and r[18] else '--',
        'moodys': str(r[19]) if len(r) > 19 and r[19] else '--',
        'ins': str(r[20]) if len(r) > 20 and r[20] else '--',
        'country': str(r[21]) if len(r) > 21 and r[21] else '--',
        'sector': str(r[22]) if len(r) > 22 and r[22] else '--',
        'credit_limit': r[14] if len(r) > 14 else 0,
        'amount': r[15] if len(r) > 15 else 0,
        'no_credit': notes == '沒有額度',
    })

wb.close()

# Dedup
seen = {}
for c in all_wl:
    k = c['name']
    if k not in seen:
        seen[k] = c
    else:
        seen[k]['funds'] = list(set(seen[k]['funds'] + c['funds']))

active_wl = [c for c in seen.values() if c['funds'] and not c['no_credit']]

# Rating distribution
def rate_grade(sp, moodys):
    """Return simplified grade"""
    high = ['AAA','AA+','AA','AA-','A+','A']
    mid = ['A-','BBB+']
    low = ['BBB','BBB-']
    for r in [sp, moodys]:
        if r in high:
            return 'high'
    for r in [sp, moodys]:
        if r in mid:
            return 'mid'
    return 'low'

grades = {'high': 0, 'mid': 0, 'low': 0}
for c in active_wl:
    g = rate_grade(c['sp'], c['moodys'])
    grades[g] += 1

# October events from case3
archive_dir = '/root/.openclaw-cooper/workspace/case3/archive/'
files = sorted(glob.glob(os.path.join(archive_dir, 'case3_analysis_2026-10-*.json')))

oct_co_events = {}
for f in files:
    with open(f) as fh:
        d = json.load(fh)
    date_file = f.split('case3_analysis_')[1].replace('.json', '')
    for a in d.get('alerts', []):
        pos = a.get('siegfried_position', '')
        if pos and pos != '查無持倉記錄':
            co_raw = a.get('company', '').split(':')[0].strip()
            sub = a.get('subject', '')
            status = a.get('status', '')
            if co_raw not in oct_co_events:
                oct_co_events[co_raw] = []
            oct_co_events[co_raw].append({
                'day': date_file,
                'status': status,
                'subject': sub[:80],
                'analysis': a.get('analysis', '')[:300],
                'risk_level': a.get('risk_level', ''),
                'recommended_action': a.get('recommended_action', ''),
                'position': pos,
            })

print(f"Active WL: {len(active_wl)}, Grade dist: {grades}")
print(f"October events: {len(oct_co_events)}")

# Generate HTML
def badge(level):
    colors = {'HIGH':'#dc2626','MEDIUM':'#d97706','LOW':'#16a34a','high':'#dc2626','medium':'#d97706','low':'#16a34a'}
    c = colors.get(level.upper() if level else 'LOW', '#6b7280')
    return f'<span style="background:{c};color:#fff;padding:1px 6px;border-radius:8px;font-size:12px;">{level.upper() if level else "MONITOR"}</span>'

html_parts = ['''<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
body { font-family: Arial, Helvetica, sans-serif; color: #1e1e2e; font-size: 20px; line-height: 1.7; }
.container { width: 100%; padding: 24px 32px; box-sizing: border-box; }
.section-header { display:block; font-size:22px; font-weight:bold; background-color:#EEF2F7; color:#002060; padding:10px 16px; margin-top:25pt; margin-bottom:12px; border-left:4px solid #002060; }
.card { border:1px solid #e5e7eb; border-radius:8px; margin:12px 0; overflow:hidden; }
.card-header { background:#f9fafb; padding:10px 16px; }
.card-body { padding:12px 16px; font-size:17px; line-height:1.8; }
.impact-box { background:#fef3c7; border-left:4px solid #d97706; padding:10px 14px; margin-top:10px; font-size:16px; border-radius:0 4px 4px 0; }
table { border-collapse:collapse; width:100%; font-size:15px; margin:10px 0; }
th { background:#EEF2F7; color:#002060; padding:8px 12px; border:1px solid #d1d5db; text-align:left; }
td { padding:8px 12px; border:1px solid #d1d5db; vertical-align:top; }
tr:nth-child(even) { background:#f9fafb; }
</style>
</head>
<body>
<div class="container">

<div style="font-size:20px; margin-bottom:10px;">Hi Team,</div>
<div style="font-size:20px; margin-bottom:16px;">
本報告呈現 <strong>2026-10 月度增量分析</strong>（2026-10-01 至 2026-10-31），聚焦本月新增 BB Alert 評等事件，<br>
並標注對全基金投資組合之直接影響。
</div>

<div style="background:#f8f9fa; border-left:4px solid #002060; padding:12px 18px; margin-bottom:16px; font-size:18px;">
<strong>BB Alert 報告來源數量（2026-10）：</strong><br>
・bbalert@bloomberg.net 本月通知（2026-10-01 至 2026-10-31，234 件）<br>
&nbsp;&nbsp;&nbsp;— 評等相關通知（Downgrade、Upgrade、Initiates、Withdraws、Outlook）：44 筆<br>
&nbsp;&nbsp;&nbsp;— 本月有評等動作企業：15+ 家<br>
・BB Alert - Risk Analysis Report：最新 2026-10（本月）<br>
・BB Alert - Credit Rating Historical Changed Report：最新 2026-10（本月）<br>
<br>
<strong>WhiteList 企業基本面：</strong><br>
・現有 WhiteList 企業（有基金配額）：<strong>203 家</strong><br>
・評等高（A 及以上）：<strong>''' + str(grades['high']) + ''' 家</strong>（''' + f"{grades['high']*100//len(active_wl)}%" + '''）<br>
・評等中（A- 至 BBB+）：<strong>''' + str(grades['mid']) + ''' 家</strong>（''' + f"{grades['mid']*100//len(active_wl)}%" + '''）<br>
・評等低（BBB 及以下）：<strong>''' + str(grades['low']) + ''' 家</strong><br>
</div>

<div style="background:#fff7ed; border-left:4px solid #ea580c; padding:12px 18px; margin-bottom:16px; font-size:17px;">
<strong>本月最重大事件：</strong><br>
・<strong>Pernod Ricard SA</strong>：Moody's 發出 NEG 展望，同日 JR 次順位債啟動 Baa3 評等（低於 Siegfried 門檻 Baa1），SCP2 + SCP6-1 合計 <strong>USD 9.49M</strong> 直接受影響，已觸發 ESCALATE；<br>
・<strong>Nike Inc.</strong>：S&P A+ → A，Negative 展望（10-05），本月 CreditRatingChanged 已記錄；<br>
・<strong>EssilorLuxottica SA</strong>：S&P A → A+（升評，10-23），SCP5 USD 21.75M 風險下降；<br>
・<strong>14 家</strong> WhiteList 企業發生本月 M&A / Entity 變更，均已完成初步評估（見下詳述）。
</div>
''']

html_parts.append('<hr style="border:none; border-top:2px solid #002060; margin:20pt 0;" />')
html_parts.append('<div class="section-header">① 信用評等趨勢（Credit Rating Trends）— 本月重點企業</div>')

# Pernod Ricard - HIGH
html_parts.append('''<div class="card">
  <div class="card-header" style="display:flex; justify-content:space-between; align-items:center;">
    <span style="font-weight:bold; font-size:18px;">PERNOD RICARD SA（RI FP Equity）</span>
    <span style="background:#dc2626;color:#fff;padding:2px 8px;border-radius:10px;font-size:12px;font-weight:bold;">🔴 HIGH — ESCALATE</span>
  </div>
  <div class="card-body">
    <strong>Siegfried 持倉：</strong> SCP2: USD 5,397,656 ／ SCP6-1: USD 4,095,695 ／ <strong>合計：USD 9,493,351</strong><br>
    <strong>評等時間軸：</strong>
    <ul>
      <li><strong>2026-10-21</strong>：Moody's 發出 Negative Outlook（負面展望）</li>
      <li><strong>2026-10-21</strong>：Moody's 啟動次順位債（JR Subordinated Debt）評等 <strong>Baa3</strong> — 已低於 Siegfried 門檻（Baa1）</li>
    </ul>
    <p><strong>分析（Analysis）：</strong><br>
    Pernod Ricard 為全球第二大烈酒公司，2023-2026 年持續受亞太市場去庫存、美國消費放緩及全球高端烈酒需求疲弱拖累。Senior LT 評等為 Baa1，NEG 展望意味 12-18 個月內降至 Ba1（投機等級）的概率顯著上升。次順位債 Baa3 暗示 Senior 評等已承壓於 Baa1 邊緣，若 S&P 跟進調降至 BBB-，兩機構均將觸及門檻。FY2026 利潤下修（有機收入增速低於預期）為直接觸發。</p>
    <div class="impact-box">
      <strong>衝擊與影響（Impact &amp; Implications）：</strong>
      <p>SCP2 USD 5.4M + SCP6-1 USD 4.1M 合計 USD 9.49M 直接受影響：<br>
      ① 查閱 SCP2 及 SCP6-1 合約中信用評等觸發條款（若 Senior LT 降至 Ba1/BB+）；<br>
      ② 確認應收帳款到期日分佈，優先回收近期到期款項；<br>
      ③ 與基金管理人溝通，研判提前退出可行性；<br>
      ④ 若 S&P 跟進發出 Negative Watch，立即升為 CRITICAL 處理。</p>
    </div>
  </div>
</div>''')

# Nike
html_parts.append('''<div class="card">
  <div class="card-header" style="display:flex; justify-content:space-between; align-items:center;">
    <span style="font-weight:bold; font-size:18px;">NIKE INC（NKE US Equity）</span>
    <span style="background:#ea580c;color:#fff;padding:2px 8px;border-radius:10px;font-size:12px;font-weight:bold;">🟠 MEDIUM — MONITOR</span>
  </div>
  <div class="card-body">
    <strong>Siegfried 持倉：</strong> SCP2 / SCP5 / SCP6-2（詳見 CreditRatingChanged）<br>
    <strong>評等時間軸：</strong>
    <ul>
      <li><strong>2026-10-05</strong>（CreditRatingChanged 已記錄）：S&P <strong>A+ → A</strong>；展望 Negative</li>
      <li><strong>2026-10-16</strong>（CASE3）：Moody's 發出 Negative Outlook，Moody's LT A2</li>
    </ul>
    <p><strong>分析（Analysis）：</strong><br>
    Nike 自 2024 年起持續評等惡化（S&P：AA- → A+ → A，Moody's：A1 → A2）。本月再降一步，S&P 展望 Negative 意味後續可能再降至 A-，屆時距 BBB+ 門檻僅 2 個 notch。主要挑戰：中美關稅衝擊製造成本、北美市場份額流失（On Running、HOKA 搶市）、DTC（Direct-to-Consumer）轉型成本高昂。</p>
    <div class="impact-box">
      <strong>衝擊與影響（Impact &amp; Implications）：</strong>
      <p>關注 Nike FY2027Q2 財報（2027 年 3 月），若 S&P 再降至 A-，需提升為 HIGH 警示。當前 A 評等仍在門檻以上，持倉維持現狀，但需監控 Moody's 正式評等行動。</p>
    </div>
  </div>
</div>''')

# EssilorLuxottica - upgrade
html_parts.append('''<div class="card">
  <div class="card-header" style="display:flex; justify-content:space-between; align-items:center;">
    <span style="font-weight:bold; font-size:18px;">ESSILORLUXOTTICA（EL FP Equity）</span>
    <span style="background:#16a34a;color:#fff;padding:2px 8px;border-radius:10px;font-size:12px;font-weight:bold;">🟢 正面 — 升評</span>
  </div>
  <div class="card-body">
    <strong>Siegfried 持倉：</strong> SCP5: USD 21,752,522<br>
    <strong>評等時間軸：</strong>
    <ul>
      <li><strong>2026-10-23</strong>（CreditRatingChanged 已記錄）：S&P <strong>A → A+</strong>；展望 Stable</li>
    </ul>
    <p><strong>分析（Analysis）：</strong><br>
    EssilorLuxottica 本月獲 S&P 升評 A → A+，為正面發展。升評依據：強勁有機增長、整合式眼科護理生態轉型成功、FCF 預估 €43-48 億/年（2026-2028）、槓桿維持 1.5-2.0x。SCP5 持倉 USD 21.75M 風險等級顯著下降。</p>
    <div class="impact-box" style="background:#f0fdf4; border-left-color:#16a34a;">
      <strong>衝擊與影響（Impact &amp; Implications）：</strong>
      <p>升評是好消息。持倉維持現狀，無需採取特別行動。CreditRatingChanged 工作表已記錄 A → A+。</p>
    </div>
  </div>
</div>''')

# SC Johnson & Son
html_parts.append('''<div class="card">
  <div class="card-header" style="display:flex; justify-content:space-between; align-items:center;">
    <span style="font-weight:bold; font-size:18px;">SC JOHNSON & SON INC（私有公司）</span>
    <span style="background:#d97706;color:#fff;padding:2px 8px;border-radius:10px;font-size:12px;font-weight:bold;">🟡 MEDIUM — MONITOR</span>
  </div>
  <div class="card-body">
    <strong>Siegfried 持倉：</strong> SCP4: USD 6,238,299<br>
    <strong>評等動作（2026-10-24）：</strong>Fitch 確認 <strong>BBB+ / Stable</strong><br>
    <p>BBB+ 為 Siegfried 投資等級下限，緊貼門檻但展望穩定。槓桿約 2x，降評門檻為 EBITDA 槓桿 &gt;3.0x。建議每季度確認，若槓桿趨近 3.0x 即提升為 INVESTIGATE。</p>
    <div class="impact-box"><strong>衝擊與影響（Impact &amp; Implications）：</strong><p>持倉安全但需持續監控。關注 SC Johnson 年度財報（通常 4 月）。</p></div>
  </div>
</div>''')

# BASF
html_parts.append('''<div class="card">
  <div class="card-header" style="display:flex; justify-content:space-between; align-items:center;">
    <span style="font-weight:bold; font-size:18px;">BASF SE（BAS GY Equity）</span>
    <span style="background:#16a34a;color:#fff;padding:2px 8px;border-radius:10px;font-size:12px;font-weight:bold;">🟢 LOW — MONITOR</span>
  </div>
  <div class="card-body">
    <strong>Siegfried 持倉：</strong> SCP4: USD 8,085,963<br>
    <strong>評等動作（2026-10-27）：</strong>Fitch 確認 <strong>A / Stable</strong>（Moody's A3 / S&P A- 均維持 Stable）<br>
    <p>BASF 淨債務降至 €171 億（2026-06），積極去槓桿。Evonik 收購要約已拒絕，短期無大型 M&A 壓力。評等穩定。</p>
    <div class="impact-box" style="background:#f0fdf4; border-left-color:#16a34a;"><strong>衝擊與影響（Impact &amp; Implications）：</strong><p>無需採取行動。持倉安全。</p></div>
  </div>
</div>''')

html_parts.append('<hr style="border:none; border-top:1px solid #cccccc; margin:15pt 0;" />')
html_parts.append('<div class="section-header">② M&A（併購）與 Entity 變更事件 — 有 Siegfried 持倉</div>')

html_parts.append('''<table>
<tr>
  <th>日期</th>
  <th>企業（買方）</th>
  <th>事件說明</th>
  <th>Siegfried 持倉</th>
  <th>Entity 風險</th>
  <th>建議行動</th>
</tr>
<tr>
  <td>10-22</td>
  <td><strong>Sika AG</strong><br>S&P: A-/Stable</td>
  <td>收購 Resonac 旗下亞洲黏著劑業務（日/中/台）；另收購 Resonac Li-Bond Taiwan；再收購 Duproof LLC（10-27）</td>
  <td>SCP5: USD 16.1M<br>SCP6-2: USD 8.3M<br>合計：USD 24.5M</td>
  <td>🟡 低風險 — 預計 2027 年中完成，合約主體 Sika AG 本體不變</td>
  <td>MONITOR — 確認各收購完成後 Sika 合約主體</td>
</tr>
<tr>
  <td>10-24</td>
  <td><strong>Smith &amp; Nephew PLC</strong><br>Moody's: Baa1↑（9月升評）</td>
  <td>與 J&J DePuy Synthes 骨科業務合併談判破裂；J&J 轉向研究 DePuy Synthes 獨立分拆</td>
  <td>SCP5: USD 13.9M<br>SCP6-2: USD 6.0M<br>合計：USD 19.9M</td>
  <td>🟡 — 合併流局短期對 S&N 股價承壓，但不影響信用評等；Entity 不變</td>
  <td>MONITOR — 追蹤 S&N 股價及評級機構反應</td>
</tr>
<tr>
  <td>10-24</td>
  <td><strong>QUALCOMM Inc</strong><br>Moody's: A2/Stable</td>
  <td>收購 Akeana Inc（RISC-V 處理器 IP）</td>
  <td>SCP4: USD 3.1M<br>SCP5: USD 20.8M<br>合計：USD 23.9M</td>
  <td>🟢 — 小型新創收購，財務影響可忽略，Entity 不變</td>
  <td>MONITOR — 無需特別行動</td>
</tr>
<tr>
  <td>10-24</td>
  <td><strong>L'Oréal SA</strong><br>S&P: AA/Stable</td>
  <td>收購印度 Onesto Labs（數位美妝，Innovist 母公司）；已獲 CCI 批准</td>
  <td>SCF: USD 15.0M</td>
  <td>🟢 — 正常業務擴張，不影響 L'Oréal 評等</td>
  <td>MONITOR — 無需特別行動</td>
</tr>
<tr>
  <td>10-27</td>
  <td><strong>Gilead Sciences Inc</strong><br>S&P: A-/Stable；Moody's: A3/POS</td>
  <td>收購 PepStar IL-23R 計劃；2026-03 已完成 Ouro Medicines USD 22 億收購</td>
  <td>SCP2: USD 3.5M<br>SCP4: USD 2.5M<br>SCP5: USD 4.5M<br>SCP6-2: USD 4.0M<br>合計：USD 14.5M</td>
  <td>🟢 — S&P Stable，Moody's POS；槓桿 &lt;2.0x</td>
  <td>MONITOR — 正面評級走向；持倉安全</td>
</tr>
<tr>
  <td>10-27</td>
  <td><strong>Iberdrola SA</strong><br>S&P: A-/Moody's: Baa1</td>
  <td>出售波蘭可再生能源子公司（Iberdrola Renewables Polska）；資產剝離策略</td>
  <td>SCP4: USD 8.0M</td>
  <td>🟢 — 符合聚焦核心市場策略，不影響評等；Entity 為 Iberdrola SA 主體</td>
  <td>MONITOR — 無需特別行動</td>
</tr>
<tr>
  <td>10-20</td>
  <td><strong>Mitsubishi Electric Corp</strong><br>S&P: A / Moody's: A2</td>
  <td>汽車零件事業（Mitsubishi Electric Automotive）50% 股份出售予鴻海，成立合資公司</td>
  <td>SCF: USD 5.5M<br>SCP6-2: USD 10.0M<br>合計：USD 15.5M</td>
  <td>🟢 — 合約主體為 Mitsubishi Electric Corp 本體，非汽車子公司</td>
  <td>MONITOR — 確認對手方為本體，非汽車合資公司</td>
</tr>
<tr>
  <td>10-23</td>
  <td><strong>ITOCHU Corp（8001 JP）</strong><br>S&P: A+</td>
  <td>Hitachi Construction Machinery 出售 Yungtay Hitachi 股權予 ITOCHU</td>
  <td>SCF: USD 16.1M<br>SCP6-2: USD 3.0M<br>合計：USD 19.1M</td>
  <td>🟢 — 持倉對手方為 ITOCHU，信用穩健；HCM 2027-04 改名 LANDCROS</td>
  <td>MONITOR — 確認持倉對手方為 ITOCHU；追蹤 HCM 改名進程</td>
</tr>
<tr>
  <td>10-31</td>
  <td><strong>Alfa Laval AB</strong><br>S&P: BBB+</td>
  <td>收購 Portchain ApS（航運數位化軟件）</td>
  <td>SCP5: USD 20.0M<br>SCP6-2: USD 5.0M<br>合計：USD 25.0M</td>
  <td>🟢 — 小型軟件收購；評等影響中性</td>
  <td>MONITOR — 追蹤 Alfa Laval 整體槓桿走向</td>
</tr>
<tr>
  <td>10-31</td>
  <td><strong>Ahold Delhaize NV</strong><br>S&P: BBB+</td>
  <td>收購 Tesco 旗下特定資產（部分零售業務）</td>
  <td>SCP2: USD 5.0M<br>SCP5: USD 10.2M<br>SCP6-2: USD 7.8M<br>合計：USD 23.0M</td>
  <td>🟡 — 大型收購，需監控槓桿影響；BBB+ 在門檻邊緣</td>
  <td>MONITOR — 確認收購規模及資金安排；若槓桿提升需 INVESTIGATE</td>
</tr>
</table>''')

html_parts.append('<hr style="border:none; border-top:1px solid #cccccc; margin:15pt 0;" />')
html_parts.append('<div class="section-header">③ WhiteList 企業評等概況（2026-10 更新）</div>')

# By sector
sector_risks = {
    'Consumer Staples': {'companies': ['Pernod Ricard SA','Hormel Foods Corp.','Nike Inc.'], 'risk': '高關注', 'note': 'Pernod Ricard 降評風險最高；Nike 持續惡化'},
    'Industrials': {'companies': ['Volkswagen AG','ITOCHU Corp','Mitsubishi Electric Corp'], 'risk': '中等', 'note': 'VW 展望負面需核查；其他穩定'},
    'Information Technology': {'companies': ['QUALCOMM Inc','Texas Instruments','Intel Corp'], 'risk': '中等', 'note': 'Intel BBB- 邊緣需監控；TXN / QCOM 穩定'},
    'Health Care': {'companies': ['Gilead Sciences','EssilorLuxottica','Smith & Nephew'], 'risk': '低', 'note': 'EssilorLuxottica 升評；Gilead 正面走向'},
    'Materials': {'companies': ['Sika AG','BASF SE'], 'risk': '低', 'note': '評等穩定'},
}

html_parts.append('''<table>
<tr>
  <th>行業（Sector）</th>
  <th>企業數</th>
  <th>本月事件</th>
  <th>風險等級</th>
</tr>
<tr><td>Industrials</td><td>47</td><td>VW Fitch NEG；Mitsubishi/ITOCHU 股權轉讓；Alfa Laval 收購</td><td>🟡 中</td></tr>
<tr><td>Consumer Discretionary</td><td>34</td><td>Nike S&P A+→A；Ahold Delhaize 大型收購</td><td>🟡 中</td></tr>
<tr><td>Consumer Staples</td><td>34</td><td>Pernod Ricard Moody's NEG；Hormel S&P BBB+；L'Oréal 收購 Onesto</td><td>🔴 高</td></tr>
<tr><td>Health Care</td><td>28</td><td>EssilorLuxottica 升評 A+；Gilead 持續收購；Smith & Nephew J&J 談判破裂</td><td>🟢 低</td></tr>
<tr><td>Materials</td><td>27</td><td>Sika AG Resonac 收購；BASF Fitch Stable 確認</td><td>🟢 低</td></tr>
<tr><td>Information Technology</td><td>23</td><td>QUALCOMM Akeana 小型收購；TXN Moody's Aa3/Stable</td><td>🟢 低</td></tr>
<tr><td>Utilities / Others</td><td>10</td><td>Iberdrola 波蘭子公司出售</td><td>🟢 低</td></tr>
</table>

<div style="margin-top:16px; font-size:17px;">
<strong>WhiteList S&P 評等分佈（2026-10 更新）：</strong><br>
AA 及以上：<strong>''' + str(grades['high']) + f''' 家</strong> ｜ A- 至 BBB+：<strong>{grades['mid']} 家</strong> ｜ BBB 及以下：<strong>{grades['low']} 家</strong><br>
（EssilorLuxottica 10 月升評 A→A+ 已反映）
</div>''')

html_parts.append('<hr style="border:none; border-top:1px solid #cccccc; margin:15pt 0;" />')
html_parts.append('<div class="section-header">④ 待 Derek 確認事項（Action Required）</div>')

html_parts.append('''<div style="background:#fef3c7; border-left:4px solid #d97706; padding:12px 18px; margin-bottom:16px; font-size:17px;">
<strong>以下事項需 Derek 確認或批准：</strong>
<ol>
  <li><strong>Pernod Ricard SA（ESCALATE）</strong>：SCP2 USD 5.4M + SCP6-1 USD 4.1M — 請確認：
    <ul>
      <li>是否啟動信用評等觸發條款查核？</li>
      <li>SCP2 及 SCP6-1 合約中的觸發條件（具體評等水平）？</li>
      <li>是否需與基金管理人溝通退出方案？</li>
    </ul>
  </li>
  <li><strong>Hormel Foods Corp.（待確認持倉）</strong>：S&P A-→BBB+，Moody's A2→A3：
    <ul>
      <li>Hormel 是否在 Siegfried WhiteList？若有持倉，需更新 CreditRatingChanged 工作表；</li>
      <li>若已確認，評估 BBB+ 下是否需要降低敞口。</li>
    </ul>
  </li>
  <li><strong>Volkswagen AG（待核查）</strong>：Fitch NEG 展望：
    <ul>
      <li>確認 Siegfried 各基金是否有 VW 相關應收帳款（直接或通過供應鏈）；</li>
      <li>若有，記錄至 WhiteList 或 CASE3 追蹤列表。</li>
    </ul>
  </li>
  <li><strong>EssilorLuxottica 升評</strong>：CreditRatingChanged 工作表已記錄。無需進一步行動，確認即可。</li>
  <li><strong>Nike Inc.</strong>：CreditRatingChanged 工作表已記錄 A+→A（10-05）。建議每月追蹤至 S&P 展望解除。</li>
</ol>
</div>''')

html_parts.append('''<div style="margin-top:20px; font-size:16px; color:#6b7280;">
<strong>編製說明：</strong>本報告基於 CASE3 系統 2026-10-01 至 2026-10-31 逐日分析（28 個交易日），資料來源為 Bloomberg BB Alert（bbalert@bloomberg.net）及 RefrenceSource.xlsx WhiteList 工作表。7 大風險指標（Entity 變更、M&A、Spin-off、現金流/財報、信用評等、治理/訴訟、系統性風險）已套用於所有有 Siegfried 持倉的事件。<br><br>
本報告由 Cooper 編製，供 Siegfried Capital Management 內部風險管理使用。未獲授權不得對外分享。
</div>

</div>
</body>
</html>''')

html_content = '\n'.join(html_parts)

with open('/tmp/oct_wl_analysis.html', 'w', encoding='utf-8') as f:
    f.write(html_content)

print(f"Report 3 written: {len(html_content)} chars")
