Exemplo n.º 1
0
import pandas as pd
import numpy as np
import pickle

from scipy import stats
import os
from dateutil.tz import tzutc
from dateutil.parser import parse
import statsmodels.api as sm
from alphacompiler.util.zipline_data_tools import fast_corr, fast_cov

SECTOR_ETF_RETURNS_FILE = '../data/sector_etf_returns.csv'  # todo: put this in constants file
MAPPING_FILE = '../data/sector_mappings.pkl'
NUM_SEC = 20  # Number of securities per side (long or short)
SPY_PATH = "%s/data/SPY.csv" % zipline_root()

GICSNAME2ETF = {
    'Energy': 'XLE',
    'Materials': 'XLB',
    'Industrials': 'XLI',
    'Consumer Discretionary': 'XLY',
    'Consumer Staples': 'XLP',
    'Health Care': 'XLV',
    'Financials': 'XLF',
    'Information Technology': 'XLK',
    'Communication Services': 'IYZ',
    'Utilities': 'XLU',
    'Real Estate': 'IYR',
    'Unmappable': 'SPY'
}
Exemplo n.º 2
0
    def __init__(self, *args, **kwargs):
        super(Fundamentals, self).__init__(*args, **kwargs)
        self.N = len(get_ticker_sid_dict_from_bundle(
            "sep")) + 1  # max(sid)+1 get this from the bundle

        self.data_path = zipline_root() + '/data/SF1.npy'
Exemplo n.º 3
0
Created by Peter Harrington (pbharrin) on 8/5/19.
"""

import pandas as pd
import numpy as np
from alphacompiler.util.zipline_data_tools import get_ticker_sid_dict_from_bundle
from zipline.data.bundles.core import register

from alphacompiler.util.database_util import create_static_table_from_database

from zipline.utils.paths import zipline_root

TICKER_FILE = '/Users/peterharrington/Downloads/SHARADAR_TICKERS_6cc728d11002ab9cb99aa8654a6b9f4e.csv'
BUNDLE_NAME = 'sep'

ZIPLINE_DATA_DIR = zipline_root() + '/data/'
SID_FILE = "SHARDAR_sectors.npy"  # persisted np.array
STATIC_FILE = "SHARDAR_static.npy"  # persisted np.array

SECTOR_CODING = {
    'Technology': 0,
    'Industrials': 1,
    'Energy': 2,
    'Utilities': 3,
    'Consumer Cyclical': 4,
    'Healthcare': 5,
    'Financial Services': 6,
    'Basic Materials': 7,
    'Consumer Defensive': 8,
    'Real Estate': 9,
    'Communication Services': 10,
import datetime
import quandl
import os
from zipline.data.bundles.core import load
import pandas as pd
import numpy as np
from zipline.utils.paths import zipline_root
from logbook import Logger, StderrHandler
from alphacompiler.util import quandl_tools
from alphacompiler.util.sparse_data import SparseDataFactor
import pickle

KERNEL_BUNDLE = 'sharadar-prices'
DATA_FILE = zipline_root(
) + '/data/SF1.npy'  # the file name to be used when storing this in ~/.zipline/data
FUNDAMENTAL_FIELDS_FILE = zipline_root() + '/data/SF1.pkl'

log = Logger('quandl_fundamentals.py')


class Fundamentals(SparseDataFactor):
    try:
        with open(FUNDAMENTAL_FIELDS_FILE, 'rb') as f:
            outputs = pickle.load(f)
    except:
        outputs = []

    def __init__(self, *args, **kwargs):
        super(Fundamentals, self).__init__(*args, **kwargs)
        self.N = len(get_tickers_from_bundle(KERNEL_BUNDLE))
        self.data_path = DATA_FILE