Esempio n. 1
0
def gentrends(x, window=1 / 3.0, charts=True):
    """
    Returns a Pandas dataframe with support and resistance lines.

    :param x: One-dimensional data set
    :param window: How long the trendlines should be. If window < 1, then it
                   will be taken as a percentage of the size of the data
    :param charts: Boolean value saying whether to print chart to screen
    """

    import numpy as np
    import pandas.io.data as pd

    x = np.array(x)

    if window < 1:
        window = int(window * len(x))

    max1 = np.where(x == max(x))[0][0]  # find the index of the abs max
    min1 = np.where(x == min(x))[0][0]  # find the index of the abs min

    # First the max
    if max1 + window > len(x):
        max2 = max(x[0:(max1 - window)])
    else:
        max2 = max(x[(max1 + window):])

    # Now the min
    if min1 - window < 0:
        min2 = min(x[(min1 + window):])
    else:
        min2 = min(x[0:(min1 - window)])

    # Now find the indices of the secondary extrema
    max2 = np.where(x == max2)[0][0]  # find the index of the 2nd max
    min2 = np.where(x == min2)[0][0]  # find the index of the 2nd min

    # Create & extend the lines
    maxslope = (x[max1] - x[max2]) / (max1 - max2)  # slope between max points
    minslope = (x[min1] - x[min2]) / (min1 - min2)  # slope between min points
    a_max = x[max1] - (maxslope * max1)  # y-intercept for max trendline
    a_min = x[min1] - (minslope * min1)  # y-intercept for min trendline
    b_max = x[max1] + (maxslope * (len(x) - max1))  # extend to last data pt
    b_min = x[min1] + (minslope * (len(x) - min1))  # extend to last data point
    maxline = np.linspace(a_max, b_max, len(x))  # Y values between max's
    minline = np.linspace(a_min, b_min, len(x))  # Y values between min's

    # OUTPUT
    trends = np.transpose(np.array((x, maxline, minline)))
    trends = pd.DataFrame(trends,
                          index=np.arange(0, len(x)),
                          columns=['Data', 'Max Line', 'Min Line'])

    if charts is True:
        from matplotlib.pyplot import plot, grid, show
        plot(trends)
        grid()
        show()

    return trends, maxslope, minslope
Esempio n. 2
0
def stock(symbol):
    """ 
    gets last traded price from google for given security
    """
    import pandas.io.data as pd

    df = pd.get_quote_yahoo(symbol)
    #print(df)

    cols = ['PE', 'change_pct', 'last', 'short_ratio', 'time']
    result = pd.DataFrame(df, columns=cols)
    return result.iloc[0]['last']
Esempio n. 3
0
def getPrice(start, end , company):
    allStock = {}
    startDate = start
    endDate = end
    listOfCompanies = company
    for ticket in listOfCompanies:
        allStock[ticket] = web.get_data_yahoo(ticket,startDate,endDate)
    
    price = web.DataFrame({tic:data['Adj Close'] for tic,data in allStock.iteritems()})
    sumStock = DataFrame(data = price.sum(axis=1),columns = ['individialStockSum'])
    sumStock['dowJones'] = Series(web.get_data_yahoo('DJIA',startDate,endDate)['Adj Close'],index = sumStock.index)
    return sumStock
Esempio n. 4
0
@author: jmalinchak
"""

#from pandas.io.data import DataReader
#from datetime import datetime
#msft = DataReader("MSFT",  "yahoo")
#print(msft.bid)

import pandas.io.data as pd 

df = pd.get_quote_yahoo('HPQ')
#print(df)

cols = ['PE', 'change_pct', 'last', 'short_ratio', 'time']
result = pd.DataFrame(df, columns=cols)
print(result.iloc[0]['last'])
#data = {'year': [2010, 2011, 2012, 2011, 2012, 2010, 2011, 2012],
#        'team': ['Bears', 'Bears', 'Bears', 'Packers', 'Packers', 'Lions', 'Lions', 'Lions'],
#        'wins': [11, 8, 10, 15, 11, 6, 10, 4],
#        'losses': [5, 8, 6, 1, 5, 10, 6, 12]}
#        
#football = pd.DataFrame(data, columns=['year', 'team', 'wins', 'losses'])
#print(football)
#
#from_csv = pd.read_csv('C:\\Documents and Settings\\jmalinchak\\My Documents\\My Python\\Active\inputs\\Options AAPL 2015-01-17 20141203221727.csv')
#from_csv.head()
#print(from_csv)
#
#cols = ['num', 'game', 'date', 'team', 'home_away', 'opponent',
#        'result', 'quarter', 'distance', 'receiver', 'score_before',