변동성과 구조적 단절
변동성 변화를 시각화하면 시계열에서 잠재적인 구조적 단절 시점을 확인하는 데 도움이 됩니다. 변동성이 바뀌는 시점을 파악하면, 그 지점을 단절점으로 합리적으로 선택할 수 있고, 이후 Chow 검정 같은 추가 통계 분석에 활용할 수 있어요.
여러분은 2008–2009년 투자은행 포트폴리오의 변동성을 두 가지 가중치에 대해 비교하는 시각화를 살펴보게 됩니다: weights_with_citi와 weights_without_citi. 각각 시티은행을 포함한 경우와 제외한 경우의 동일가중 포트폴리오를 의미하며, 1장에서 보셨듯이 이 기간 동안 네 자산 중 시티은행의 변동성이 가장 컸습니다.
2008–2009년 시티은행을 포함한 포트폴리오 가격은 prices_with_citi로, 제외한 가격은 prices_without_citi로 제공됩니다.
이 연습은 강의의 일부입니다
Python을 활용한 정량적 리스크 관리
연습 안내
weights_with_citi와weights_without_citi를 사용해 두 포트폴리오의 수익률 시리즈를 구하세요.- 두 포트폴리오 각각에 대해 30일 롤링 윈도우 표준편차를 계산하세요.
- 두 개의 Pandas
Series객체를 하나의 "vol" DataFrame 객체로 결합하세요. vol객체를 시각화해 시간에 따른 두 포트폴리오의 변동성을 비교하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Find the time series of returns with and without Citibank
ret_with_citi = prices_with_citi.____.dot(weights_with_citi)
ret_without_citi = prices_without_citi.pct_change().____(____)
# Find the average 30-day rolling window volatility as the standard deviation
vol_with_citi = ret_with_citi.____.std().dropna().rename("With Citi")
vol_without_citi = ret_without_citi.rolling(30).____.dropna().rename("Without Citi")
# Combine two volatilities into one Pandas DataFrame
vol = pd.concat([____, ____], axis=1)
# Plot volatilities over time
vol.____().set_ylabel("Losses")
plt.show()