Get startedGet started for free

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.

This exercise is part of the course

Foundations of Inference in Python

View Course

Exercise instructions

  • 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%.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# 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)
Edit and Run Code