Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python 3.9 and zipline 1.4.1 #32

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions .github/workflows/ci-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,30 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6]
python-version: [3.9]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install TA-Lib
run: |
# Insatll talib
cd /tmp && \
curl -L https://downloads.sourceforge.net/project/ta-lib/ta-lib/0.4.0/ta-lib-0.4.0-src.tar.gz | \
tar xvz && \
cd /tmp/ta-lib && \
./configure --prefix=/usr && \
make && \
sudo make install

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
pip install pandas==0.22.0 numpy==1.19.4 scipy==1.5.4 pandas-datareader==0.8.1
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
python setup.py install
- name: Lint with flake8
Expand Down
4 changes: 2 additions & 2 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ name = "pypi"
[packages]
alpaca-trade-api = ">=0.37"
iexfinance = ">=0.4.1"
zipline = "==1.3.0"
zipline-reloaded = "*"
numpy = "*"

[dev-packages]
Expand All @@ -15,4 +15,4 @@ pytest-cov = "*"
flake8 = "*"

[requires]
python_version = "3.6"
python_version = "3.9"
1,076 changes: 642 additions & 434 deletions Pipfile.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions pipeline_live/data/alpaca/pricing_loader.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import numpy as np
import logbook
import pandas as pd
from interface import implements

from zipline.lib.adjusted_array import AdjustedArray
from zipline.pipeline.loaders.base import PipelineLoader
Expand All @@ -13,17 +14,16 @@
log = logbook.Logger(__name__)


class USEquityPricingLoader(PipelineLoader):
class USEquityPricingLoader(implements(PipelineLoader)):
"""
PipelineLoader for US Equity Pricing data
"""

def __init__(self):
cal = get_calendar('NYSE')

self._all_sessions = cal.all_sessions

def load_adjusted_array(self, columns, dates, symbols, mask):
def load_adjusted_array(self, domain, columns, dates, sids, mask):
# load_adjusted_array is called with dates on which the user's algo
# will be shown data, which means we need to return the data that would
# be known at the start of each date. We assume that the latest data
Expand All @@ -42,7 +42,7 @@ def load_adjusted_array(self, columns, dates, symbols, mask):
prices = alpaca.get_stockprices(chart_range)

dfs = []
for symbol in symbols:
for symbol in sids:
if symbol not in prices:
df = pd.DataFrame(
{c.name: c.missing_value for c in columns},
Expand Down
14 changes: 7 additions & 7 deletions pipeline_live/data/iex/fundamentals_loader.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import logging

import numpy as np

from interface import implements
from pipeline_live.data.sources import iex
from zipline.pipeline.loaders.base import PipelineLoader
from zipline.utils.numpy_utils import object_dtype

log = logging.getLogger(__name__)


class IEXEventLoader(PipelineLoader):
class IEXEventLoader(implements(PipelineLoader)):

def _safe_flat_getter(self, symbol, symbols, column):
data = symbols.get(symbol, None)
Expand All @@ -19,29 +19,29 @@ def _safe_flat_getter(self, symbol, symbols, column):
return out


def load_adjusted_array(self, columns, dates, symbols, mask):
def load_adjusted_array(self, domain, columns, dates, sids, mask):
symbol_dict = self._load()
out = {}
for c in columns:
data = np.array([
self._safe_flat_getter(symbol, symbol_dict, c)
for symbol in symbols
for symbol in sids
], dtype=c.dtype)
if c.dtype == object_dtype:
data[data == None] = c.missing_value # noqa
out[c] = np.tile(data, (len(dates), 1))
return out


class IEXBaseLoader(PipelineLoader):
class IEXBaseLoader(implements(PipelineLoader)):

def load_adjusted_array(self, columns, dates, symbols, mask):
def load_adjusted_array(self, domain, columns, dates, sids, mask):
symbol_dict = self._load()
out = {}
for c in columns:
data = np.array([
symbol_dict.get(symbol, {}).get(c.name, c.missing_value)
for symbol in symbols
for symbol in sids
], dtype=c.dtype)
if c.dtype == object_dtype:
data[data == None] = c.missing_value # noqa
Expand Down
7 changes: 4 additions & 3 deletions pipeline_live/data/iex/pricing_loader.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import numpy as np
import logbook
import pandas as pd
from interface import implements

from zipline.lib.adjusted_array import AdjustedArray
from zipline.pipeline.loaders.base import PipelineLoader
Expand All @@ -13,7 +14,7 @@
log = logbook.Logger(__name__)


class USEquityPricingLoader(PipelineLoader):
class USEquityPricingLoader(implements(PipelineLoader)):
"""
PipelineLoader for US Equity Pricing data
"""
Expand All @@ -23,7 +24,7 @@ def __init__(self):

self._all_sessions = cal.all_sessions

def load_adjusted_array(self, columns, dates, symbols, mask):
def load_adjusted_array(self, domain, columns, dates, sids, mask):
# load_adjusted_array is called with dates on which the user's algo
# will be shown data, which means we need to return the data that would
# be known at the start of each date. We assume that the latest data
Expand Down Expand Up @@ -52,7 +53,7 @@ def load_adjusted_array(self, columns, dates, symbols, mask):
prices = iex.get_stockprices(chart_range)

dfs = []
for symbol in symbols:
for symbol in sids:
if symbol not in prices:
df = pd.DataFrame(
{c.name: c.missing_value for c in columns},
Expand Down
8 changes: 4 additions & 4 deletions pipeline_live/data/polygon/fundamentals_loader.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import numpy as np

from interface import implements
from zipline.pipeline.loaders.base import PipelineLoader

from pipeline_live.data.sources import polygon


class PolygonCompanyLoader(PipelineLoader):
class PolygonCompanyLoader(implements(PipelineLoader)):

def load_adjusted_array(self, columns, dates, symbols, mask):
def load_adjusted_array(self, domain, columns, dates, sids, mask):

company = polygon.company()
out = {}
for c in columns:
data = [
company.get(symbol, {}).get(c.name, c.missing_value)
for symbol in symbols
for symbol in sids
]
out[c] = np.tile(np.array(data, dtype=c.dtype), (len(dates), 1))

Expand Down
7 changes: 2 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,11 @@
keywords='financial,zipline,pipeline,stock,screening,api,trade',
packages=find_packages(),
install_requires=[
'pandas==0.22.0',
'numpy==1.19.4',
'scipy<=1.6.0',
'pandas-datareader<=0.8.1',
'pandas-datareader>=0.8.1',
'lxml>=4.6.2',
'alpaca-trade-api>=0.52.0',
'iexfinance>=0.4.1,<0.5.0',
'zipline==1.3.0',
'zipline-reloaded>=2',
],
tests_require=[
'pytest',
Expand Down
5 changes: 3 additions & 2 deletions tests/test_alpaca.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ def test_pricing_loader(refdata, alpaca_tradeapi, data_path):
mock_tradeapi.get_barset(alpaca_tradeapi)

loader = USEquityPricing.get_loader()
domain = None
columns = [USEquityPricing.close]
dates = [pd.Timestamp('2018-08-22', tz='UTC')]
symbols = ['AA']
mask = np.zeros((1, 1), dtype='bool')
out = loader.load_adjusted_array(columns, dates, symbols, mask)
out = loader.load_adjusted_array(domain, columns, dates, symbols, mask)

assert out[USEquityPricing.close]._data.shape == (1, 1)
assert out[USEquityPricing.close]._data.shape == (1, 1)
6 changes: 5 additions & 1 deletion tests/test_factors.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@


def test_factors():
assert factors.AverageDollarVolume.inputs[0] == USEquityPricing.close
factor = factors.AverageDollarVolume(
window_length=30,
inputs=[USEquityPricing.close, USEquityPricing.volume])

assert factor.inputs[0] == USEquityPricing.close
6 changes: 4 additions & 2 deletions tests/test_iex.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ def test_IEXKeyStats(refdata, stocks, data_path):
mock_iex.get_available_symbols(refdata)
mock_iex.get_key_stats(stocks)

domains = None
marketcap = IEXKeyStats.marketcap
loader = marketcap.dataset.get_loader()
date = pd.Timestamp('2018-08-20', tz='utc')
out = loader.load_adjusted_array([marketcap], [date], ['AA'], [])
out = loader.load_adjusted_array(domains, [marketcap], [date], ['AA'], [])

assert out[marketcap][0][0] != 0.0

Expand All @@ -26,9 +27,10 @@ def test_pricing_loader(refdata, stocks, data_path):

loader = USEquityPricing.get_loader()
columns = [USEquityPricing.close]
domains = None
dates = [pd.Timestamp('2018-08-22', tz='UTC')]
symbols = ['AA']
mask = np.zeros((1, 1), dtype='bool')
out = loader.load_adjusted_array(columns, dates, symbols, mask)
out = loader.load_adjusted_array(domains, columns, dates, symbols, mask)

assert out[USEquityPricing.close]._data.shape == (1, 1)
3 changes: 2 additions & 1 deletion tests/test_polygon.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ def test_PolygonCompany(tradeapi, data_path):
mock_tradeapi.list_assets(tradeapi)
mock_tradeapi.list_companies(tradeapi)

domains = None
marketcap = PolygonCompany.marketcap
loader = marketcap.dataset.get_loader()
date = pd.Timestamp('2018-08-20', tz='utc')
out = loader.load_adjusted_array([marketcap], [date], ['AA'], [])
out = loader.load_adjusted_array(domains, [marketcap], [date], ['AA'], [])

assert out[marketcap][0][0] > 10e6

Expand Down