def __init__(self, dates, fmt='%Y-%m-%d'): self.dates = dates self.fmt = fmt def __call__(self, x, pos=0): 'Return the label for time x at position pos' ind = int(round(x)) if ind>=len(self.dates) or ind<0: return '' return self.dates[ind].strftime(self.fmt) formatter= MyFormatter(data.vDate[daysToPlot:]) [per_k, per_d] = stochastic_oscillator.stoc_osc(data.vHigh, data.vLow, data.vClose,15,5,5,"ema") plt.figure(1) ax1 = plt.subplot('411') candlestick2(ax1, data.vOpen[daysToPlot:],data.vClose[daysToPlot:],data.vHigh[daysToPlot:],data.vLow[daysToPlot:], width=0.6) [macdOut, ema, divergence] = macd.macd(data.vClose, 12,26, 9) ax2 = plt.subplot('412') ax2.plot(macdOut[daysToPlot:]) ax2.plot( ema[daysToPlot:]) ax2.stem(arange(-1*daysToPlot), divergence[daysToPlot:]) # MACD [macdOut, ema, divergence] = macd.macd(data.vClose, 5,10, 4) ax2 = plt.subplot('413') ax2.plot(macdOut[daysToPlot:]) ax2.plot( ema[daysToPlot:])
################################################################################ # Copyright (C) 2010 Ray M. Salem # http://code.google.com/p/finance-py/ # Distributed under the GPL license Version 3.0 ( See accompanying file # License_ or copy at http://code.google.com/p/finance-py/LICENSE) ################################################################################ from numpy import * from scipy import * import sys sys.path.append("../src/") import stochastic_oscillator high = array([ 34.7500, 34.7500, 34.2188, 33.8281, 33.4755, 33.4688, 34.3750, 34.7188, 34.6250, 34.9219 ]) low = array([ 33.5312, 33.9062, 33.6875, 33.2500, 33.0000, 32.9375, 33.2500, 34.0469, 33.9375, 34.0625 ]) close = array([ 34.3125, 32.1250, 33.7500, 33.6406, 33.0156, 33.0469, 34.2969, 34.1406, 34.5469, 34.3281 ]) d_method = 'ema' [per_k, per_d] = stochastic_oscillator.stoc_osc(high, low, close, 5, 3, 3, d_method)
################################################################################ # Copyright (C) 2010 Ray M. Salem # http://code.google.com/p/finance-py/ # Distributed under the GPL license Version 3.0 ( See accompanying file # License_ or copy at http://code.google.com/p/finance-py/LICENSE) ################################################################################ from numpy import * from scipy import * import sys sys.path.append("../src/") import stochastic_oscillator high = array([34.7500, 34.7500, 34.2188, 33.8281, 33.4755, 33.4688, 34.3750, 34.7188, 34.6250,34.9219]); low = array([33.5312, 33.9062, 33.6875, 33.2500, 33.0000, 32.9375, 33.2500, 34.0469, 33.9375,34.0625]); close = array([34.3125, 32.1250, 33.7500, 33.6406, 33.0156, 33.0469, 34.2969, 34.1406, 34.5469,34.3281]); d_method = 'ema' [per_k, per_d] = stochastic_oscillator.stoc_osc(high, low, close, 5,3,3, d_method)
class MyFormatter(Formatter): def __init__(self, dates, fmt='%Y-%m-%d'): self.dates = dates self.fmt = fmt def __call__(self, x, pos=0): 'Return the label for time x at position pos' ind = int(round(x)) if ind >= len(self.dates) or ind < 0: return '' return self.dates[ind].strftime(self.fmt) formatter = MyFormatter(data.vDate[daysToPlot:]) [per_k, per_d] = stochastic_oscillator.stoc_osc(data.vHigh, data.vLow, data.vClose, 15, 5, 5, "ema") plt.figure(1) ax1 = plt.subplot('411') candlestick2(ax1, data.vOpen[daysToPlot:], data.vClose[daysToPlot:], data.vHigh[daysToPlot:], data.vLow[daysToPlot:], width=0.6) [macdOut, ema, divergence] = macd.macd(data.vClose, 12, 26, 9) ax2 = plt.subplot('412') ax2.plot(macdOut[daysToPlot:]) ax2.plot(ema[daysToPlot:]) ax2.stem(arange(-1 * daysToPlot), divergence[daysToPlot:])