matplotlib.finance
¶A collection of functions for collecting, analyzing and plotting financial data. User contributions welcome!
This module is deprecated in 1.4 and will be moved to mpl_toolkits
or it’s own project in the future.
matplotlib.finance.
candlestick2_ochl
(ax, opens, closes, highs, lows, width=4, colorup='k', colordown='r', alpha=0.75)¶Represent the open, close as a bar line and high low range as a vertical line.
Preserves the original argument order.
Parameters:  ax :
opens : sequence
closes : sequence
highs : sequence
lows : sequence
ticksize : int
colorup : color
colordown : color
alpha : float


Returns:  ret : tuple

matplotlib.finance.
candlestick2_ohlc
(ax, opens, highs, lows, closes, width=4, colorup='k', colordown='r', alpha=0.75)¶Represent the open, close as a bar line and high low range as a vertical line.
NOTE: this code assumes if any value open, low, high, close is missing they all are missing
Parameters:  ax :
opens : sequence
highs : sequence
lows : sequence
closes : sequence
ticksize : int
colorup : color
colordown : color
alpha : float


Returns:  ret : tuple

matplotlib.finance.
candlestick_ochl
(ax, quotes, width=0.2, colorup='k', colordown='r', alpha=1.0)¶Plot the time, open, close, high, low as a vertical line ranging from low to high. Use a rectangular bar to represent the openclose span. If close >= open, use colorup to color the bar, otherwise use colordown
Parameters:  ax :
quotes : sequence of (time, open, close, high, low, ...) sequences
width : float
colorup : color
colordown : color
alpha : float


Returns:  ret : tuple

matplotlib.finance.
candlestick_ohlc
(ax, quotes, width=0.2, colorup='k', colordown='r', alpha=1.0)¶Plot the time, open, high, low, close as a vertical line ranging from low to high. Use a rectangular bar to represent the openclose span. If close >= open, use colorup to color the bar, otherwise use colordown
Parameters:  ax :
quotes : sequence of (time, open, high, low, close, ...) sequences
width : float
colorup : color
colordown : color
alpha : float


Returns:  ret : tuple

matplotlib.finance.
fetch_historical_yahoo
(ticker, date1, date2, cachename=None, dividends=False)¶Fetch historical data for ticker between date1 and date2. date1 and date2 are date or datetime instances, or (year, month, day) sequences.
Parameters:  ticker : str
date1 : sequence of form (year, month, day),
date2 : sequence of form (year, month, day),
cachename : str
dividends : bool


Returns:  file_handle : file handle

Examples
>>> fh = fetch_historical_yahoo('^GSPC', (2000, 1, 1), (2001, 12, 31))
matplotlib.finance.
index_bar
(ax, vals, facecolor='b', edgecolor='l', width=4, alpha=1.0)¶Add a bar collection graph with height vals (1 is missing).
Parameters:  ax :
vals : sequence
facecolor : color
edgecolor : color
width : int
alpha : float


Returns:  ret :

matplotlib.finance.
md5
(x)¶matplotlib.finance.
parse_yahoo_historical_ochl
(fh, adjusted=True, asobject=False)¶Parse the historical data in file handle fh from yahoo finance.
Parameters:  adjusted : bool
asobject : bool or None


matplotlib.finance.
parse_yahoo_historical_ohlc
(fh, adjusted=True, asobject=False)¶Parse the historical data in file handle fh from yahoo finance.
Parameters:  adjusted : bool
asobject : bool or None


matplotlib.finance.
plot_day_summary2_ochl
(ax, opens, closes, highs, lows, ticksize=4, colorup='k', colordown='r')¶Represent the time, open, close, high, low, as a vertical line ranging from low to high. The left tick is the open and the right tick is the close.
Parameters:  ax :
opens : sequence
closes : sequence
highs : sequence
lows : sequence
ticksize : int
colorup : color
colordown : color


Returns:  ret : list

matplotlib.finance.
plot_day_summary2_ohlc
(ax, opens, highs, lows, closes, ticksize=4, colorup='k', colordown='r')¶Represent the time, open, high, low, close as a vertical line ranging from low to high. The left tick is the open and the right tick is the close. opens, highs, lows and closes must have the same length. NOTE: this code assumes if any value open, high, low, close is missing (1) they all are missing
Parameters:  ax :
opens : sequence
highs : sequence
lows : sequence
closes : sequence
ticksize : int
colorup : color
colordown : color


Returns:  ret : list

matplotlib.finance.
plot_day_summary_oclh
(ax, quotes, ticksize=3, colorup='k', colordown='r')¶Plots day summary
Represent the time, open, close, high, low as a vertical line ranging from low to high. The left tick is the open and the right tick is the close.
Parameters:  ax :
quotes : sequence of (time, open, close, high, low, ...) sequences
ticksize : int
colorup : color
colordown : color


Returns:  lines : list

matplotlib.finance.
plot_day_summary_ohlc
(ax, quotes, ticksize=3, colorup='k', colordown='r')¶Plots day summary
Represent the time, open, high, low, close as a vertical line ranging from low to high. The left tick is the open and the right tick is the close.
Parameters:  ax :
quotes : sequence of (time, open, high, low, close, ...) sequences
ticksize : int
colorup : color
colordown : color


Returns:  lines : list

matplotlib.finance.
quotes_historical_yahoo_ochl
(ticker, date1, date2, asobject=False, adjusted=True, cachename=None)¶Get historical data for ticker between date1 and date2.
See parse_yahoo_historical()
for explanation of output formats
and the asobject and adjusted kwargs.
Parameters:  ticker : str
date1 : sequence of form (year, month, day),
date2 : sequence of form (year, month, day),
cachename : str or


Examples
>>> sp = f.quotes_historical_yahoo_ochl('^GSPC', d1, d2,
asobject=True, adjusted=True)
>>> returns = (sp.open[1:]  sp.open[:1])/sp.open[1:]
>>> [n,bins,patches] = hist(returns, 100)
>>> mu = mean(returns)
>>> sigma = std(returns)
>>> x = normpdf(bins, mu, sigma)
>>> plot(bins, x, color='red', lw=2)
matplotlib.finance.
quotes_historical_yahoo_ohlc
(ticker, date1, date2, asobject=False, adjusted=True, cachename=None)¶Get historical data for ticker between date1 and date2.
See parse_yahoo_historical()
for explanation of output formats
and the asobject and adjusted kwargs.
Parameters:  ticker : str
date1 : sequence of form (year, month, day),
date2 : sequence of form (year, month, day),
cachename : str or


Examples
>>> sp = f.quotes_historical_yahoo_ohlc('^GSPC', d1, d2,
asobject=True, adjusted=True)
>>> returns = (sp.open[1:]  sp.open[:1])/sp.open[1:]
>>> [n,bins,patches] = hist(returns, 100)
>>> mu = mean(returns)
>>> sigma = std(returns)
>>> x = normpdf(bins, mu, sigma)
>>> plot(bins, x, color='red', lw=2)
matplotlib.finance.
volume_overlay
(ax, opens, closes, volumes, colorup='k', colordown='r', width=4, alpha=1.0)¶Add a volume overlay to the current axes. The opens and closes are used to determine the color of the bar. 1 is missing. If a value is missing on one it must be missing on all
Parameters:  ax :
opens : sequence
closes : sequence
volumes : sequence
width : int
colorup : color
colordown : color
alpha : float


Returns:  ret :

matplotlib.finance.
volume_overlay2
(ax, closes, volumes, colorup='k', colordown='r', width=4, alpha=1.0)¶Add a volume overlay to the current axes. The closes are used to determine the color of the bar. 1 is missing. If a value is missing on one it must be missing on all
nb: first point is not displayed  it is used only for choosing the right color
Parameters:  ax :
closes : sequence
volumes : sequence
width : int
colorup : color
colordown : color
alpha : float


Returns:  ret :

matplotlib.finance.
volume_overlay3
(ax, quotes, colorup='k', colordown='r', width=4, alpha=1.0)¶Add a volume overlay to the current axes. quotes is a list of (d, open, high, low, close, volume) and closeopen is used to determine the color of the bar
Parameters:  ax :
quotes : sequence of (time, open, high, low, close, ...) sequences
width : int
colorup : color
colordown : color
alpha : float


Returns:  ret :
