Advertisement
Guest User

decreasing variance of increments

a guest
Apr 12th, 2021
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.01 KB | None | 0 0
  1. import pandas as pd
  2. import numpy as np
  3. import requests
  4. from scipy.stats import norm
  5. from scipy.stats import spearmanr
  6. from tqdm.notebook import tqdm
  7. import matplotlib.pyplot as plt
  8.  
  9. prediction_corr = 0.02
  10. N = 5000
  11. rounds = 20
  12. iterations = 1000
  13.  
  14.  
  15. corr_paths = []
  16. for _ in tqdm(range(iterations)):
  17.   # Generate random walk
  18.   random_walk = norm.rvs(0,1, (rounds, N))
  19.   # Generate final
  20.   final = random_walk.sum(axis=0)
  21.   # Generate noise of same distribution
  22.   noise =  norm.rvs(0,1, (rounds, N)).sum(axis=0)
  23.   # Generate predictions
  24.   predictions = final * prediction_corr + (1-prediction_corr**2)*noise
  25.   # Generate round path
  26.   corr_path = []
  27.   for i in range(rounds):
  28.     # Preliminary score is the corr vs current standings of random walk
  29.     corr_path.append(spearmanr(predictions, random_walk[:i+1].sum(axis=0))[0])
  30.   corr_paths.append(corr_path)
  31.  
  32. # Differentiate to get corr increments and take standard deviation per day
  33. plt.plot(np.diff(np.array(corr_paths).T,axis=0).std(axis=1))
  34. plt.show()
  35.  
  36.  
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement