Exemple #1
0
def read_modulate_data(data):
    """
        Data ingestion : Function to read and formulate the data
    """
    #data = pd.read_csv(data_file)
    data.fillna(data.mean(), inplace=True)
    df = data.copy()
    data.set_index("Date", inplace=True)
    data.index = pd.to_datetime(data.index)
    return data, df
Exemple #2
0
def getEquityDataFromCSV(path):
    data = pd.read_csv(path)
    new = data.set_index('date')
    new = new[::-1]
    new = new.pivot(columns='ticker')

    return new
Exemple #3
0
def getEquityData(tickers, qopts = { 'columns': ['ticker', 'date', 'adj_close', 'adj_open', 'adj_low', 'adj_high', 'adj_volume'] }, end_date = datetime.datetime.today().strftime('%Y-%m-%d'), start_date = "2015-01-01"):
    data = quandl.get_table('WIKI/PRICES', 
                            ticker = tickers, 
                            qopts = qopts, 
                            date={'gte':start_date, 'lte':end_date},
                            api_key='KB7ZyJpPrzE1zPpBX7xu')
    data = data.set_index('date')
    data = new[::-1]
    new = new.pivot(columns='ticker')
    return new
Exemple #4
0
def get_quandl_data(stocksList=['AAPL','AMZN','GOOGL','FB'], start_date='2017-01-01', end_date='2018-01-01'):
    with open('quandl_api.txt', 'r') as inf:
        apikey = inf.readline().strip()
    print('apikey=', apikey, 'now use file input')
    quandl.ApiConfig.api_key = apikey #  '-dJhdMB1EcYEkxzxEGMA' # 'your_api_key_here'
    # stocks = ['AAPL','AMZN','GOOGL','FB']
    stocks = stocksList
    data = quandl.get_table('WIKI/PRICES', ticker = stocks,
                            qopts = { 'columns': ['date', 'ticker', 'adj_close'] },
                            date = { 'gte': start_date, 'lte': end_date }, paginate=True)
    df = data.set_index('date')
    table = df.pivot(columns='ticker')
    table.columns = [col[1] for col in table.columns]
    return table
Exemple #5
0
    print('FF3 p-values:\n', FF3.pvalues)
    print('FF5 p-values:\n', FF5.pvalues)

    CAPM_coeff = CAPM.params
    FF3_coeff = FF3.params
    FF5_coeff = FF5.params

    results = pd.DataFrame({'CAPM_coeff': CAPM_coeff,
                            'CAPM_tstat': CAPM_tstat,
                            'FF3_coeff': FF3_coeff,
                            'FF3_tstat': FF3_tstat,
                            'FF5_coeff': FF5_coeff,
                            'FF5_tstat': FF5_tstat},
                           index=['Intercept', 'MKT', 'SMB', 'HML', 'RMW', 'CMA'])

    return results


ticker = 'AAPL'

tickerFile = ticker + '.csv'
data = pd.read_csv(tickerFile, parse_dates=['Date'])
data = data.sort_values(by='Date')
data.set_index('Date', inplace=True)

data['Returns'] = data['Adj Close'].pct_change()  # Create daily returns column
returns = data['Returns'].dropna()  # Remove values of N/A

capm = assetPrice(data)
print(capm)
Exemple #6
0
import datetime
tickers = ['AAPL', 'MSFT', 'NFLX', 'AMZN', 'GOOG']
start = datetime.datetime(2010, 1, 1)
end = datetime.datetime(2018, 12, 31)
df = pd.DataFrame([data.DataReader(ticker, 'yahoo', start, end)['Adj Close'] for ticker in tickers]).T
df.columns = tickers


#getting data by quandl
import quandl
quandl.ApiConfig.api_key = '-dJhdMB1EcYEkxzxEGMA' # 'your_api_key_here'
stocks = ['AAPL','AMZN','GOOGL','FB']
data = quandl.get_table('WIKI/PRICES', ticker = stocks,
                        qopts = { 'columns': ['date', 'ticker', 'adj_close'] },
                        date = { 'gte': '2016-1-1', 'lte': '2017-12-31' }, paginate=True)
df = data.set_index('date')
table = df.pivot(columns='ticker')
table.columns = [col[1] for col in table.columns]


# re-index by different date range  ; but it may not work.. range from Sun - Sat..., which df has no data ..
df = pd.DataFrame()
all_weeks = pd.date_range(start='2019-01-03', end='2019-12-31', freq='W')
df = df.loc[all_weeks]


# rolling function  on moving average
df['mah15'] = df['Aju Close'].rolling(15, center=True, win_type='hamming').mean()


# return
Exemple #7
0
# get the table for daily stock prices and,
# filter the table for selected tickers, columns within a time range
# set paginate to True because Quandl limits tables API to 10,000 rows per call

data = quandl.get_table('WIKI/PRICES',
                        ticker=['AAPL', 'MSFT', 'WMT'],
                        qopts={'columns': ['ticker', 'date', 'adj_close']},
                        date={
                            'gte': '2015-12-31',
                            'lte': '2016-12-31'
                        },
                        paginate=True)
data.head()

# create a new dataframe with 'date' column as index
new = data.set_index('date')

# use pandas pivot function to sort adj_close by tickers
clean_data = new.pivot(columns='ticker')

# check the head of the output
clean_data.head()

import quandl
import pandas as pd
import datetime
from datetime import timedelta
from pandas import ExcelWriter

quandl.ApiConfig.api_key = 'NL6weZFnRNw5q_L5-Nve'
tickers = ['BA', 'MSFT', 'ACN']