PageSourceSearch

https://xynergy.ai/_next/static/chunks/7083.b7095397a176c125.js

js xynergy.ai collected 2026-10-05 16:02:31 UTC 10,593 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[7083],{27083:(e,s,t)=>{t.r(s),t.d(s,{default:()=>N});var l=t(85047),a=t(31615),n=t(73521),i=t(82520),r=t(21582),c=t(21410),d=t(21016),x=t(2962),o=t(7004),m=t(11787),h=t(94430),u=t(61414);let j=(0,t(46775).A)("grid-3x3",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M3 9h18",key:"1pudct"}],["path",{d:"M3 15h18",key:"5xshup"}],["path",{d:"M9 3v18",key:"fh3hqa"}],["path",{d:"M15 3v18",key:"14nvp0"}]]);var p=t(35617),f=t(87884),b=t(60996),g=t(91595);function N(){let{user:e,viewingUserId:s}=(0,n.A)(),[t,N]=(0,a.useState)("1y"),[y,k]=(0,a.useState)(null),[v,w]=(0,a.useState)(!1),[A,C]=(0,a.useState)(null),[Z,F]=(0,a.useState)(!1),R=s||e?.uid,S=(0,a.useCallback)(async()=>{if(R&&e){w(!0),C(null);try{let s=await e.getIdToken(),l=new URLSearchParams({period:t});R&&l.set("userId",R);let a=await fetch(`/api/portfolio/risk-analysis?${l.toString()}`,{headers:{Authorization:`Bearer ${s}`}}),n=await a.json();if(!a.ok)throw Error(n?.error?.message||"分析失敗");k(n.data)}catch(e){C(e instanceof Error?e.message:"無法取得風險分析結果")}finally{w(!1)}}},[R,e,t]);(0,a.useEffect)(()=>{R&&e&&S()},[S,R,e]),(0,g.py)();let B=y?Object.keys(y.weights):[],W=B.length>20&&!Z?B.map(e=>({s:e,w:y.weights[e]})).sort((e,s)=>s.w-e.w).slice(0,20).map(e=>e.s):B,T=[];if(y)for(let e=0;e<W.length;e++)for(let s=0;s<W.length;s++){let t=y.correlationMatrix[W[e]]?.[W[s]]??0;T.push([s,e,Math.round(100*t)/100])}let L=[...y?.riskContribution??[]].sort((e,s)=>s.riskContributionPct-e.riskContributionPct).slice(0,15).map(e=>({name:e.name||e.symbol,y:e.riskContributionPct})),M=[...y?.riskContribution??[]].sort((e,s)=>s.riskContributionPct-e.riskContributionPct).slice(0,15),P=y?Object.entries(y.weights).map(([e,s])=>({name:e,y:Math.round(1e3*s)/10})):[],$=y&&W.length>0?{chart:{type:"heatmap",height:320,backgroundColor:"transparent"},title:{text:null},xAxis:{categories:W,title:null},yAxis:{categories:W,title:null},colorAxis:{min:-1,max:1,minColor:"#ef4444",maxColor:"#22c55e",startOnTick:!0,endOnTick:!0},series:[{type:"heatmap",name:"相關性",data:T,dataLabels:{enabled:W.length<=10,format:"{point.value:.2f}"}}],tooltip:{formatter:function(){let e=W[this.x]??String(this.x),s=W[this.y]??String(this.y),t=this.value;return`<b>${e} \xd7 ${s}</b>: ${"number"==typeof t?t.toFixed(2):t}`}},credits:{enabled:!1}}:null,O=L.length>0?{chart:{type:"bar",height:320,backgroundColor:"transparent"},title:{text:null},xAxis:{categories:L.map(e=>e.name),title:null},yAxis:{title:{text:"風險貢獻 (%)"}},series:[{type:"bar",name:"風險貢獻",data:L.map(e=>e.y)}],plotOptions:{bar:{dataLabels:{enabled:!0,format:"{y:.1f}%"}}},credits:{enabled:!1}}:null,V=P.length>0?{chart:{type:"pie",height:320,backgroundColor:"transparent"},title:{text:null},series:[{type:"pie",name:"權重",data:P}],plotOptions:{pie:{dataLabels:{enabled:!0,format:"{point.percentage:.1f}%"}}},credits:{enabled:!1}}:null;return R?(0,l.jsxs)("div",{className:"space-y-6",children:[(0,l.jsxs)("div",{className:"flex flex-wrap items-center gap-4",children:[(0,l.jsxs)("div",{className:"flex items-center gap-2",children:[(0,l.jsx)("span",{className:"text-sm text-muted-foreground",children:"分析區間"}),(0,l.jsxs)(r.l6,{value:t,onValueChange:e=>N(e),children:[(0,l.jsx)(r.bq,{className:"w-[120px]",children:(0,l.jsx)(r.yv,{})}),(0,l.jsxs)(r.gC,{children:[(0,l.jsx)(r.eb,{value:"1y",children:"1 年"}),(0,l.jsx)(r.eb,{value:"2y",children:"2 年"}),(0,l.jsx)(r.eb,{value:"3y",children:"3 年"})]})]})]}),(0,l.jsx)(c.$,{onClick:S,disabled:v,size:"sm",children:v?(0,l.jsx)(m.A,{className:"h-4 w-4 animate-spin"}):"重新分析"})]}),v&&!y&&(0,l.jsx)("div",{className:"flex items-center justify-center py-16",children:(0,l.jsx)(m.A,{className:"h-8 w-8 animate-spin text-muted-foreground"})}),A&&(0,l.jsxs)(d.Fc,{variant:"destructive",children:[(0,l.jsx)(o.A,{className:"h-4 w-4"}),(0,l.jsx)(d.XL,{children:"分析失敗"}),(0,l.jsx)(d.TN,{children:A})]}),y&&y.portfolioValue>0&&(0,l.jsxs)("div",{className:v?"opacity-60 pointer-events-none relative":void 0,children:[v&&(0,l.jsx)("div",{className:"absolute inset-0 z-10 flex items-start justify-center pt-8",children:(0,l.jsx)(m.A,{className:"h-6 w-6 animate-spin text-muted-foreground"})}
1),y.excludedSymbols.length>0&&(0,l.jsx)(d.Fc,{className:"mb-4",children:(0,l.jsxs)(d.TN,{children:["以下標的因歷史資料不足已排除:",y.excludedSymbols.join(", ")]})}),(0,l.jsxs)("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-3",children:[(0,l.jsxs)(i.Zp,{children:[(0,l.jsx)(i.aR,{className:"pb-2",children:(0,l.jsx)(i.ZB,{className:"text-sm font-medium",children:"投資組合價值"})}),(0,l.jsxs)(i.Wu,{children:[(0,l.jsx)("p",{className:"text-2xl font-bold tabular-nums",children:(0,p.C)(y.portfolioValue)}),(0,l.jsx)("p",{className:"text-xs text-muted-foreground mt-1",children:"目前納入分析的台股總市值"})]})]}),(0,l.jsxs)(i.Zp,{children:[(0,l.jsx)(i.aR,{className:"pb-2",children:(0,l.jsx)(i.ZB,{className:"text-sm font-medium",children:"年化報酬"})}),(0,l.jsxs)(i.Wu,{children:[(0,l.jsxs)("p",{className:"text-2xl font-bold tabular-nums",children:[(100*y.portfolioReturn).toFixed(2),"%"]}),(0,l.jsx)("p",{className:"text-xs text-muted-foreground mt-1",children:"依日報酬均值 \xd7 252 估算"})]})]}),(0,l.jsxs)(i.Zp,{children:[(0,l.jsx)(i.aR,{className:"pb-2",children:(0,l.jsx)(i.ZB,{className:"text-sm font-medium",children:"年化波動率"})}),(0,l.jsxs)(i.Wu,{children:[(0,l.jsxs)("p",{className:"text-2xl font-bold tabular-nums",children:[(100*y.portfolioVolatility).toFixed(2),"%"]}),(0,l.jsx)("p",{className:"text-xs text-muted-foreground mt-1",children:"價格起伏幅度,愈高代表波動愈大、風險愈高"})]})]}),(0,l.jsxs)(i.Zp,{children:[(0,l.jsx)(i.aR,{className:"pb-2",children:(0,l.jsx)(i.ZB,{className:"text-sm font-medium",children:"夏普比率"})}),(0,l.jsxs)(i.Wu,{children:[(0,l.jsx)("p",{className:"text-2xl font-bold tabular-nums",children:y.sharpeRatio.toFixed(2)}),(0,l.jsx)("p",{className:"text-xs text-muted-foreground mt-1",children:"考量風險後的報酬效率,愈高愈好(通常 > 1 較佳)"})]})]}),(0,l.jsxs)(i.Zp,{children:[(0,l.jsx)(i.aR,{className:"pb-2",children:(0,l.jsx)(i.ZB,{className:"text-sm font-medium",children:"索提諾比率"})}),(0,l.jsxs)(i.Wu,{children:[(0,l.jsx)("p",{className:"text-2xl font-bold tabular-nums",children:y.sortinoRatio.toFixed(2)}),(0,l.jsx)("p",{className:"text-xs text-muted-foreground mt-1",children:"只考慮下跌波動的報酬效率,愈高愈好"})]})]}),(0,l.jsxs)(i.Zp,{children:[(0,l.jsx)(i.aR,{className:"pb-2",children:(0,l.jsx)(i.ZB,{className:"text-sm font-medium",children:"VaR 95%(歷史)"})}),(0,l.jsxs)(i.Wu,{children:[(0,l.jsx)("p",{className:"text-2xl font-bold tabular-nums",children:(0,p.C)(y.var95Amount)}),(0,l.jsx)("p",{className:"text-xs text-muted-foreground mt-1",children:"歷史約 5% 機率單日損失超過此金額"}),(0,l.jsxs)("p",{className:"text-xs text-muted-foreground",children:[(100*y.var95Ratio).toFixed(2),"% 日損失"]})]})]}),(0,l.jsxs)(i.Zp,{children:[(0,l.jsx)(i.aR,{className:"pb-2",children:(0,l.jsx)(i.ZB,{className:"text-sm font-medium",children:"最大回撤"})}),(0,l.jsxs)(i.Wu,{children:[(0,l.jsxs)("p",{className:"text-2xl font-bold tabular-nums",children:[(100*y.maxDrawdown).toFixed(2),"%"]}),(0,l.jsx)("p",{className:"text-xs text-muted-foreground mt-1",children:"從高點到最低點曾出現的最大跌幅百分比"})]})]})]}),(0,l.jsxs)("p",{className:"text-xs text-muted-foreground",children:["無風險利率:",(100*y.riskFreeRate).toFixed(2),"% | 基準:","0050"===y.benchmarkSymbol?"0050 台灣50":y.benchmarkSymbol,"unavailable"===y.benchmarkStatus&&"(資料暫不可用)"]}),y.riskContribution.length>0&&(0,l.jsxs)(i.Zp,{children:[(0,l.jsxs)(i.aR,{children:[(0,l.jsxs)(i.ZB,{className:"flex items-center gap-2",children:[(0,l.jsx)(h.A,{className:"h-5 w-5"}),"風險貢獻"]}),(0,l.jsx)("p",{className:"text-sm text-muted-foreground font-normal mt-1",children:"各標的對整體組合風險的貢獻占比,愈長代表該標的愈拉高整體波動"})]}),(0,l.jsxs)(i.Wu,{children:[O&&(0,l.jsx)(b.A,{highcharts:f.A,options:O,immutable:!1}),(0,l.jsxs)(x.XI,{className:"mt-4",children:[(0,l.jsx)(x.A0,{children:(0,l.jsxs)(x.Hj,{children:[(0,l.jsx)(x.nd,{children:"標的"}),(0,l.jsx)(x.nd,{children:"權重"}),(0,l.jsx)(x.nd,{children:"波動率"}),(0,l.jsx)(x.nd,{children:"風險貢獻"})]})}),(0,l.jsx)(x.BF,{children:M.map(e=>(0,l.jsxs)(x.Hj,{children:[(0,l.jsx)(x.nA,{children:e.name||e.symbol}),(0,l.jsxs)(x.nA,{children:[(100*e.weight).toFixed(1),"%"]}),(0,l.jsxs)(x.nA,{children:[(100*e.volatility).toFixed(2),"%"]}),(0,l.jsxs)(x.nA,{children:[e.riskContributionPct.toFixed(1),"%"]})]},e.symbol))})]})]})]}),P.length>0&&(0,l.jsxs)(i.Zp,{children:[(0,l.jsxs)(i.aR,{children:[(0,l.jsxs)(i.ZB,{className:"flex items-center gap-2",children:[(0,l.jsx)(u.A,{className:"h-5 w-5"}),"集中度"]}),(0,l.jsx)("p",{className:"text-sm text-muted-foreground font-normal mt-1",children:"各標的占組合權重比例;單一標的權重過高代表集中風險較大"}),(0,l.jsxs)("p",{className:"text-sm text-muted-foreground",children:["單一標的最大權重:",(100*y.concentration.maxSingleWeight).toFixed(1),"%"]})]}),(0,l.jsx)(i.Wu,{children:V&&(0,l.jsx)(b.A,{highcharts:f.A,options:V,immutable:!1})})]}),W.length>0&&(0,l.jsxs)(i.Zp,{children:[(0,l.jsxs)(i.aR,{children:[(0,l.jsxs)(i.ZB,{className:"flex items-center gap-2",children:[(0,l.jsx)(j,{className:"h-5 w-5"}),"相關性矩陣"]}),(0,l.jsx)("p",{className:"text-sm text-muted-foreground font-normal mt-1",children:"兩兩標的報酬走勢的相關程度(-1~1);愈接近 1 愈同向、分散效果愈差"}),B.length>20&&(0,l.jsx)(c.$,{variant:"outline",size:"sm",onClick:()=>F(e=>!e),children:Z?"顯示 Top 20":"顯示全部"})]}),(0,l.jsx)(i.Wu,{children:$?(0,l.jsx)(b.A,{highcharts:f.A,options:$,immutable:!1}):(0,l.jsx)("p",{className:"text-muted-foreground",children:"無足夠資料顯示相關性矩陣"})})]})]}),!v&&(!y||0===y.portfolioValue)&&!A&&R&&(0,l.jsxs)(d.Fc,{children:[(0,l.jsx)(o.A,{className:"h-4 w-4"}),(0,l.jsx)(d.XL,{children:"尚無可分析之台股部位"}),(0,l.jsx)(d.TN,{children:"請先新增台股投資標的,系統將依歷史價格計算投資組合風險指標。"})]})]}):(0,l.jsxs)(d.Fc,{children:[(0,l.jsx)(o.A,{className:"h-4 w-4"}),(0,l.jsx)(d.XL,{children:"請先登入"}),(0,l.jsx)(d.TN,{children:"需要登入才能使用風險分析功能。"})]})}}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.