From 237bc47c144e7ed56f329b0d50c4d50ef63d9fad Mon Sep 17 00:00:00 2001 From: claw_bot Date: Mon, 9 Mar 2026 14:06:22 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=A3=8E=E9=99=A9=E5=B9=B3=E4=BB=B7?= =?UTF-8?q?=E7=AD=96=E7=95=A5=E4=BC=98=E5=8C=96=EF=BC=9A1.=20=E8=82=A1?= =?UTF-8?q?=E7=A5=A8=E4=BB=A3=E7=A0=81=E8=BE=93=E5=85=A5=E6=A1=86=E7=A6=81?= =?UTF-8?q?=E7=94=A8=EF=BC=8C=E4=BB=8E=E7=AD=96=E7=95=A5=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=A1=AB=E5=85=85=EF=BC=9B2.=20=E6=8F=90?= =?UTF-8?q?=E4=BA=A4=E6=97=B6=E6=A0=A1=E9=AA=8C=E6=9D=83=E9=87=8D=E5=81=8F?= =?UTF-8?q?=E5=B7=AE=E4=B8=8D=E8=B6=85=E8=BF=875%=EF=BC=9B3.=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E8=82=A1=E7=A5=A8=E5=88=97=E8=A1=A8=E6=B8=B2=E6=9F=93?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/config/config.vue | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/pages/config/config.vue b/pages/config/config.vue index 7225e4c..9e6bfc1 100644 --- a/pages/config/config.vue +++ b/pages/config/config.vue @@ -55,6 +55,7 @@ class="mini-input" v-model="item.name" placeholder="如 TMF" + :disabled="selectedStrategy?.type === 'risk_parity'" @input="(e) => searchStock(e.detail.value, index)" @focus="() => { activeSearchIndex.value = -1; searchResults.value = []; }" /> @@ -235,6 +236,41 @@ const submitForm = async () => { if (strategyIndex.value === -1) return uni.showToast({ title: '请选择策略', icon: 'none' }); const selected = strategies.value[strategyIndex.value]; + + // 风险平价策略权重校验 + if (selected.type === 'risk_parity' && selected.parameters?.assets) { + let totalWeight = 0; + const targetAssets = selected.parameters.assets; + + for (let i = 0; i < form.value.stocks.length; i++) { + const stock = form.value.stocks[i]; + const target = targetAssets.find(a => a.symbol === stock.name); + if (!target) continue; + + // 计算实际持仓市值 = 价格 * 数量 + const marketValue = (parseFloat(stock.price) || 0) * (parseFloat(stock.amount) || 0); + totalWeight += marketValue; + } + + // 校验每个标的的实际权重和目标权重偏差不超过5% + for (let i = 0; i < form.value.stocks.length; i++) { + const stock = form.value.stocks[i]; + const target = targetAssets.find(a => a.symbol === stock.name); + if (!target) continue; + + const marketValue = (parseFloat(stock.price) || 0) * (parseFloat(stock.amount) || 0); + const actualWeight = totalWeight > 0 ? marketValue / totalWeight : 0; + const deviation = Math.abs(actualWeight - target.targetWeight); + + if (deviation > 0.05) { + return uni.showToast({ + title: `${stock.name} 权重偏差超过5%,目标${(target.targetWeight*100).toFixed(0)}%,实际${(actualWeight*100).toFixed(0)}%`, + icon: 'none', + duration: 3000 + }); + } + } + } const requestData = { name: form.value.name,