关于 trader-hand-skill
面向学习技术分析与风险管理的交易者,提供交易参考资料。内容介绍指标公式、图表形态,以及仓位和组合风险计算。
主要功能
- 01技术指标公式与解读
- 02蜡烛图形态参考
- 03支撑位与阻力位方法
- 04仓位规模与风险公式
- 05交易指标使用指引
适用场景
- 01复核 RSI、MACD 或 ATR 计算
- 02解读蜡烛图形态
- 03估算仓位规模与止损位
- 04比较技术指标
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ rightnow-ai/ openfang --skill trader-hand-skill安装后在 Claude Code 中输入/trader-hand-skill确认已加载。
附带文件HAND.toml
详细介绍
交易专家知识
参考知识
1. 技术分析指标参考
RSI(相对强弱指数)
Formula: RSI = 100 - (100 / (1 + RS))
Where: RS = Average Gain / Average Loss over N periods (default N = 14)
Step-by-step calculation:
1. For each period, compute change = Close(t) - Close(t-1)
2. Gains = max(change, 0), Losses = abs(min(change, 0))
3. First average: simple mean of first 14 gains/losses
4. Subsequent: AvgGain = (PrevAvgGain * 13 + CurrentGain) / 14 (Wilder smoothing)
5. RS = AvgGain / AvgLoss
6. RSI = 100 - (100 / (1 + RS))
Worked example (14-period):
Avg Gain over 14 periods = 1.02
Avg Loss over 14 periods = 0.68
RS = 1.02 / 0.68 = 1.50
RSI = 100 - (100 / (1 + 1.50)) = 100 - 40 = 60.0
解读:
- RSI < 30:超卖区域(潜在买入信号)
- RSI > 70:超买区域(潜在卖出信号)
- RSI = 50:中性——价格动能均衡
RSI 高级信号:
| 信号 | 描述 | 强度 |
|---|---|---|
| 看跌背离 | 价格创出新高,RSI 创出更低的高点 | 强烈的反转警示 |
| 看涨背离 | 价格创出新低,RSI 创出更高的低点 | 强烈的反转警示 |
| 看涨失败摆动 | RSI 跌破 30,反弹,回升至 30 以上,并突破此前 RSI 高点 | 非常强烈的买入信号 |
| 看跌失败摆动 | RSI 升破 70,回落,反弹至 70 以下,并跌破此前 RSI 低点 | 非常强烈的卖出信号 |
| 区间转换 | 上升趋势中 RSI 在 40-80 之间波动;下降趋势中在 20-60 之间波动 | 趋势确认 |
**最佳实践:**切勿将 RSI 作为唯一信号。应结合趋势方向(移动平均线)和成交量。在强劲趋势中,RSI 可能会长时间处于超买或超卖状态。
MACD(移动平均收敛发散指标)
MACD Line = EMA(12) - EMA(26)
Signal Line = EMA(9) of MACD Line
Histogram = MACD Line - Signal Line
EMA formula: EMA(t) = Price(t) * k + EMA(t-1) * (1 - k)
Where: k = 2 / (N + 1)
For EMA(12): k = 2/13 = 0.1538
For EMA(26): k = 2/27 = 0.0741
Worked example:
EMA(12) = 155.20
EMA(26) = 152.80
MACD Line = 155.20 - 152.80 = 2.40
Previous Signal Line = 1.80
Signal Line = 2.40 * (2/10) + 1.80 * (8/10) = 0.48 + 1.44 = 1.92
Histogram = 2.40 - 1.92 = 0.48 (positive = bullish momentum increasing)
解读:
| 信号 | 条件 | 强度 |
|---|---|---|
| 看涨交叉 | MACD 上穿信号线 | 中等买入信号 |
| 看跌交叉 | MACD 下穿信号线 | 中等卖出信号 |
| 零轴看涨交叉 | MACD 上穿零轴 | 趋势转为看涨 |
| 零轴看跌交叉 | MACD 下穿零轴 | 趋势转为看跌 |
| 柱状图扩大 | 柱体变高 | 动能加速 |
| 柱状图收缩 | 柱体变短 | 动能减弱,可能即将反转 |
| 看涨背离 | 价格创出新低,MACD 创出更高的低点 | 强烈的反转信号 |
| 看跌背离 | 价格创出新高,MACD 创出更低的高点 | 强烈的反转信号 |
布林带
Middle Band = SMA(20)
Upper Band = SMA(20) + 2 * StdDev(20)
Lower Band = SMA(20) - 2 * StdDev(20)
Bandwidth = (Upper - Lower) / Middle
%B = (Price - Lower) / (Upper - Lower)
Worked example:
SMA(20) = 150.00
StdDev(20) = 3.50
Upper = 150.00 + 2 * 3.50 = 157.00
Lower = 150.00 - 2 * 3.50 = 143.00
Bandwidth = (157.00 - 143.00) / 150.00 = 0.0933 (9.33%)
Current price = 155.00
%B = (155.00 - 143.00) / (157.00 - 143.00) = 12/14 = 0.857
Interpretation: Price is 85.7% of the way from lower to upper band — near upper band
布林带关键信号:
| 信号 | 条件 | 含义 |
|---|---|---|
| 收窄 | 带宽处于 6 个月低位 | 波动性收缩,大幅波动即将到来 |
| 收窄后向上突破 | 收窄后价格突破上轨 | 强烈的看涨突破 |
| 收窄后向下突破 | 收窄后价格跌破下轨 | 强烈的看跌突破 |
| 沿上轨运行 | 价格紧贴上轨,且中轨上升 | 强劲的上升趋势——切勿做空 |
| 沿下轨运行 | 价格紧贴下轨,且中轨下降 | 强劲的下降趋势——切勿买入 |
| 均值回归触轨 | 价格触及外轨,%B 反转 | 可能回归至中轨 |
| W 底 | 价格两次触及下轨,第二个低点的 %B 更高 | 看涨反转形态 |
| M 顶 | 价格两次触及上轨,第二个高点的 %B 更低 | 看跌反转形态 |
VWAP(成交量加权平均价格)
VWAP = Cumulative(Typical Price * Volume) / Cumulative(Volume)
Typical Price = (High + Low + Close) / 3
Worked example (first 3 bars of the day):
Bar 1: TP = (101+99+100)/3 = 100.00, Vol = 10,000 -> cumTP*V = 1,000,000
Bar 2: TP = (102+100+101)/3 = 101.00, Vol = 15,000 -> cumTP*V = 2,515,000
Bar 3: TP = (103+101+102)/3 = 102.00, Vol = 8,000 -> cumTP*V = 3,331,000
Cumulative Volume = 33,000
VWAP = 3,331,000 / 33,000 = 100.94
用法:
- 机构基准:价格 > VWAP 时买方占优;价格 < VWAP 时卖方占优
- 日内支撑位/阻力位:上升趋势中,VWAP 充当动态支撑位;下降趋势中,充当阻力位
- 入场过滤条件:仅在价格回落至 VWAP 时买入(不要追逐大幅延伸的行情)
- 标准差:VWAP +1/-1 和 +2/-2 标准差带可用作止盈目标
- 每日重置:切勿将 VWAP 延续至下一个交易时段——它是日内指标
移动平均线
SMA(N) = (Close_1 + Close_2 + ... + Close_N) / N
EMA(N) = Close * (2/(N+1)) + PrevEMA * (1 - 2/(N+1))
Key Moving Averages:
EMA(9) — very short-term trend (scalping, day trading)
EMA(20) — short-term trend
EMA(50) — medium-term trend
SMA(100) — intermediate trend
SMA(200) — long-term trend (institutional benchmark)
关键交叉信号:
| 交叉 | 名称 | 含义 | 可靠性 |
|---|---|---|---|
| 50 MA > 200 MA | 黄金交叉 | 看涨趋势反转 | 高(滞后约 2 周) |
| 50 MA < 200 MA | 死亡交叉 | 看跌趋势反转 | 高(滞后约 2 周) |
| 9 EMA > 21 EMA | 快速看涨交叉 | 短期动能转变 | 中等 |
| 价格 > 200 SMA | 高于长期趋势 | 看涨市场状态 | 极高 |
| 价格 < 200 SMA | 低于长期趋势 | 看跌市场状态 | 极高 |
移动平均线带(20/50/100/200 MA 均呈发散状):表明趋势非常强劲。当所有均线按顺序排列(上升趋势中为 20 > 50 > 100 > 200)时,趋势的可靠性很高。
ATR(平均真实波幅)
True Range = max(High - Low, |High - PrevClose|, |Low - PrevClose|)
ATR(14) = Simple or Wilder Moving Average of True Range over 14 periods
Worked example:
Today: High = 105, Low = 101, PrevClose = 102
TR = max(105-101, |105-102|, |101-102|) = max(4, 3, 1) = 4
If ATR(14) was 3.50 yesterday:
ATR(14) = (3.50 * 13 + 4) / 14 = (45.50 + 4) / 14 = 3.536
实际应用:
| 用例 | 公式 | 示例 |
|---|---|---|
| 止损位设置 | 入场价 - 2 * ATR | 入场价 $100,ATR $2.50 -> 止损位 $95.00 |
| 止盈目标 | 入场价 + 3 * ATR | 入场价 $100,ATR $2.50 -> 目标价 $107.50 |
| 仓位规模 | 风险金额 / ATR | $200 风险 / $2.50 ATR = 80 股 |
| 波动率筛选 | ATR > 阈值 | 仅在 ATR > 日均值时交易(避免市场沉寂) |
| 移动止损 | 最高收盘价 - 3 * ATR | 随着价格上涨锁定利润 |
成交量分析
OBV (On-Balance Volume):
If Close > PrevClose: OBV = PrevOBV + Volume
If Close < PrevClose: OBV = PrevOBV - Volume
If Close = PrevClose: OBV = PrevOBV
Volume Rate of Change: VROC = (Volume - Volume_N_ago) / Volume_N_ago * 100
成交量确认规则:
| 价格走势 | 成交量 | 解读 |
|---|---|---|
| 价格上涨 | 成交量增加 | 强劲看涨——走势可信 |
| 价格上涨 | 成交量减少 | 涨势疲弱——可能反转 |
| 价格下跌 | 成交量增加 | 强劲看跌——恐慌抛售或破位 |
| 价格下跌 | 成交量减少 | 跌势疲弱——可能接近底部 |
| 突破 | 成交量 > 20 日均值的 150% | 突破得到确认——执行交易 |
| 突破 | 成交量 < 均值 | 可能是假突破——等待或反向交易 |
| 成交量高潮 | 成交量极度飙升(均值的 3 倍以上) | 可能是耗竭/反转点 |
支撑位与阻力位
斐波那契回撤位:
After a move from Low (L) to High (H):
23.6% level = H - (H - L) * 0.236
38.2% level = H - (H - L) * 0.382
50.0% level = H - (H - L) * 0.500
61.8% level = H - (H - L) * 0.618 (Golden Ratio — strongest level)
78.6% level = H - (H - L) * 0.786
Worked example (move from $80 to $120):
Range = $40
23.6% = 120 - 40 * 0.236 = 120 - 9.44 = $110.56
38.2% = 120 - 40 * 0.382 = 120 - 15.28 = $104.72
50.0% = 120 - 40 * 0.500 = 120 - 20.00 = $100.00
61.8% = 120 - 40 * 0.618 = 120 - 24.72 = $95.28 (most likely bounce)
78.6% = 120 - 40 * 0.786 = 120 - 31.44 = $88.56
枢轴点(标准):
PP = (High + Low + Close) / 3
S1 = 2 * PP - High
S2 = PP - (High - Low)
R1 = 2 * PP - Low
R2 = PP + (High - Low)
Worked example (prev day: High=155, Low=148, Close=152):
PP = (155 + 148 + 152) / 3 = 151.67
S1 = 2 * 151.67 - 155 = 148.33
S2 = 151.67 - (155 - 148) = 144.67
R1 = 2 * 151.67 - 148 = 155.33
R2 = 151.67 + (155 - 148) = 158.67
2. 蜡烛图形态
单根蜡烛形态
| 形态 | 信号 | 实体 | 影线 | 所需背景 |
|---|---|---|---|---|
| 十字星 | 犹豫不决 | 开盘价 = 收盘价(或接近) | 两侧均有长影线 | 出现在支撑位/阻力位 = 反转 |
| 锤子线 | 看涨反转 | 较小,位于蜡烛顶部 | 下影线 > 实体的 2 倍 | 必须出现在下跌趋势底部 |
| 倒锤线 | 看涨反转 | 较小,位于蜡烛底部 | 上影线 > 实体的 2 倍 | 出现在下跌趋势底部,需确认 |
| 射击之星 | 看跌反转 | 较小,位于蜡烛底部 | 上影线 > 实体的 2 倍 | 必须出现在上涨趋势顶部 |
| 上吊线 | 看跌反转 | 较小,位于蜡烛顶部 | 下影线 > 实体的 2 倍 | 出现在上涨趋势顶部(形状与锤子线相同) |
| 光头光脚阳线 | 强劲延续 | 完整绿色实体,无影线 | 无 | 买盘压力强劲 |
| 光头光脚阴线 | 强劲延续 | 完整红色实体,无影线 | 无 | 卖盘压力强劲 |
| 纺锤线 | 犹豫不决 | 居中的小实体 | 两侧影线等长 | 趋势可能正在失去动能 |
| 蜻蜓十字星 | 看涨反转 | 开盘价 = 收盘价 = 最高价 | 仅有长下影线 | 出现在支撑位 = 强烈反转信号 |
| 墓碑十字星 | 看跌反转 | 开盘价 = 收盘价 = 最低价 | 仅有长上影线 | 出现在阻力位 = 强烈反转信号 |
多根 K 线形态
| 形态 | 信号 | 描述 | 可靠性 |
|---|---|---|---|
| 看涨吞没 | 向上反转 | 大型绿色 K 线完全吞没前一根红色 K 线 | 在支撑位处较高 |
| 看跌吞没 | 向下反转 | 大型红色 K 线完全吞没前一根绿色 K 线 | 在阻力位处较高 |
| 早晨之星 | 看涨反转 | 红色 K 线、小实体/十字星(带跳空),以及大型绿色 K 线 | 非常高 |
| 黄昏之星 | 看跌反转 | 绿色 K 线、小实体/十字星(带跳空),以及大型红色 K 线 | 非常高 |
| 三白兵 | 强烈看涨 | 连续三根大型绿色 K 线,每根收盘价都更高 | 非常高 |
| 三乌鸦 | 强烈看跌 | 连续三根大型红色 K 线,每根收盘价都更低 | 非常高 |
| 看涨孕线 | 潜在反转 | 先是一根大型红色 K 线,随后是一根实体包含在前者实体内的小型绿色 K 线 | 中等(需要确认) |
| 看跌孕线 | 潜在反转 | 先是一根大型绿色 K 线,随后是一根实体包含在前者实体内的小型红色 K 线 | 中等(需要确认) |
| 镊子底 | 看涨反转 | 两根 K 线在支撑位处具有相同的最低价 | 高 |
| 镊子顶 | 看跌反转 | 两根 K 线在阻力位处具有相同的最高价 | 高 |
| 刺透形态 | 看涨反转 | 红色 K 线之后,绿色 K 线开盘价低于前者最低价,收盘价高于前者实体的 50% 位置 | 中等偏高 |
| 乌云盖顶 | 看跌反转 | 绿色 K 线之后,红色 K 线开盘价高于前者最高价,收盘价低于前者实体的 50% 位置 | 中等偏高 |
3. 风险管理公式
仓位规模(固定比例法)
Position Size (shares) = Account Risk Amount / (Entry Price - Stop Loss Price)
Account Risk Amount = Portfolio Value * Risk Per Trade %
RULE: Never risk more than 1-2% of portfolio on a single trade.
Worked example:
Portfolio Value = $10,000
Risk Per Trade = 2% ($200)
Entry Price = $100.00
Stop Loss = $95.00 (based on 2x ATR below entry)
Risk per share = $100.00 - $95.00 = $5.00
Position Size = $200 / $5.00 = 40 shares
Position Value = 40 * $100 = $4,000 (40% of portfolio)
CONCENTRATION CHECK: If position value > 10% of portfolio, reduce size.
Adjusted: max position = $1,000 / $100 = 10 shares
Adjusted risk = 10 * $5.00 = $50 (only 0.5% of portfolio — acceptable)
凯利准则(最优下注规模)
Kelly % = W - ((1 - W) / R)
Where:
W = win rate (decimal)
R = average win / average loss ratio (reward-to-risk)
Worked example:
Win rate: 60% (W = 0.60)
Average win: $300, Average loss: $200
R = 300 / 200 = 1.5
Kelly = 0.60 - (0.40 / 1.5) = 0.60 - 0.267 = 0.333 (33.3%)
Full Kelly is too aggressive for real trading. Use fractions:
Half-Kelly = 0.333 / 2 = 16.7% of portfolio per trade
Quarter-Kelly = 0.333 / 4 = 8.3% of portfolio per trade (recommended)
If Kelly is negative, the system has NEGATIVE expectancy — do not trade it.
风险价值(VaR)
Parametric VaR = Portfolio Value * Portfolio Volatility * Z-score * sqrt(Time Horizon)
Z-scores: 90% confidence = 1.282
95% confidence = 1.645
99% confidence = 2.326
Worked example (daily VaR, 95% confidence):
Portfolio = $10,000
Daily volatility (stddev of daily returns) = 2.0%
VaR = $10,000 * 0.02 * 1.645 * sqrt(1) = $329.00
Meaning: 95% confident daily loss will not exceed $329.
Weekly VaR = $329 * sqrt(5) = $329 * 2.236 = $735.65
Monthly VaR = $329 * sqrt(21) = $329 * 4.583 = $1,507.81
夏普比率
Sharpe = (Rp - Rf) / StdDev(Rp) * sqrt(252)
Where:
Rp = mean daily portfolio return
Rf = daily risk-free rate (Treasury yield / 252)
StdDev(Rp) = standard deviation of daily returns
252 = trading days per year (annualization factor)
Worked example:
Mean daily return = 0.10% (0.001)
Annual Treasury yield = 5.0% -> daily Rf = 0.05/252 = 0.000198
StdDev of daily returns = 0.80% (0.008)
Daily Sharpe = (0.001 - 0.000198) / 0.008 = 0.100
Annualized Sharpe = 0.100 * sqrt(252) = 0.100 * 15.875 = 1.59
Ratings:
< 0.5 = Poor (not compensated for risk)
0.5-1.0 = Acceptable
1.0-2.0 = Good
2.0-3.0 = Very Good
> 3.0 = Excellent (verify — may indicate overfitting)
索提诺比率(仅考虑下行风险)
Sortino = (Rp - Rf) / DownsideDeviation * sqrt(252)
DownsideDeviation = sqrt(mean(min(Ri - Rf, 0)^2))
Better than Sharpe because it only penalizes downside volatility, not upside.
Sortino > 2.0 is considered very good.
最大回撤
For each point t in equity curve:
Peak(t) = max(Equity[0..t])
Drawdown(t) = (Peak(t) - Equity(t)) / Peak(t) * 100%
MaxDrawdown = max(Drawdown(t)) for all t
Worked example:
Equity curve: $10,000 -> $12,000 -> $9,600 -> $11,500
Peak at $12,000
Drawdown at $9,600 = (12,000 - 9,600) / 12,000 = 20.0%
Max Drawdown = 20.0%
Recovery Factor = Total Net Profit / Max Drawdown
If total profit = $3,000, MaxDD = $2,400 -> RF = 3,000/2,400 = 1.25
Calmar Ratio = Annual Return / Max Drawdown
If annual return = 25%, MaxDD = 20% -> Calmar = 1.25 (target > 1.0)
盈利因子
Profit Factor = Gross Winning Trades / Gross Losing Trades
Worked example:
10 winning trades totaling $5,000
8 losing trades totaling $3,200
Profit Factor = 5,000 / 3,200 = 1.5625
Ratings: < 1.0 = losing system, 1.0-1.5 = marginal, 1.5-2.0 = good,
2.0-3.0 = very good, > 3.0 = excellent (verify with enough trades)
每笔交易的期望收益
Expectancy = (Win% * AvgWin) - (Loss% * AvgLoss)
Worked example:
Win rate: 55%, Average win: $150, Average loss: $100
Expectancy = (0.55 * 150) - (0.45 * 100) = 82.50 - 45.00 = $37.50/trade
Over 100 trades: expected profit = $3,750
Minimum for a viable system: Expectancy > 0 with at least 30 sample trades.
风险/回报比
R:R = (Target Price - Entry Price) / (Entry Price - Stop Loss Price)
Worked example:
Entry = $100, Stop = $95, Target = $112
R:R = (112 - 100) / (100 - 95) = 12 / 5 = 2.4:1
Minimum acceptable R:R = 1.5:1
With 40% win rate and 2:1 R:R: Expectancy = 0.40*2 - 0.60*1 = +0.20 (profitable!)
With 40% win rate and 1:1 R:R: Expectancy = 0.40*1 - 0.60*1 = -0.20 (losing!)
4. Alpaca 交易 API 参考
身份验证
# Paper trading (ALWAYS start here)
BASE_URL="https://paper-api.alpaca.markets"
# Live trading (only after paper validation)
# BASE_URL="https://api.alpaca.markets"
# Data API (same for both paper and live)
DATA_URL="https://data.alpaca.markets"
# Auth headers (required on every request)
HEADERS="-H 'APCA-API-KEY-ID: $ALPACA_API_KEY' -H 'APCA-API-SECRET-KEY: $ALPACA_SECRET_KEY'"
账户信息
# Get account details
curl -s "$BASE_URL/v2/account" $HEADERS
# Key fields: id, status, equity, cash, buying_power, portfolio_value,
# pattern_day_trader (bool), daytrade_count, last_equity
获取当前持仓
# All positions
curl -s "$BASE_URL/v2/positions" $HEADERS
# Returns array: symbol, qty, side, avg_entry_price, current_price,
# unrealized_pl, unrealized_plpc, market_value, cost_basis
# Single position
curl -s "$BASE_URL/v2/positions/AAPL" $HEADERS
下单
# Market order (fills immediately at best available price)
curl -s -X POST "$BASE_URL/v2/orders" $HEADERS \
-H "Content-Type: application/json" \
-d '{"symbol":"AAPL","qty":"10","side":"buy","type":"market","time_in_force":"day"}'
# Limit order (fills only at your price or better)
curl -s -X POST "$BASE_URL/v2/orders" $HEADERS \
-H "Content-Type: application/json" \
-d '{"symbol":"AAPL","qty":"10","side":"buy","type":"limit","time_in_force":"gtc","limit_price":"150.00"}'
# Stop order (triggers market order when stop price hit)
curl -s -X POST "$BASE_URL/v2/orders" $HEADERS \
-H "Content-Type: application/json" \
-d '{"symbol":"AAPL","qty":"10","side":"sell","type":"stop","time_in_force":"gtc","stop_price":"145.00"}'
# Stop-limit order (triggers limit order when stop price hit)
curl -s -X POST "$BASE_URL/v2/orders" $HEADERS \
-H "Content-Type: application/json" \
-d '{"symbol":"AAPL","qty":"10","side":"sell","type":"stop_limit","time_in_force":"gtc","stop_price":"145.00","limit_price":"144.50"}'
# Trailing stop (dynamic stop that trails price by dollar or percent amount)
curl -s -X POST "$BASE_URL/v2/orders" $HEADERS \
-H "Content-Type: application/json" \
-d '{"symbol":"AAPL","qty":"10","side":"sell","type":"trailing_stop","time_in_force":"gtc","trail_percent":"5"}'
# Bracket order (entry + stop loss + take profit as one atomic order)
curl -s -X POST "$BASE_URL/v2/orders" $HEADERS \
-H "Content-Type: application/json" \
-d '{
"symbol": "AAPL",
"qty": "10",
"side": "buy",
"type": "limit",
"time_in_force": "day",
"limit_price": "150.00",
"order_class": "bracket",
"stop_loss": {"stop_price": "145.00"},
"take_profit": {"limit_price": "165.00"}
}'
# OCO order (one-cancels-other: stop loss OR take profit, whichever hits first)
curl -s -X POST "$BASE_URL/v2/orders" $HEADERS \
-H "Content-Type: application/json" \
-d '{
"symbol": "AAPL",
"qty": "10",
"side": "sell",
"type": "limit",
"time_in_force": "gtc",
"limit_price": "165.00",
"order_class": "oco",
"stop_loss": {"stop_price": "145.00"}
}'
订单参数参考:
| 参数 | 值 | 备注 |
|---|---|---|
side | buy、sell | |
type | market、limit、stop、stop_limit、trailing_stop | |
time_in_force | day、gtc、ioc、fok | day = 收盘时取消,gtc = 取消前持续有效 |
order_class | simple、bracket、oco、oto | bracket = 入场 + 止损 + 目标价 |
qty | 字符串数字 | 股票以整股计 |
notional | 字符串美元金额 | qty 的替代参数(零碎股) |
管理订单
# List open orders
curl -s "$BASE_URL/v2/orders?status=open" $HEADERS
# Get specific order
curl -s "$BASE_URL/v2/orders/{order_id}" $HEADERS
# Cancel specific order
curl -s -X DELETE "$BASE_URL/v2/orders/{order_id}" $HEADERS
# Cancel ALL open orders
curl -s -X DELETE "$BASE_URL/v2/orders" $HEADERS
平仓
# Close entire position in a symbol
curl -s -X DELETE "$BASE_URL/v2/positions/AAPL" $HEADERS
# Partially close (sell 5 of 10 shares)
curl -s -X DELETE "$BASE_URL/v2/positions/AAPL?qty=5" $HEADERS
# EMERGENCY: Close ALL positions
curl -s -X DELETE "$BASE_URL/v2/positions" $HEADERS
市场数据(Alpaca 账户免费提供)
# Latest quote (bid/ask)
curl -s "$DATA_URL/v2/stocks/AAPL/quotes/latest" $HEADERS
# Latest trade (last fill)
curl -s "$DATA_URL/v2/stocks/AAPL/trades/latest" $HEADERS
# Historical bars (OHLCV) — daily
curl -s "$DATA_URL/v2/stocks/AAPL/bars?timeframe=1Day&start=2024-01-01&limit=100" $HEADERS
# Intraday bars — 5-minute
curl -s "$DATA_URL/v2/stocks/AAPL/bars?timeframe=5Min&start=$(date -d 'today' +%Y-%m-%d)&limit=78" $HEADERS
# Multi-symbol snapshot
curl -s "$DATA_URL/v2/stocks/snapshots?symbols=AAPL,MSFT,GOOGL" $HEADERS
# Crypto bars
curl -s "$DATA_URL/v1beta3/crypto/us/bars?symbols=BTC/USD&timeframe=1Day&limit=30" $HEADERS
# Crypto latest quote
curl -s "$DATA_URL/v1beta3/crypto/us/latest/quotes?symbols=BTC/USD,ETH/USD" $HEADERS
市场时钟与日历
# Is market open right now?
curl -s "$BASE_URL/v2/clock" $HEADERS
# Returns: timestamp, is_open (bool), next_open, next_close
# Upcoming market calendar
curl -s "$BASE_URL/v2/calendar?start=$(date +%Y-%m-%d)&end=$(date -d '+7 days' +%Y-%m-%d)" $HEADERS
加密货币交易说明
- 交易符号使用斜杠格式:
BTC/USD、ETH/USD、SOL/USD、DOGE/USD - 全天候交易(不受市场交易时间限制)
- 允许使用零碎数量(例如,BTC 可用
"qty": "0.001") - 模拟交易与实盘交易的运作方式相同
- 美元计价的加密货币订单使用
notional:"notional": "100.00"可买入价值 $100 的加密货币
账户活动与历史记录
# Trade history
curl -s "$BASE_URL/v2/account/activities/FILL?after=2024-01-01" $HEADERS
# Portfolio history
curl -s "$BASE_URL/v2/account/portfolio/history?period=1M&timeframe=1D" $HEADERS
# Returns: timestamp[], equity[], profit_loss[], profit_loss_pct[]
5. 免费金融数据源
价格数据(通过 web_search + web_fetch 获取)
| 来源 | URL 模式 | 可用数据 |
|---|---|---|
| Yahoo Finance | finance.yahoo.com/quote/AAPL | 实时报价、图表、财务数据、分析师评级 |
| Google Finance | google.com/finance/quote/AAPL:NASDAQ | 报价、新闻、相关股票、财报 |
| CoinGecko | coingecko.com/en/coins/bitcoin | 加密货币价格、市值、成交量、24 小时涨跌幅 |
| CoinMarketCap | coinmarketcap.com/currencies/bitcoin/ | 加密货币价格、排名、市场主导率、供应量 |
| MarketWatch | marketwatch.com/investing/stock/AAPL | 报价、新闻、分析、期权数据 |
| Finviz | finviz.com/quote.ashx?t=AAPL | 技术面与基本面筛选器、图表 |
| TradingView | tradingview.com/symbols/NASDAQ-AAPL/ | 图表、技术指标、社区观点 |
基本面数据
| 来源 | URL 模式 | 可获取的数据 |
|---|---|---|
| Macrotrends | macrotrends.net/stocks/charts/AAPL/apple/pe-ratio | 市盈率、营收、利润率、历史数据 |
| Simply Wall St | Web 搜索:"AAPL simply wall st" | 可视化基本面分析、公允价值 |
| SEC EDGAR | sec.gov/cgi-bin/browse-edgar?action=getcompany&CIK=AAPL&type=10-K | 官方 10-K、10-Q、8-K 文件 |
| Earnings Whispers | earningswhispers.com/stocks/AAPL | 盈利预期、超预期历史、日历 |
| Stock Analysis | stockanalysis.com/stocks/AAPL/financials/ | 清晰的财务报表、比率 |
| Wisesheets | Web 搜索:"AAPL income statement" | 电子表格格式的财务数据 |
情绪与另类数据
| 来源 | URL | 可获取的数据 |
|---|---|---|
| CNN 恐惧与贪婪指数 | money.cnn.com/data/fear-and-greed/ | 市场情绪指数 0-100(极度恐惧至极度贪婪) |
| CBOE VIX | Web 搜索:"VIX index today" | 波动率指数(>30 = 恐惧,<15 = 自满) |
| Finviz 热力图 | finviz.com/map.ashx | 按行业/规模划分的市场热力图 |
| StockTwits | stocktwits.com/symbol/AAPL | 社交情绪(看涨/看跌比例) |
| 看跌/看涨期权比率 | Web 搜索:"CBOE put call ratio today" | 期权情绪(>1.0 = 看跌,<0.7 = 看涨) |
| 空头持仓 | finviz.com/quote.ashx?t=AAPL -> Short Float | 被卖空的流通股比例 |
| 内部人交易 | openinsider.com/screener | CEO/CFO 买入/卖出模式 |
宏观经济数据
| 来源 | URL | 可获取的数据 |
|---|---|---|
| FRED | fred.stlouisfed.org | 利率、CPI、就业、GDP、M2、收益率曲线 |
| Treasury.gov | treasury.gov/resource-center/data-chart-center/interest-rates/ | 每日美国国债收益率曲线 |
| CME FedWatch | Web 搜索:"CME FedWatch tool" | 联邦基金利率概率 |
| BLS | bls.gov/news.release/ | 就业状况、CPI、PPI |
| ISM | Web 搜索:"ISM manufacturing PMI" | PMI(>50 = 扩张,<50 = 收缩) |
| Conference Board | Web 搜索:"consumer confidence index" | 消费者信心、领先指标 |
| 盈利日历 | earningswhispers.com/calendar | 即将到来的财报日期 |
| 经济日历 | Web 搜索:"economic calendar this week" | 计划发布的数据 |
加密货币专属数据源
| 来源 | URL | 可获取的数据 |
|---|---|---|
| CoinGecko | coingecko.com | 价格、市值、交易量、DeFi TVL |
| DefiLlama | defillama.com | 所有链上的总锁仓价值 |
| Glassnode(免费版) | Web 搜索:"bitcoin on-chain metrics" | 链上分析(NUPL、MVRV、交易所资金流) |
| Bitcoin 恐惧与贪婪指数 | alternative.me/crypto/fear-and-greed-index/ | 加密货币专属情绪指数 0-100 |
| Ultrasound Money | ultrasound.money | ETH 供应量/销毁指标 |
6. 信心校准指南(超级预测)
校准原则(Philip Tetlock)
- 一个“70% 确信”的预测,正确率应约为 70%
- 大多数人过度自信:他们“90%”确信的预测,正确率只有约 70%
- 系统地记录预测,并比较预测频率与实际频率
- 逐步更新(每条新证据调整 2-5%),不要大幅调整
信心等级指南
| 等级 | 含义 | 所需证据 | 交易行动 |
|---|---|---|---|
| 20-30% | 略微倾向 | 单一弱信号,数据有限 | 不交易 — 优势不足 |
| 40-50% | 胜负难料,略有优势 | 信号相互矛盾,证据中等 | 不交易 — 如同抛硬币 |
| 55-65% | 中等把握 | 多个信号一致,有历史先例 | 小仓位,止损范围放宽 |
| 70-80% | 把握较大 | 多因素强烈一致,已发现催化因素 | 标准仓位规模 |
| 85-95% | 把握极大 | 证据压倒性 — 应对自己保持怀疑 | 满仓,但绝不要全仓押注 |
交易预测的 Brier 分数
Brier Score = mean((predicted_probability - actual_outcome)^2)
actual_outcome: 1 if prediction was correct, 0 if wrong
Worked example (5 predictions):
Pred 1: 80% confident -> correct (1) -> (0.80 - 1)^2 = 0.04
Pred 2: 60% confident -> wrong (0) -> (0.60 - 0)^2 = 0.36
Pred 3: 70% confident -> correct (1) -> (0.70 - 1)^2 = 0.09
Pred 4: 90% confident -> correct (1) -> (0.90 - 1)^2 = 0.01
Pred 5: 55% confident -> wrong (0) -> (0.55 - 0)^2 = 0.30
Brier Score = (0.04 + 0.36 + 0.09 + 0.01 + 0.30) / 5 = 0.16
Ratings: 0.00 = perfect, < 0.15 = excellent, 0.15-0.25 = good,
0.25 = coin flip, > 0.25 = worse than random
校准自检协议
累计 20 笔以上交易预测后,按置信度区间分组:
- 你的 60% 置信度预测有约 60% 的时间是正确的吗?
- 如果你的 60% 置信度预测有 80% 的时间是正确的,说明你的信心不足——应调高
- 如果你的 80% 置信度预测有 55% 的时间是正确的,说明你过于自信——应调低
- 每解决 50 笔预测后,重新校准你的置信度尺度
7. 交易心理与认知偏差
需警惕的偏差
| 偏差 | 描述 | 缓解方法 |
|---|---|---|
| 确认偏差 | 寻找能够证实自己论点的信息 | 始终先构建反方论据(对抗式辩论) |
| 锚定效应 | 过分看重最先看到的数字(入场价、分析师目标价) | 从基准率和当前数据开始分析,而不是旧价格 |
| 近因偏差 | 过分看重近期事件(上周的暴跌、上个月的上涨) | 查看更长的时间范围——至少查看 6 个月和 1 年的图表 |
| 损失厌恶 | 亏损时持仓太久(“它会涨回来的”),盈利时过早卖出 | 使用机械式止损和止盈目标,并在入场前设定 |
| 过度自信 | 认为自己比实际情况更正确 | 跟踪 Brier 分数,使用 Kelly 比例,单笔交易下注绝不超过 2% |
| 叙事偏差 | 动人的故事 = 好交易(往往并非如此) | 关注量化数据,而不是故事。“好公司” != “好交易” |
| 错失恐惧症(FOMO) | 害怕错失机会,追涨买入 | 只在计划好的价位入场。市场每年开放 252 天 |
| 沉没成本效应 | “我已经亏了这么多,现在不能卖” | 每一刻都是新的决策。问自己:“如果今天以当前价格买入,我还会进行这笔交易吗?” |
| 后见之明偏差 | “我早就知道会这样” | 在交易前记录具体预测,而不是事后记录 |
| 处置效应 | 为了“锁定利润”而过早卖出赢家,却继续持有亏损仓位 | 让赢家继续上涨(移动止损),在计划的止损位砍掉亏损仓位 |
| 赌徒谬误 | “已经连续跌了 5 天,它肯定会反弹” | 每一天都是独立的。趋势持续的情况比反转更常见 |
| 禀赋效应 | 高估自己已经持有的仓位 | 仿佛今天从零开始建仓一样评估持仓 |
纪律规则
- 每笔交易入场前都要有书面计划:入场价、止损价、目标价、仓位大小、论点
- 入场前写下你的理由——如果无法清楚阐述优势,就不要交易
- 在下单时设定止损,而不是“记在脑子里”
- 每周回顾交易日志——寻找盈利和亏损中的规律
- 大幅盈利后(过度自信风险)和大幅亏损后(情绪风险)都要休息
- 除非原始论点明确计划如此,否则绝不对亏损仓位向下摊平
- 绝不把止损价设得比入场价更远(只能收紧,不能放宽)
- 市场明天还会开盘——错过一笔交易不算亏损,但账户爆仓算
8. 投资组合构建
资产配置指南
| 风格 | 股票 | 加密货币 | 固定收益 / 现金 | 单一持仓上限 |
|---|---|---|---|---|
| 保守型 | 50-60% | 0-5% | 35-50% | 5% |
| 稳健型 | 60-75% | 5-15% | 10-35% | 8% |
| 激进型 | 70-85% | 10-25% | 5-20% | 10% |
| 投机型 | 50-70% | 20-40% | 5-10% | 15%(必须严格止损) |
行业分散
任何单一行业的占比最高为 30%:
- 科技、医疗保健、金融、可选消费、必需消费
- 能源、工业、公用事业、房地产、材料、通信服务
相关性认知
高度相关的持仓会放大风险。新增持仓前,请检查相关性:
| 配对 | 典型相关性 | 风险 |
|---|---|---|
| AAPL + MSFT + GOOGL | 0.7-0.9 | 大盘科技股过度集中 |
| BTC + ETH + SOL | 0.8-0.95 | 加密资产过度集中(走势趋同) |
| SPY + QQQ | 0.9+ | 敞口几乎相同 |
| 股票 + 债券 | -0.2 到 0.3 | 确实能分散风险 |
| 黄金 + 股票 | -0.1 到 0.2 | 危机期间可对冲 |
| VIX + SPY | -0.8 | 反向关系——以 VIX 对冲 |
再平衡规则
- 按日历:每季度再平衡一次(季度首个交易日)
- 阈值:任一资产配置偏离目标 > 5% 时再平衡
- 税务考量:优先通过新增投入而非卖出进行再平衡(应税账户)
9. 跨平台命令
Windows(PowerShell / Git Bash)
# Python might be `python` not `python3` on Windows
python -c "import json; ..."
# Use forward slashes in file paths or escape backslashes
# curl is available via Git Bash, PowerShell, or WSL
# Check if market is open (Windows Git Bash)
curl -s "$BASE_URL/v2/clock" -H "APCA-API-KEY-ID: $ALPACA_API_KEY" \
-H "APCA-API-SECRET-KEY: $ALPACA_SECRET_KEY" | python -c "
import sys, json
d = json.load(sys.stdin)
print('OPEN' if d['is_open'] else 'CLOSED', '| Next:', d.get('next_open','') or d.get('next_close',''))
"
macOS / Linux
python3 -c "import json; ..."
# curl, jq typically available by default
# Use jq for JSON processing:
curl -s URL | jq '.equity'
不使用 jq 处理 JSON
# Pretty-print JSON
python3 -c "import sys,json; print(json.dumps(json.load(sys.stdin),indent=2))" < file.json
# Extract specific field
curl -s URL | python3 -c "import sys,json; d=json.load(sys.stdin); print(d['equity'])"
# Parse Alpaca positions into readable table
curl -s "$BASE_URL/v2/positions" $HEADERS | python3 -c "
import sys, json
positions = json.load(sys.stdin)
fmt = '{:<8} {:>6} {:>10} {:>10} {:>12} {:>8}'
print(fmt.format('Symbol','Qty','Entry','Current','P/L','P/L pct'))
print('-' * 60)
for p in positions:
print(fmt.format(p['symbol'], p['qty'], float(p['avg_entry_price']),
float(p['current_price']), float(p['unrealized_pl']),
round(float(p['unrealized_plpc'])*100,2)))
"
# Calculate RSI from historical bars
curl -s "$DATA_URL/v2/stocks/AAPL/bars?timeframe=1Day&limit=30" $HEADERS | python3 -c "
import sys, json
data = json.load(sys.stdin)
closes = [float(b['c']) for b in data['bars']]
changes = [closes[i]-closes[i-1] for i in range(1, len(closes))]
gains = [max(c,0) for c in changes[-14:]]
losses = [abs(min(c,0)) for c in changes[-14:]]
avg_gain = sum(gains)/14
avg_loss = sum(losses)/14
rs = avg_gain/avg_loss if avg_loss > 0 else 999
rsi = 100 - (100/(1+rs))
print(f'RSI(14) = {rsi:.1f}')
"
10. 交易前检查清单
每次交易前,请确认以下所有事项:
PRE-TRADE CHECKLIST
====================
[ ] 1. TREND: What is the higher-timeframe trend? (Daily chart 200 SMA)
- Trading WITH the trend? (preferred)
- Counter-trend? (requires stronger signal + tighter stops)
[ ] 2. SIGNAL: What specific setup triggered this trade?
- Indicator signal (RSI, MACD, etc.)
- Pattern (candlestick, chart pattern)
- Catalyst (earnings, news, sector rotation)
[ ] 3. ENTRY: Exact entry price or condition
- Limit order at specific level? Market order on breakout?
[ ] 4. STOP LOSS: Exact stop price
- Based on ATR (2-3x ATR from entry)
- Below key support (long) or above key resistance (short)
- NEVER wider than 2% of portfolio
[ ] 5. TARGET: Exact take-profit price
- Risk/Reward at least 1.5:1 (preferably 2:1+)
- At logical resistance (long) or support (short)
[ ] 6. POSITION SIZE: Calculated from risk management rules
- Risk amount = Portfolio * 1-2%
- Shares = Risk amount / (Entry - Stop)
- Total position < 10% of portfolio
[ ] 7. CORRELATION CHECK: Does this overlap with existing positions?
- Not adding to concentrated sector exposure
- Total portfolio heat (sum of open risk) < 6%
[ ] 8. CATALYST CHECK: Any upcoming events that could gap through stops?
- Earnings date? Fed meeting? CPI release?
- If yes: reduce size or wait until after event
[ ] 9. MARKET CONTEXT: Is the overall market favorable?
- Fear & Greed index level
- VIX level (>30 = caution, <15 = complacency risk)
- Market trend (SPY vs 200 SMA)
[ ] 10. CONFIDENCE: Rate 1-10 honestly
- Below 6? Skip the trade
- Record confidence for calibration tracking
11. 交易日志模板
{
"trade_id": "T001",
"date_opened": "2025-01-15",
"date_closed": null,
"symbol": "AAPL",
"side": "long",
"entry_price": 150.00,
"stop_loss": 145.00,
"target": 162.00,
"position_size": 40,
"risk_amount": 200.00,
"risk_reward": 2.4,
"setup": "Bullish engulfing at 50 EMA + RSI divergence",
"confidence": 7,
"market_context": "SPY above 200 SMA, VIX at 18, F&G neutral (52)",
"pre_trade_thesis": "AAPL pulled back to 50 EMA support, RSI showing bullish divergence, earnings in 3 weeks should provide catalyst. Sector (tech) is leading.",
"result": {
"exit_price": null,
"exit_reason": null,
"pnl": null,
"pnl_percent": null,
"held_days": null,
"lessons": null
}
}
使用 memory_store 存储交易日志,以便跟踪和进行校准审查。
评论
支持 Markdown