<commit_before>import time
import datetime
import numpy as np
import matplotlib
import matplotlib.pyplot as mplot
import matplotlib.ticker as mticker
import matplotlib.dates as mdates
from matplotlib.finance import candlestick_ochl
# custom matplotlib parameters
matplotlib.rcParams.update({'font.size': 9})
import urllib2
stocks = 'AAPL', 'FB', 'UAA'

# compute the n period relative strength indicator
# matploblib finance example
def rsiFunction(prices, n=14):
	deltas = np.diff(prices)
	seed = deltas[:n+1]
	up = seed[seed >= 0].sum()/n
	down = -seed[seed < 0].sum()/n
	rs = up/down
	rsi = np.zeros_like(prices)
	rsi[:n] = 100. - 100./(1. + rs)

	for i in range(n, len(prices)):
		delta = deltas[i-1] # diff is 1 shorter

		if delta > 0:
			upval = delta
			downval = 0.
		else:
			upval = 0.
			downval = -delta

		up = (up * (n - 1) + upval)/n
		down = (down * (n - 1) + downval)/n

		rs = up/down
		rsi[i] = 100. - 100./(1. + rs)

	return rsi

def movingaverage(values, window):
	weights = np.repeat(1.0, window) / window
	# line smoothening
	smas = np.convolve(values, weights, 'valid')
	# list of values being returned as numpy array
	return smas

def ema(values, window):
	weights = np.exp(np.linspace(-1., 0., window))
	weights /= weights.sum()
	a = np.convolve(values, weights, mode='full')[:len(values)]
	a[:window] = a[window]
	return a

# macd line = 12ema - 26ema
# signal line = 9ema of the macd line
# histogram = macd line - signal line
def computeMACD(x, slow=26, fast=12):
	emaslow = ema(x, slow)
	emafast = ema(x, fast)
	return emaslow, emafast, emafast-emaslow

def graphData(stock, MA1, MA2):
	try:
		try:
			print 'pulling data on', stock
			urlToVisit = 'http://chartapi.finance.yahoo.com/instrument/1.0/' + stock + '/chartdata;type=quote;range=1y/csv'
			stockFile = []
			try:
				sourceCode = urllib2.urlopen(urlToVisit).read()
				splitSource = sourceCode.split('\n')<commit_msg>commenting<commit_after>import time
import datetime
import numpy as np
import matplotlib
import matplotlib.pyplot as mplot
import matplotlib.ticker as mticker
import matplotlib.dates as mdates
from matplotlib.finance import candlestick_ochl
# custom matplotlib parameters
matplotlib.rcParams.update({'font.size': 9})
import urllib2
stocks = 'AAPL', 'FB', 'UAA'

'''
compute the n period relative strength indicator
n=14 (periods) as a default developed by <NAME>
momentum oscillator that measures the speed and change of price movements
'''
def rsiFunction(prices, n=14):
	deltas = np.diff(prices)
	seed = deltas[:n+1]
	up = seed[seed >= 0].sum()/n
	down = -seed[seed < 0].sum()/n
	rs = up/down
	rsi = np.zeros_like(prices)
	rsi[:n] = 100. - 100./(1. + rs)

	for i in range(n, len(prices)):
		delta = deltas[i-1] # diff is 1 shorter

		if delta > 0:
			upval = delta
			downval = 0.
		else:
			upval = 0.
			downval = -delta

		up = (up * (n - 1) + upval)/n
		down = (down * (n - 1) + downval)/n

		rs = up/down
		rsi[i] = 100. - 100./(1. + rs)

	return rsi

def movingaverage(values, window):
	weights = np.repeat(1.0, window) / window
	# line smoothening
	smas = np.convolve(values, weights, 'valid')
	# list of values being returned as numpy array
	return smas

def ema(values, window):
	weights = np.exp(np.linspace(-1., 0., window))
	weights /= weights.sum()
	a = np.convolve(values, weights, mode='full')[:len(values)]
	a[:window] = a[window]
	return a

'''
macd line = 12ema - 26ema
signal line = 9ema of the macd line
histogram = macd line - signal line
12 - two trading weeks
26 - one trading month
9 - one and half trading week
http://www.forexabode.com/forex-school/technical-indicators/macd/
5-day trading week -> 10,22,7 or 10,22,8
'''
def computeMACD(x, slow=26, fast=12):
	emaslow = ema(x, slow)
	emafast = ema(x, fast)
	return emaslow, emafast, emafast-emaslow

def graphData(stock, MA1, MA2):
	try:
		try:
			print 'pulling data on', stock
			urlToVisit = 'http://chartapi.finance.yahoo.com/instrument/1.0/' + stock + '/chartdata;type=quote;range=1y/csv'
			stockFile = []
			try:
				sourceCode = urllib2.urlopen(urlToVisit).read()
				splitSource = sourceCode.split('\n')
{'fraction_non_alphanumeric': 0.13979019272993412, 'fraction_numerical': 0.027323737496950475, 'mean_word_length': 3.7453703703703702, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1366840', 'n_tokens_mistral': 1706, 'n_tokens_neox': 1546, 'n_words': 436}