Python 投资组合风险管理入门
Dakota Wixom
Quantitative Analyst | QuantCourse.com
学习分析投资回报分布,构建组合并降低风险,识别驱动组合回报的关键因子。
什么是风险?
通常如何度量风险?




$$ Rl = \ln(\frac{P_{t_2}}{P_{t_1}}) $$
或等价地:
$$ Rl = \ln(P_{t_2}) - \ln(P_{t_1}) $$
加载股票价格数据,并存为按日期组织的 pandas DataFrame:
import pandas as pd
StockPrices = pd.read_csv('StockData.csv', parse_dates=['Date'])
StockPrices = StockPrices.sort_values(by='Date')
StockPrices.set_index('Date', inplace=True)
计算复权收盘价的日回报,并将其作为新列加入 DataFrame。
StockPrices["Returns"] = StockPrices["Adj Close"].pct_change()
StockPrices["Returns"].head()

import matplotlib.pyplot as plt
plt.hist(StockPrices["Returns"].dropna(), bins=75, density=False)
plt.show()

Python 投资组合风险管理入门