Volatility
Volatility ความผันผวน Historical Implied VIX Standard Deviation ATR Bollinger Bands Option Pricing Risk Management Position Size Trading Strategy
| Volatility Type | Calculation | Timeframe | Use Case | Data Source |
|---|---|---|---|---|
| Historical (HV) | StdDev of Log Returns | Past 20-252 days | Risk assessment | Price history |
| Implied (IV) | Back-solved from Option | Forward looking | Option pricing | Option market |
| Realized | Actual StdDev period | Specific period | Performance eval | Price history |
| ATR | Avg True Range | 14 periods typical | Stop loss sizing | OHLC data |
| VIX | S&P 500 Option IV | 30-day forward | Market sentiment | CBOE |
| Bollinger BW | (Upper-Lower)/Middle | 20 periods | Squeeze detection | Price + StdDev |
Volatility Calculation
# === Volatility Calculation in Python ===
import numpy as np
from dataclasses import dataclass
def historical_volatility(prices, window=20):
log_returns = np.diff(np.log(prices))
rolling_std = []
for i in range(window, len(log_returns) + 1):
std = np.std(log_returns[i-window:i], ddof=1)
annualized = std * np.sqrt(252)
rolling_std.append(annualized)
return rolling_std
def atr(high, low, close, period=14):
tr_list = []
for i in range(1, len(high)):
tr = max(
high[i] - low[i],
abs(high[i] - close[i-1]),
abs(low[i] - close[i-1])
)
tr_list.append(tr)
atr_values = []
atr_val = np.mean(tr_list[:period])
atr_values.append(atr_val)
for i in range(period, len(tr_list)):
atr_val = (atr_val * (period - 1) + tr_list[i]) / period
atr_values.append(atr_val)
return atr_values
# Example calculation
np.random.seed(42)
prices = 100 + np.cumsum(np.random.randn(100) * 1.5)
hv = historical_volatility(prices, 20)
print("=== Historical Volatility ===")
print(f" Latest HV (20-day): {hv[-1]:.2%}")
print(f" Average HV: {np.mean(hv):.2%}")
print(f" Max HV: {np.max(hv):.2%}")
print(f" Min HV: {np.min(hv):.2%}")
@dataclass
class VolRegime:
regime: str
hv_range: str
vix_range: str
market_behavior: str
strategy: str
regimes = [
VolRegime("Low", "< 15%", "< 15", "ตลาดสงบ Trend ชัด", "Trend Following, Sell Premium"),
VolRegime("Normal", "15-25%", "15-20", "ตลาดปกติ มี Swing", "Swing Trading, Covered Call"),
VolRegime("High", "25-40%", "20-30", "ตลาดผันผวน ข่าวสำคัญ", "Reduce Size, Widen Stops"),
VolRegime("Extreme", "> 40%", "> 30", "ตลาดตกใจ Crisis", "Hedge, Buy Premium, Cash"),
]
print(f"\nVolatility Regimes:")
for v in regimes:
print(f" [{v.regime}] HV: {v.hv_range} | VIX: {v.vix_range}")
print(f" Market: {v.market_behavior}")
print(f" Strategy: {v.strategy}")
Trading Applications
# === Volatility-based Trading ===
# Position Sizing with ATR
# risk_per_trade = account * 0.01 # 1% risk
# stop_loss_distance = atr * 2 # 2x ATR
# position_size = risk_per_trade / stop_loss_distance
# Bollinger Bands
# middle = SMA(close, 20)
# upper = middle + 2 * StdDev(close, 20)
# lower = middle - 2 * StdDev(close, 20)
# bandwidth = (upper - lower) / middle
# Bollinger Squeeze Detection
# if bandwidth < threshold: # Squeeze — low volatility
# prepare_for_breakout()
# if bandwidth > high_threshold: # Expansion — high volatility
# consider_mean_reversion()
@dataclass
class TradingSetup:
setup: str
volatility_condition: str
entry: str
stop_loss: str
target: str
risk_reward: str
setups = [
TradingSetup("Breakout", "Bollinger Squeeze → Expansion", "Break above Upper Band", "Below Middle Band", "2x ATR from entry", "1:2"),
TradingSetup("Mean Reversion", "Bollinger > 2 StdDev", "Touch Lower Band + RSI < 30", "Below recent low", "Middle Band", "1:1.5"),
TradingSetup("Trend Follow", "ATR rising + ADX > 25", "Pullback to 20 EMA", "1.5x ATR", "3x ATR", "1:2"),
TradingSetup("Range Trade", "ATR falling + ADX < 20", "Support/Resistance bounce", "Outside range", "Opposite boundary", "1:1"),
TradingSetup("Vol Expansion", "VIX spike > 25%", "After spike settles", "Above VIX high", "VIX mean revert", "1:2"),
]
print("\n=== Volatility Trading Setups ===")
for s in setups:
print(f" [{s.setup}] Vol: {s.volatility_condition}")
print(f" Entry: {s.entry}")
print(f" SL: {s.stop_loss} | TP: {s.target} | R:R: {s.risk_reward}")
Risk Management
# === Risk Management with Volatility ===
@dataclass
class RiskRule:
rule: str
low_vol: str
normal_vol: str
high_vol: str
extreme_vol: str
rules = [
RiskRule("Position Size", "Full (1-2% risk)", "Normal (1% risk)", "Half (0.5% risk)", "Quarter (0.25% risk)"),
RiskRule("Stop Loss", "1.5x ATR", "2x ATR", "2.5x ATR", "3x ATR or no trade"),
RiskRule("Max Open Trades", "5-8", "3-5", "2-3", "0-1"),
RiskRule("Leverage", "Normal", "Reduce 25%", "Reduce 50%", "No leverage"),
RiskRule("Hedge", "ไม่จำเป็น", "Optional", "Recommended", "Required"),
RiskRule("Cash Allocation", "10-20%", "20-30%", "30-50%", "50-80%"),
]
print("Risk Management by Volatility:")
for r in rules:
print(f" [{r.rule}]")
print(f" Low: {r.low_vol}")
print(f" Normal: {r.normal_vol}")
print(f" High: {r.high_vol}")
print(f" Extreme: {r.extreme_vol}")
# Kelly Criterion adjusted for volatility
# f = (W * R - L) / R
# f_adjusted = f * (base_vol / current_vol)
# Where lower vol = larger position, higher vol = smaller position
vol_tools = {
"ATR Indicator": "TradingView: ATR(14) overlay on chart",
"Bollinger Bands": "TradingView: BB(20,2) squeeze detection",
"VIX Chart": "TradingView: CBOE:VIX daily chart",
"IV Rank": "Option platform: current IV vs 52-week range",
"HV Calculator": "Python script above or Excel",
"Vol Surface": "Option platform: IV by strike and expiry",
}
print(f"\n\nVolatility Tools:")
for k, v in vol_tools.items():
print(f" [{k}]: {v}")
เคล็ดลับ
- ATR: ใช้ ATR ตั้ง Stop Loss ให้เหมาะกับ Volatility ปัจจุบัน
- Size: ลด Position Size เมื่อ Volatility สูง
- Squeeze: สังเกต Bollinger Squeeze เตรียม Breakout Trade
- VIX: ดู VIX เป็น Sentiment Indicator ก่อนเทรด
- Regime: ปรับ Strategy ตาม Volatility Regime
การนำความรู้ไปประยุกต์ใช้งานจริง
แหล่งเรียนรู้ที่แนะนำ ได้แก่ Official Documentation ที่อัพเดทล่าสุดเสมอ Online Course จาก Coursera Udemy edX ช่อง YouTube คุณภาพทั้งไทยและอังกฤษ และ Community อย่าง Discord Reddit Stack Overflow ที่ช่วยแลกเปลี่ยนประสบการณ์กับนักพัฒนาทั่วโลก
เปรียบเทียบข้อดีและข้อเสีย
จากตารางเปรียบเทียบจะเห็นว่าข้อดีมีมากกว่าข้อเสียอย่างชัดเจน โดยเฉพาะในแง่ของประสิทธิภาพและความสามารถในการ Scale สำหรับข้อเสียส่วนใหญ่สามารถแก้ไขได้ด้วยการเรียนรู้อย่างเป็นระบบและวางแผนทรัพยากรให้เหมาะสม
Volatility แปลว่าอะไร
ความผันผวน การเปลี่ยนแปลงราคา Standard Deviation สูงเปลี่ยนมาก ต่ำเปลี่ยนน้อย หุ้น Forex Crypto Option ความเสี่ยง โอกาส
Historical กับ Implied Volatility ต่างกันอย่างไร
HV คำนวณจากอดีต StdDev Log Return IV คำนวณจาก Option ราคาตลาด อนาคต IV สูงกว่า HV ตลาดคาดผันผวนมาก Black-Scholes
VIX Index คืออะไร
Volatility Index S&P 500 IV 30 วัน ต่ำกว่า 20 สงบ 20-30 ปานกลาง สูงกว่า 30 กลัว Fear Index ความเชื่อมั่น Futures ETF Options
ใช้ Volatility ในการเทรดอย่างไร
ATR Stop Loss Position Size Bollinger Bands Squeeze Breakout Mean Reversion VIX Sentiment Option Straddle Strangle Risk Reward Regime
สรุป
Volatility ความผันผวน Historical Implied VIX ATR Bollinger Bands Position Size Risk Management Regime Trading Strategy Option Pricing Production
