Example #1
0
def get_quote_database(table, symbol, timerange):
    '''
    table: sqlite3 database table object
    database primary key: date in mdates ordinal format
    return: pandas dataframe
    '''

    selection = True

    if len(timerange) == 1:
        od1 = int(mdates.date2num(timerange[0]))
        od2 = od1 + 1
    elif len(timerange) == 2:
        od1 = int(mdates.date2num(timerange[0]))
        od2 = int(mdates.date2num(timerange[1])) + 1

    print 'request range:', [od1, od2]

    ts1, ts2 = table.get_timestamp_range()
    print 'available data range: ', [ts1, ts2]

    if ts1 and ts2:
        if (od2 < ts1) or (od1 > ts2):
            selection = False

    if selection is True:
        data = table.to_dataframe([od1, od2])
        print data.head()
        return data
    else:
        print "no selection available"
        return pd.DataFrame({})
Example #2
0
def quandl_api(userticker,scraped_data):
    tickers = [userticker];
    # api call to quandl, gte and lte are data bounds
    data = quandl.get_table('WIKI/PRICES', ticker = tickers,
                                qopts = { 'columns': ['ticker', 'date', 'adj_close'] },
                                date = { 'gte': '2018-01-19', 'lte': '2018-10-20' },
                                paginate=True)
    print(data.head(1))
    # get most recent entry
    onedata=data.head(1)
    onedata = onedata.reset_index()
    lastdate = onedata[['date'][0]]
    lastdatevalue = lastdate[0]
    lastclosing = onedata[['adj_close'][0]]
    lastclosingvalue = float(lastclosing[0])
    
    
    #convert date to human readable format
    readabledate = "{:%B %d, %Y}".format(lastdatevalue)

    # extract last closing of stock and conver to number
    stripcomma = scraped_data["Previous Close"]
    stripcomma = stripcomma.replace(',' , '')
    currentclose = float(stripcomma)

    # find difference in closing value
    diff = currentclose - lastclosingvalue
    diff = round(diff,2)

    print(str(userticker), ' has had a change of', str(diff), 'since', readabledate)

    # add change to scraped data file
    strwrite = str(diff) + ' from ' + readabledate
    scraped_data["change"] = strwrite
Example #3
0
import pandas as pd
from pandas_datareader import data

start_date = '2019-01-01'
end_date = '2020-01-01'
ticker = 'AMZN'

data = data.get_data_yahoo(ticker, start_date, end_date)
data.head()

import matplotlib.pyplot as plt
from matplotlib import inline
from astropy.utils.tests import data
data['Adj Close'].plot(figsize=(10, 7))
plt.title('Adjusted Close Price of %s' % ticker, fontsize=16)
plt.ylabel('Price', fontsize=14)
plt.xlabel('Year', fontsize=14)
plt.grid(which='major', color='k', linestyle='_.', linewidth=0.5)
plt.show()
Example #4
0
# Rolling Windows
rolling = goog.rolling(365, center = True)
data = pd.DataFrame({'input': goog,
                     'one-year rolling_mean': rolling.mean(),
                     'one-year rolling_std': rolling.std()})
ax = data.plot(style = ['-', '--', ':'])
ax.lines[0].set_alpha(0.3)


#%%
# example: Visualizing Seattle Bycicle Counts
data = pd.read_csv('data/Fremont_Bridge.csv', index_col = 'Date',
                   parse_dates =True)

#%%
print(data.head())
print(data.columns)
#%%
data.columns = ['Total', 'East', 'West']

#%%
data.dropna().describe()

#%%
# Visualizing the data
data.plot()
plt.ylabel('Hourly Bicycle Count')

#%% resample data to a coarser grid
weekly = data.resample('W').sum()
weekly.plot(style = [':', '--', '-'])
Example #5
0
def get_data_summary(data):
    print("datasize: ", len(data))
    print("No. of columns : ", len(data.columns))
    print("\nColumn List:", list(data.columns), "\n")
    print("\n data glimpse\n")
    print(data.head())
from datetime import date
from sklearn.neural_network import MLPRegressor
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error

from pandas.plotting import scatter_matrix

# In[2]:

data = pd.read_csv(
    '/Users/xiangliu/Desktop/CSC560 Data/pollution_us_2000_2016.csv')
data.shape

# In[3]:

data.head(3)

# In[4]:

le = data['CO AQI']
le[le.isnull()]

# In[5]:

##Look Into each value
data = data.dropna()
data.to_csv("/Users/xiangliu/Desktop/CSC560 Data/pollution_AQI.csv",
            index=True,
            sep=',')

# In[6]:
import pandas_datareader as pdr
df = pdr.get_data_fred('GS10')
#https://fred.stlouisfed.org/series/GS10
df.shape
df.head()

import pandas as pd
from pandas_datareader import data
# Set the start and end date
start_date = '1990-01-01'
end_date = '2019-04-27'
# Set the ticker
ticker = 'AMZN'
# Get the data
data = data.get_data_yahoo(ticker, start_date, end_date)
data.head()
data.shape

df = data.drop(['Volume'], axis=1)

import matplotlib.pyplot as plt
data['Adj Close'].plot()
df.plot()
plt.savefig('pandas_datareader_demo1.png')



import yfinance as yf
data = yf.download("SPY AAPL", start="2017-01-01", end="2017-04-30")
data.shape
data.head(10)
# quantrautil is a module specific to Quantra to fetch stock data
from quantrautil import get_quantinsti_api_key
api_key = get_quantinsti_api_key()

data = quandl.get('EOD/AAPL', start_date='2017-1-1', end_date='2018-1-1', api_key= api_key)

# Note that you need to know the "Quandl code" of each dataset you download. In the above example, it is 'EOD/AAPL'.
# To get your personal API key, sign up for a free Quandl account. Then, you can find your API key on Quandl account settings page.
print("________________________")
print(data.head())'''

import pandas as pd
from pandas_datareader import data
data = data.get_data_yahoo('AAPL', '2017-01-01', '2018-01-01')
data.head()
print(data.head())

# Yahoo recently has become an unstable data source.
# If it gives an error, you may run the cell again, or try yfinance
import pandas as pd
from pandas_datareader import data
# Set the start and end date
start_date = '1990-01-01'
end_date = date.today()  #'2019-02-01'
# Set the ticker
ticker = 'AMZN'
# Get the data
data = data.get_data_yahoo(ticker, start_date, end_date)
data.head()