# -*- coding: utf-8 -*- """ A FAIRE: 1/ telecharger les cours des composantes du CAC40 (ou DJIA, ou ...) en prix journaliers (au moins le "close") si possible depuis 5 ans Idee: utiliser yahoo comme source et par exemple yfinance "pip install yfinance" Sinon prendre le fichier https://turinici.com/wp-content/uploads/cours/common/close_cac40_historical.csv 1'/ ordonner par date croissante 2/ dessiner l'histograme du prix et du rendement (avec "log" et "actuariel") 3/ tester la normalité des prix, celle des rendements log et "actuariel" (par exemple utiliser scipy.stats.normaltest) """ import pandas as pd import numpy as np import matplotlib.pyplot as plt from scipy.stats import normaltest,kstest from scipy.special import softmax # take csv from www cours data = pd.read_csv('close_cac40_historical.csv',sep=';', index_col = 'Date') data.head() data.sort_values(by='Date',inplace=True)#alternative "sort_index" data.head() data.tail() # plot histogram of prices _=data.hist(bins=30, figsize = (15,15)) def normality_test(data,kolmogorov_smirnov=False,level=0.01,print_results=True): """ Tests normality of each column of dataframe "data". Inputs: kolmogorov_smirnov= false: use "normaltest", otherswise use kstest, both from scipy.stats level = p-value threshold level for the conclusions Outputs: the number of yes/no in the results """ pvalues=[] for cols in data.keys(): # normality test if(kolmogorov_smirnov): pv=kstest(data[cols].dropna(),'norm').pvalue else: pv=normaltest(data[cols],nan_policy='omit').pvalue pvalues.append(pv) if(pv