Histograms

Finance를 위한 Python 입문

Adina Howe

Professor

Why histograms for financial analysis?

histogram

Finance를 위한 Python 입문

Histograms and Data

  • Is your data skewed?
  • Is your data centered around the average?
  • Do you have any abnormal data points (outliers) in your data?
Finance를 위한 Python 입문

Histograms and matplotlib.pyplot

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

hist1

Finance를 위한 Python 입문

Changing the number of bins

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

hist2

Finance를 위한 Python 입문

Normalizing histogram data

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

normed

Finance를 위한 Python 입문

Layering histograms on a plot

import matplotlib.pyplot as plt
plt.hist(x=prices, bins=6, density=True)
plt.hist(x=prices_new, bins=6, density=True)
plt.show()
Finance를 위한 Python 입문

Histogram result

two_hist_normed

Finance를 위한 Python 입문

Alpha: Changing transparency of histograms

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()
Finance를 위한 Python 입문

Histogram result

two-hist-transparent

Finance를 위한 Python 입문

Adding a legend

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()
Finance를 위한 Python 입문

Histogram result

pretty hist

Finance를 위한 Python 입문

Let's practice!

Finance를 위한 Python 입문

Preparing Video For Download...