相关性的效应量
资产的波动率大致定义为价格变动的幅度。在本练习中,您将按日度来度量波动率,定义为 (最高价 - 最低价) / 收盘价。
哪些因素能够解释比特币的波动率?它与 S&P500 的波动率是否密切相关?当价格上升时,波动率是上升还是下降?换句话说,这些不同因素之间的相关性有多强(效应量多大)?您将在本练习中计算这两种效应量。
我们已为您加载了包含 S&P 500 与比特币价格的数据框 btc_sp_df,并导入了 pandas 为 pd、NumPy 为 np、Matplotlib 为 plt,以及 SciPy 中的 stats。
本练习是课程的一部分
Python 推断基础
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Compute the volatility of Bitcoin
btc_sp_df['Volatility_BTC'] = ____
# Compute the volatility of the S&P500
btc_sp_df['Volatility_SP500'] = ____
# Compute and print R^2 between the volatility of BTC and SP500
r_volatility, p_value_volatility = ____
print('R^2 between volatility of the assets:', ____)
# Compute and print R^2 between the volatility of BTC and the closing price of BTC
r_closing, p_value_closing = ____
print('R^2 between closing price and volatility of BTC:', ____)