Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- import numpy as np
- import requests
- from scipy.stats import norm
- from scipy.stats import spearmanr
- from tqdm.notebook import tqdm
- import matplotlib.pyplot as plt
- prediction_corr = 0.02
- N = 5000
- rounds = 20
- iterations = 1000
- corr_paths = []
- for _ in tqdm(range(iterations)):
- # Generate random walk
- random_walk = norm.rvs(0,1, (rounds, N))
- # Generate final
- final = random_walk.sum(axis=0)
- # Generate noise of same distribution
- noise = norm.rvs(0,1, (rounds, N)).sum(axis=0)
- # Generate predictions
- predictions = final * prediction_corr + (1-prediction_corr**2)*noise
- # Generate round path
- corr_path = []
- for i in range(rounds):
- # Preliminary score is the corr vs current standings of random walk
- corr_path.append(spearmanr(predictions, random_walk[:i+1].sum(axis=0))[0])
- corr_paths.append(corr_path)
- # Differentiate to get corr increments and take standard deviation per day
- plt.plot(np.diff(np.array(corr_paths).T,axis=0).std(axis=1))
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement