Skip to content

Commit

Permalink
quandl country code fix
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-jansen committed Feb 26, 2021
1 parent 5f491dc commit b33e5c9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 23 deletions.
16 changes: 8 additions & 8 deletions etc/dev-install
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@ python -m pip install pip==19.2.2 'setuptools<46' $@
# Install external requirements first: if they share any of our
# transitive dependencies, we want our pinned versions to win.
if [ "${EXTERNAL_REQUIREMENTS:-}" ]; then
# Note: If EXTERNAL_REQUIREMENTS is unset, the expression in the
# above test expands to the empty string, which fails the test.
# (Simply expanding $EXTERNAL_REQUIREMENTS causes an error with the
# -u option, which helps prevent many other kinds of errors.)
echo "Installing additional packages: $EXTERNAL_REQUIREMENTS"
python -m pip install "$EXTERNAL_REQUIREMENTS" $@
# Note: If EXTERNAL_REQUIREMENTS is unset, the expression in the
# above test expands to the empty string, which fails the test.
# (Simply expanding $EXTERNAL_REQUIREMENTS causes an error with the
# -u option, which helps prevent many other kinds of errors.)
echo "Installing additional packages: $EXTERNAL_REQUIREMENTS"
python -m pip install "$EXTERNAL_REQUIREMENTS" $@
fi

# These have to be installed first so that the other requirements can be
# compiled against the specific versions we use.
python -m pip install -r etc/requirements_build.in -c etc/requirements_locked.txt $@
python -m pip install -r etc/requirements_build.in -c etc/requirements_py36_locked.txt $@

# XXX: bcolz has to be compiled against our specific version of numpy:
# by default, it uses an incompatible pre-compiled binary.
python -m pip install --no-binary=bcolz -e .[all] -r etc/requirements_blaze.in -c etc/requirements_locked.txt $@
python -m pip install --no-binary=bcolz -e .[all] -r etc/requirements_blaze.in -c etc/requirements_py36_locked.txt $@

# TODO: resolve these error messages:
# flake8 3.6.0 has requirement setuptools>=30, but you'll have setuptools 28.8.0 which is incompatible.
Expand Down
19 changes: 10 additions & 9 deletions zipline/assets/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
from . import (
Asset, Equity, Future,
)
from . continuous_futures import (
from .continuous_futures import (
ADJUSTMENT_STYLES,
CHAIN_PREDICATES,
ContinuousFuture,
Expand Down Expand Up @@ -230,11 +230,11 @@ def _convert_asset_timestamp_fields(dict_):

CONTINUOUS_FUTURE_ROLL_STYLE_IDS = {
'calendar': 0,
'volume': 1,
'volume' : 1,
}

CONTINUOUS_FUTURE_ADJUSTMENT_STYLE_IDS = {
None: 0,
None : 0,
'div': 1,
'add': 2,
}
Expand Down Expand Up @@ -295,6 +295,7 @@ class AssetFinder(object):
--------
:class:`zipline.assets.AssetDBWriter`
"""

@preprocess(engine=coerce_string_to_eng(require_exists=True))
def __init__(self, engine, future_chain_predicates=CHAIN_PREDICATES):
self.engine = engine
Expand Down Expand Up @@ -1099,8 +1100,8 @@ def lookup_future_symbol(self, symbol):
"""

data = self._select_asset_by_symbol(self.futures_contracts, symbol)\
.execute().fetchone()
data = self._select_asset_by_symbol(self.futures_contracts, symbol) \
.execute().fetchone()

# If no data found, raise an exception
if not data:
Expand Down Expand Up @@ -1202,7 +1203,7 @@ def _get_contract_sids(self, root_symbol):
list(sa.select((fc_cols.sid,)).where(
(fc_cols.root_symbol == root_symbol) &
(fc_cols.start_date != pd.NaT.value)).order_by(
fc_cols.sid).execute().fetchall())]
fc_cols.sid).execute().fetchall())]

def _get_root_symbol_exchange(self, root_symbol):
fc_cols = self.futures_root_symbols.c
Expand Down Expand Up @@ -1571,9 +1572,9 @@ def was_active(reference_date_value, asset):
Whether or not the `asset` existed at the specified time.
"""
return (
asset.start_date.value
<= reference_date_value
<= asset.end_date.value
asset.start_date.value
<= reference_date_value
<= asset.end_date.value
)


Expand Down
15 changes: 9 additions & 6 deletions zipline/data/bundles/quandl.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def format_metadata_url(api_key):
query_params = [('api_key', api_key), ('qopts.export', 'true')]

return (
QUANDL_DATA_URL + urlencode(query_params)
QUANDL_DATA_URL + urlencode(query_params)
)


Expand Down Expand Up @@ -65,7 +65,7 @@ def load_data_table(file,

data_table.rename(
columns={
'ticker': 'symbol',
'ticker' : 'symbol',
'ex-dividend': 'ex_dividend',
},
inplace=True,
Expand Down Expand Up @@ -141,7 +141,7 @@ def parse_splits(data, show_progress):
data.rename(
columns={
'split_ratio': 'ratio',
'date': 'effective_date',
'date' : 'effective_date',
},
inplace=True,
copy=False,
Expand All @@ -157,7 +157,7 @@ def parse_dividends(data, show_progress):
data.rename(
columns={
'ex_dividend': 'amount',
'date': 'ex_date',
'date' : 'ex_date',
},
inplace=True,
copy=False,
Expand Down Expand Up @@ -211,7 +211,11 @@ def quandl_bundle(environ,
raw_data[['symbol', 'date']],
show_progress
)
asset_db_writer.write(asset_metadata)

exchanges = pd.DataFrame(data=[['QUANDL', 'QUANDL', 'US']],
columns=['exchange', 'canonical_name', 'country_code'])
asset_db_writer.write(equities=asset_metadata,
exchanges=exchanges)

symbol_map = asset_metadata.symbol
sessions = calendar.sessions_in_range(start_session, end_session)
Expand Down Expand Up @@ -318,7 +322,6 @@ def quantopian_quandl_bundle(environ,
cache,
show_progress,
output_dir):

if show_progress:
data = download_with_progress(
QUANTOPIAN_QUANDL_URL,
Expand Down

0 comments on commit b33e5c9

Please sign in to comment.