Histogrammes

Introduction à Python pour la finance

Adina Howe

Professor

Pourquoi des histogrammes en finance ?

histogramme

Introduction à Python pour la finance

Histogrammes et données

  • Vos données sont-elles asymétriques ?
  • Sont-elles centrées autour de la moyenne ?
  • Avez-vous des valeurs anormales (outliers) ?
Introduction à Python pour la finance

Histogrammes et matplotlib.pyplot

import matplotlib.pyplot as plt
plt.hist(x=prices, bins=3)
plt.show()

hist1

Introduction à Python pour la finance

Modifier le nombre de classes

import matplotlib.pyplot as plt
plt.hist(prices, bins=6)
plt.show()

hist2

Introduction à Python pour la finance

Normaliser l’histogramme

import matplotlib.pyplot as plt
plt.hist(prices, bins=6, density=True)
plt.show()

normalisé

Introduction à Python pour la finance

Superposer des histogrammes

import matplotlib.pyplot as plt
plt.hist(x=prices, bins=6, density=True)
plt.hist(x=prices_new, bins=6, density=True)
plt.show()
Introduction à Python pour la finance

Résultat de l’histogramme

deux_hist_normés

Introduction à Python pour la finance

Alpha : régler la transparence

import matplotlib.pyplot as plt
plt.hist(x=prices, bins=6, density=True, alpha=0.5)
plt.hist(x=prices_new, bins=6, density=True, alpha=0.5)
plt.show()
Introduction à Python pour la finance

Résultat de l’histogramme

deux-hist-transparents

Introduction à Python pour la finance

Ajouter une légende

import matplotlib.pyplot as plt
plt.hist(x=prices, bins=6, density=True, alpha=0.5, label="Prices 1")
plt.hist(x=prices_new, bins=6, density=True, alpha=0.5, label="Prices New")
plt.legend()
plt.show()
Introduction à Python pour la finance

Résultat de l’histogramme

joli hist

Introduction à Python pour la finance

Passons à la pratique !

Introduction à Python pour la finance

Preparing Video For Download...