开始使用免费开始使用

Permutation tests for correlations

How does the volatility of Bitcoin compare to the volatility of the S&P 500?

You previously computed volatility as the percent daily change, which has been stored for you in the Pct_Daily_Change_BTC and Pct_Daily_Change_SP500 columns in your data. The question you want to answer is the extent to which these two values correlate. One way to answer this is through a permutation test. By randomly shuffling values between the S&P 500 and BTC you are able to see what a random outcome would like like, and then compare this to the observed values.

A DataFrame of S&P 500 and Bitcoin prices (btc_sp_df) has been loaded for you, as have the packages pandas as pd, NumPy as np, and stats from SciPy.

本练习是课程的一部分

Foundations of Inference in Python

查看课程

练习说明

  • Define a statistic() function which returns just the Pearson R value between two vectors.
  • Set your data equal to a tuple containing the volatility of BTC and SP500.
  • Conduct a permutation test with this data, statistic, 1000 resamples, and with an alternative hypothesis of greater volatility with Bitcoin.
  • Print if the p-value is significant at 5%.

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Define a function which returns the Pearson R value
def statistic(x, y):
	____

# Define the data as the percent daily change from each asset
data = ____

# Compute a permutation test for the percent daily change of each asset
res = ____(____, ____, 
           n_resamples=____,
           vectorized=____, 
           alternative='____')

# Print if the p-value is significant at 5%
print(res.pvalue < 0.05)
编辑并运行代码