Histogram

Introduktion till Python för finans

Adina Howe

Professor

Varför histogram för finansiell analys?

histogram

Introduktion till Python för finans

Histogram och data

  • Är datan skev?
  • Är datan centrerad kring medelvärdet?
  • Finns det avvikande datapunkter (outliers) i datan?
Introduktion till Python för finans

Histogram och matplotlib.pyplot

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

hist1

Introduktion till Python för finans

Ändra antalet intervall

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

hist2

Introduktion till Python för finans

Normalisera histogramdata

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

normed

Introduktion till Python för finans

Lägg histogram ovanpå varandra

import matplotlib.pyplot as plt
plt.hist(x=prices, bins=6, density=True)
plt.hist(x=prices_new, bins=6, density=True)
plt.show()
Introduktion till Python för finans

Histogramresultat

two_hist_normed

Introduktion till Python för finans

Alpha: justera histogrammens genomskinlighet

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()
Introduktion till Python för finans

Histogramresultat

two-hist-transparent

Introduktion till Python för finans

Lägga till en förklaring

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()
Introduktion till Python för finans

Histogramresultat

pretty hist

Introduktion till Python för finans

Nu kör vi en övning!

Introduktion till Python för finans

Preparing Video For Download...