LoslegenKostenlos loslegen

Bootstrap confidence intervals

You previously saw that there is some degree of correlation between the S&P 500 and Bitcoin. One way to measure this would be to look at the correlation coefficient Pearson's R between the two. However, doing so results in only a point estimate. Presumably, at some points in time the correlation between the two is quite close, while at other times they behave very differently. How can you characterize the variability? One approach is to create a bootstrap confidence interval for the correlation coefficient between the two. That's precisely what you'll do now!

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.

Diese Übung ist Teil des Kurses

Foundations of Inference in Python

Kurs anzeigen

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# Compute the daily percent change of each asset
btc_sp_df['Pct_Daily_Change_BTC'] = (____['Open_BTC'] - ____['Close_BTC']) / ____['Open_BTC']
btc_sp_df['Pct_Daily_Change_SP500'] = ____

# Write a function which returns the correlation coefficient
def pearson_r(x, y):
    return stats.____[0]
  
# Compute a bootstrap confidence interval
ci = stats.bootstrap((____, ____), 
                     statistic=____, 
                     vectorized=False, paired=True, n_resamples=1000, random_state=1)

print(ci.confidence_interval)
Code bearbeiten und ausführen