Histograms

ファイナンスのためのPython入門

Adina Howe

Professor

Why histograms for financial analysis?

histogram

ファイナンスのための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?
ファイナンスのためのPython入門

Histograms and matplotlib.pyplot

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

hist1

ファイナンスのためのPython入門

Changing the number of bins

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

hist2

ファイナンスのためのPython入門

Normalizing histogram data

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

normed

ファイナンスのための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()
ファイナンスのためのPython入門

Histogram result

two_hist_normed

ファイナンスのための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()
ファイナンスのためのPython入門

Histogram result

two-hist-transparent

ファイナンスのための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()
ファイナンスのためのPython入門

Histogram result

pretty hist

ファイナンスのためのPython入門

Let's practice!

ファイナンスのためのPython入門

Preparing Video For Download...