這一篇文章我們一樣分享opencode這套AI開發工具結合理財心法, 協助您打造專屬的投資組合健檢查助理, 與過去不一樣的地方是我們只要簡單的一句話加上投資組合的資料素材, AI就能夠根據我們的規範與資源, 協助我們針對現有的資產配置進行評估與建議, 大幅度提升效率, 讓我們可以更快速的調整我們的資產配置, 在此之前會建議您參考opencode相關的文章:
當然這邊也不代表作者只推薦opencode, 而是我們接下來的分享將以opencode這套具有免費模型的工具來進行示範, 心法掌握之後, 套用到claude code、codex...等工具皆能夠適用。
Agent Skill架構概覽

關鍵元件:
- 輸入層:支援 CSV / Excel 解析(用 pandas),自動辨識欄位(代號、股數、市值、占比)
- 資料層:透過 opencode 的 @.opencode/commands/finmind.md 呼叫 FinMind,取得最新股價、還原股價、PER、股利等
- 規則層:將理財老師的核心理念寫成可設定規則(例如:曝險比例上限、單一標的不超過 X%、股債比 Y:Z、槓桿ETF上限等)
- 輸出層:產生對比表格 + 建議文字 + 圖表(圓餅圖對比現狀 vs 理念目標)
安裝finmind
FinMind AI Agent Skill 讓你可以直接用自然語言在 Cursor 或 Claude Code 等工具中,快速查詢台美股價、籌碼及財報等 75 種以上的金融數據,並自動生成圖表與分析報告。

詳細安裝請參考: https://finmind.github.io/tutor/AgentSkill/
詳細架構圖

建立Skill骨架
prompt參考如下, 請根據自己偏好的理財理念進行調整。
幫我在.opencode/skills底下建立一個「投資組合理念檢查器」
1. 投資理念參考: <Youtube連結、文章連結、內化知識文件檔...等>。
2. 資產配置檔案格式: csv、excel、json。
3. 格式範例:
代號,股價,股數,市值,占比,類型
0050,xxx,xxx,xxx,xxx,市值型
4. 股價資料來源:@.opencode/commands/finmind.md。
5. 投資哲學規則撰寫(可選): philosophy_rules.yaml
philosophy:
name: "XXX 老師的資產配置法"
description: "股債平衡 + 現金避險 + 槓桿控管"
version: 1.0
rules:
<以下由AI Agent協助生成, 我們僅負責審核>
6. 工作流程: 分析使用者資產配置 -> 根據股票代號取得資料 -> 投資哲學載入。
7. 分析及評估報告:
**Diagnostic Table:**
| Rule | Target | Current | Status | Severity |
|------|--------|---------|--------|----------|
| 股債比 | 60:40 | 52:48 | ⚠️ 偏離 | medium |
| 單一標的上限 | ≤15% | 00687B 22% | ❌ 超標 | high |
| 槓桿ETF上限 | ≤20% | 28% | ❌ 超標 | high |
| 現金水位 | ≥5% | 14% | ✅ 合格 | - |
**Adjustment Suggestions:**
1. 00687B 佔比 22% 超過 15% 上限 → 建議減持至 15% 以下
2. 槓桿ETF (00631L+00675L) 合計 28% 超過 20% 上限 → 建議逐步減碼 8%
3. 股債比偏離目標 → 建議將多餘現金或減碼債券轉至股票
骨架概覽:
.opencode/skills/portfolio-philosophy-checker/
├── SKILL.md # 主指令 — 定義流程、資料源、分析邏輯
└── philosophy_rules.yaml # 可設定理論規則(換老師只改這檔)
philosophy_rules.yaml範本:
# philosophy_rules.yaml
philosophy:
name: "穩健平衡投資法"
rules:
asset_allocation:
stock_bond_ratio: [60, 40] # 股債比目標 6:4
diversification:
max_single_position: 15 # 單一標的不超過 15%
concentration:
max_leverage_etf: 10 # 槓桿型標的上限制 10%
cash_reserve:
min_cash: 5 # 至少保留 5% 現金
SKILL.md範本:
---
name: portfolio-philosophy-checker
description: Analyze a user's asset portfolio against a configurable investment philosophy and provide actionable adjustment suggestions.
---
# Portfolio Philosophy Checker
Analyze a user's asset portfolio against a configurable investment philosophy and provide actionable adjustment suggestions.
## Usage
```bash
# Load the skill in opencode
/load-skill portfolio-philosophy-checker
# Then ask naturally:
"幫我檢視資產配置是否符合 xxx 老師的理念"
"分析我的 portfolio 並給調整建議"
"檢查目前持股的股債比是否合理"
```
## Input Format
Support these user-supplied files (auto-detect by extension):
| Format | File Pattern | Notes |
|--------|-------------|-------|
| CSV | `*.csv` | Must contain: 代號, 股價, 股數, 市值, 占比, 類型 |
| Excel | `*.xlsx` / `*.xls` | Same columns as CSV |
| JSON | `*.json` | Keys: `symbol`, `price`, `shares`, `market_value`, `weight`, `type` |
### Example CSV (matching existing project format):
```csv
代號,股價,股數,市值,占比,類型
Symbol_A,100.0,1000,100000,10%,核心持股
Symbol_B,50.0,2000,100000,10%,槓桿基金
Symbol_C,30.0,5000,150000,15%,高股息
Symbol_D,25.0,8000,200000,20%,債券
現金,1,450000,450000,45%,現金
```
Place the file anywhere under the project root. The skill will search for `*資產*`, `*portfolio*`, `*holding*` patterns.
## Investment Philosophy Configuration
The core philosophy rules are defined in `philosophy_rules.yaml` (same directory as this skill).
### Built-in Rule Categories
| Category | Example Rule | Description |
|----------|-------------|-------------|
| `asset_allocation` | `stock_bond_ratio: 60:40` | Target allocation between stocks/equity and bonds |
| `diversification` | `max_single_position: 15%` | Maximum allowed weight per single position |
| `concentration` | `max_leverage_etf: 20%` | Limit on leveraged/inverse ETFs |
| `region_exposure` | `max_tw_stock: 50%` | Maximum Taiwan stock exposure |
| `sector_exposure` | `max_tech: 40%` | Maximum single sector exposure |
| `cash_reserve` | `min_cash: 5%` | Minimum cash holding |
| `risk_control` | `max_drawdown: 20%` | Maximum acceptable drawdown |
| `yield_requirement` | `min_dividend_yield: 3%` | Minimum portfolio dividend yield |
## Data Sources
Uses `@.opencode/commands/finmind.md` to fetch live data:
| Data Needed | FinMind Dataset | Purpose |
|------------|----------------|---------|
| Current price | `TaiwanStockPrice` / `USStockPrice` | Recalculate market value & weight |
| Adjusted price | `TaiwanStockPriceAdj` | Total return calculation |
| PER / PBR | `TaiwanStockPER` | Valuation check |
| Dividend | `TaiwanStockDividend` | Yield calculation |
| Institutional flow | `TaiwanStockInstitutionalInvestorsBuySell` | Recent buy/sell signal |
## Analysis Workflow
### Step 1: Parse Portfolio
Read the user's asset file, normalize column names, calculate current weights.
### Step 2: Fetch Live Data
For each holding:
- Call FinMind via the command reference to get latest price
- Calculate current market value and actual weight
- Get dividend yield for yield-type assets
### Step 3: Apply Philosophy Rules
Compare current allocation against each rule in `philosophy_rules.yaml`:
```
For each rule:
if current_value violates rule_threshold:
record as VIOLATION with severity (low/medium/high)
store: rule_name, current, target, delta, severity
```
### Step 4: Generate Report
**Diagnostic Table:**
| Rule | Target | Current | Status | Severity |
|------|--------|---------|--------|----------|
| 股債比 | 60:40 | 52:48 | ⚠️ 偏離 | medium |
| 單一標的上限 | ≤15% | 00687B 22% | ❌ 超標 | high |
| 槓桿ETF上限 | ≤20% | 28% | ❌ 超標 | high |
| 現金水位 | ≥5% | 14% | ✅ 合格 | - |
**Adjustment Suggestions:**
1. 00687B 佔比 22% 超過 15% 上限 → 建議減持至 15% 以下
2. 槓桿ETF (00631L+00675L) 合計 28% 超過 20% 上限 → 建議逐步減碼 8%
3. 股債比偏離目標 → 建議將多餘現金或減碼債券轉至股票
### Step 5: Visualization (Optional)
Generate comparison charts:
- Pie chart: current allocation vs target allocation
- Bar chart: each rule status (green/yellow/red)
- Treemap: position sizes with violation highlights
## Configuration Tips
Users should edit `philosophy_rules.yaml` to match their chosen teacher's philosophy:
```yaml
# Example: 保守型價值投資
philosophy:
name: "XXX 老師價值投資法"
rules:
asset_allocation:
stock_bond_ratio: [50, 50] # stock:bond
diversification:
max_single_position: 10 # %
concentration:
max_leverage_etf: 0 # no leverage
region_exposure:
max_tw_stock: 40
max_us_stock: 60
cash_reserve:
min_cash: 10
yield_requirement:
min_dividend_yield: 4
```
## Customization
To adapt for a different teacher/philosophy, only edit `philosophy_rules.yaml` — no code changes needed.
To add new rule categories, extend the `rules` section and the analysis script will auto-detect them.
## Integration with opencode
This skill is designed to work alongside:
- `@.opencode/commands/finmind.md` — for all financial data queries
- Existing `query_stock.py` / `query_etf_adj.py` — for reusable data extraction patterns
- `AGENTS.md` — for project-level conventions (script cleanup, reusable patterns)
實際案例
幫我檢視資產配置是否符合 <文章、Youtube連結、筆記...> 老師的投資理念
1. 務必使用近一年的核心理念。
2. 股價務必按照skill提供工具抓取最新資訊。
分析報告參考如下:

結語
AI Agent已經是這個時代必要的技能了, 我們只要給予足夠的資訊、規範、核心理念, AI就能夠自動根據我們的資料進行檢核、評估、分析與建議, 除了大幅提升效率之外, 更把我們的工作流程進行SOP, 甚至可複製, 只要我們將這樣的代理規則制定好, AI就會按照指令幫我們做事, 過去的我們從做事情的角色進化成制定規則、審核規則、調整優化方向的轉變, 這已經是不得不改變的趨勢了, 就讓我們共同學習並跟上吧! 共勉之。















