몬테카를로 리스크 시뮬레이션 — 포트폴리오 결과 모델링
몬테카를로 시뮬레이션을 통해 포트폴리오의 100,000개 이상의 잠재적인 미래 경로를 모델링하고, VaR(Value at Risk) 및 예상 부족액과 같은 리스크 지표를 정량화할 수 있습니다. 단일 결과를 가정하는 대신 가능성의 분포를 확인할 수 있습니다.
예시: 거래 전략에 대한 10만 번의 시뮬레이션을 실행합니다. 결과는 다음과 같습니다: 68%의 결과에서 $10-$50의 수익, 25%는 $10-$30의 손실, 5%는 $50-$200의 손실, 2%는 $100 이상의 수익. 이제 리스크 프로필을 이해할 수 있습니다.
기본 기하 브라운 운동(GBM)
미래 가격을 드리프트와 변동성을 가진 랜덤 워크로 모델링:
Python — 몬테카를로 가격 경로
import numpy as np
def simulate_price_paths(S0, mu, sigma, T, dt, n_sims=10000):
# S0: 현재 가격, mu: 드리프트, sigma: 변동성
# T: 시간 범위(일), dt: 시간 단계, n_sims: 시뮬레이션 횟수
steps = int(T / dt)
paths = np.zeros((n_sims, steps))
paths[:, 0] = S0
for i in range(1, steps):
# dS = mu*S*dt + sigma*S*sqrt(dt)*Z
Z = np.random.normal(0, 1, n_sims)
dS = mu * paths[:, i-1] * dt + sigma * paths[:, i-1] * np.sqrt(dt) * Z
paths[:, i] = paths[:, i-1] + dS
return paths
포트폴리오 리스크 지표
VaR(Value at Risk)
시나리오의 5%에서만 초과하는 손실(95% 신뢰 수준):
Python — VaR 계산
def calculate_var(simulations, confidence=0.95):
pnl = simulations[:, -1] - simulations[:, 0]
var = np.percentile(pnl, (1 - confidence) * 100)
return var # 예: -$2,340
예상 부족액(CVaR)
최악의 5% 경우의 평균 손실:
Python — CVaR 계산
def calculate_cvar(simulations, confidence=0.95):
pnl = simulations[:, -1] - simulations[:, 0]
var_threshold = np.percentile(pnl, (1 - confidence) * 100)
worst_5_pct = pnl[pnl <= var_threshold]
cvar = np.mean(worst_5_pct)
return cvar # 예: -$3,800 (VaR보다 더 나쁨)
전략별 시뮬레이션
가격 경로뿐만 아니라 실제 거래 규칙을 시뮬레이션:
Python — 전략 몬테카를로
def simulate_strategy(capital, win_rate, avg_win, avg_loss, trades_per_day=10, days=30, n_sims=10000):
results = np.zeros(n_sims)
for sim in range(n_sims):
equity = capital
n_trades = trades_per_day * days
for _ in range(n_trades):
if np.random.rand() < win_rate:
pnl = np.random.normal(avg_win, avg_win * 0.2)
else:
pnl = -np.random.normal(avg_loss, avg_loss * 0.2)
equity += pnl
if equity < capital * 0.5:
break # 50% 손실 시 중단
results[sim] = equity
return results
Smart Money 신호를 이용한 스트레스 테스트
Smart Money 신뢰도가 하락할 때 최악의 시나리오 모델링:
Python — 스트레스 테스트 시나리오
def stress_test_scenarios(base_win_rate):
# 시나리오 1: 정상 조건(HIGH 신뢰도)
scenario_normal = simulate_strategy(10000, win_rate=base_win_rate)
# 시나리오 2: 악화되는 신호(MEDIUM 신뢰도)
scenario_medium = simulate_strategy(10000, win_rate=base_win_rate * 0.95)
# 시나리오 3: 붕괴(VETO 조건)
scenario_veto = simulate_strategy(10000, win_rate=0.45) # 부정적인 경계
return {
'normal': {'var': np.percentile(scenario_normal, 5), 'mean': np.mean(scenario_normal)},
'medium': {'var': np.percentile(scenario_medium, 5), 'mean': np.mean(scenario_medium)},
'veto': {'var': np.percentile(scenario_veto, 5), 'mean': np.mean(scenario_veto)}
}
해석
10,000번의 시뮬레이션을 통해 다음을 학습합니다:
- 중간 결과(50번째 백분위수)
- 최상의 경우(95번째 백분위수)
- 최악의 경우(5번째 백분위수)
- 파산 확률(자본 < 0)
- 예상 드로다운 기간
Smart Money 신호로 전략 스트레스 테스트
정상, 악화 및 VETO Smart Money 조건에서 포트폴리오 리스크를 이해하십시오. 당사의 API는 신호를 제공하고 몬테카를로는 결과를 모델링합니다.
오늘의 리스크 모델 →