Skip to content

Commit

Permalink
Merge d1077a3 into 164bd06
Browse files Browse the repository at this point in the history
  • Loading branch information
jbredeche committed Aug 4, 2016
2 parents 164bd06 + d1077a3 commit 79855ec
Show file tree
Hide file tree
Showing 35 changed files with 702 additions and 268 deletions.
6 changes: 3 additions & 3 deletions tests/calendars/test_trading_calendar.py
Expand Up @@ -56,13 +56,13 @@ def test_register_calendar(self):
dummy_cal = self.dummy_cal_type('DMY')

# Try to register and retrieve the calendar
register_calendar(dummy_cal)
register_calendar('DMY', dummy_cal)
retr_cal = get_calendar('DMY')
self.assertEqual(dummy_cal, retr_cal)

# Try to register again, expecting a name collision
with self.assertRaises(CalendarNameCollision):
register_calendar(dummy_cal)
register_calendar('DMY', dummy_cal)

# Deregister the calendar and ensure that it is removed
deregister_calendar('DMY')
Expand All @@ -76,7 +76,7 @@ def test_force_registration(self):
real_nyse = get_calendar('NYSE')

# Force a registration of the dummy NYSE
register_calendar(dummy_nyse, force=True)
register_calendar("NYSE", dummy_nyse, force=True)

# Ensure that the dummy overwrote the real calendar
retr_cal = get_calendar('NYSE')
Expand Down
6 changes: 3 additions & 3 deletions tests/finance/test_cancel_policy.py
Expand Up @@ -17,18 +17,18 @@
from zipline.finance.cancel_policy import NeverCancel, EODCancel
from zipline.gens.sim_engine import (
BAR,
DAY_END
SESSION_END
)


class CancelPolicyTestCase(TestCase):

def test_eod_cancel(self):
cancel_policy = EODCancel()
self.assertTrue(cancel_policy.should_cancel(DAY_END))
self.assertTrue(cancel_policy.should_cancel(SESSION_END))
self.assertFalse(cancel_policy.should_cancel(BAR))

def test_never_cancel(self):
cancel_policy = NeverCancel()
self.assertFalse(cancel_policy.should_cancel(DAY_END))
self.assertFalse(cancel_policy.should_cancel(SESSION_END))
self.assertFalse(cancel_policy.should_cancel(BAR))
2 changes: 1 addition & 1 deletion tests/pipeline/test_slice.py
Expand Up @@ -165,7 +165,7 @@ def test_non_existent_asset(self):
Test that indexing into a term with a non-existent asset raises the
proper exception.
"""
my_asset = Asset(0)
my_asset = Asset(0, exchange="TEST")
returns = Returns(window_length=2, inputs=[self.col])
returns_slice = returns[my_asset]

Expand Down
2 changes: 1 addition & 1 deletion tests/pipeline/test_statistical.py
Expand Up @@ -314,7 +314,7 @@ def test_correlation_and_regression_with_bad_asset(self):
`RollingLinearRegressionOfReturns` raise the proper exception when
given a nonexistent target asset.
"""
my_asset = Equity(0)
my_asset = Equity(0, exchange="TEST")
start_date = self.pipeline_start_date
end_date = self.pipeline_end_date
run_pipeline = self.run_pipeline
Expand Down
2 changes: 1 addition & 1 deletion tests/pipeline/test_term.py
Expand Up @@ -290,7 +290,7 @@ def test_instance_caching_multiple_outputs(self):
self.assertIs(beta, multiple_outputs.beta)

def test_instance_caching_of_slices(self):
my_asset = Asset(1)
my_asset = Asset(1, exchange="TEST")

f = GenericCustomFactor()
f_slice = f[my_asset]
Expand Down
Binary file modified tests/resources/example_data.tar.gz
Binary file not shown.
96 changes: 62 additions & 34 deletions tests/test_algorithm.py
Expand Up @@ -12,11 +12,11 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import warnings
from collections import namedtuple
import datetime
from datetime import timedelta
from textwrap import dedent
import warnings
from unittest import skip
from copy import deepcopy

Expand All @@ -32,11 +32,10 @@
import numpy as np
import pandas as pd
import pytz
from pandas.io.common import PerformanceWarning

from zipline import (
run_algorithm,
TradingAlgorithm,
)
from zipline import run_algorithm
from zipline import TradingAlgorithm
from zipline.api import FixedSlippage
from zipline.assets import Equity, Future
from zipline.assets.synthetic import (
Expand Down Expand Up @@ -164,7 +163,7 @@
no_handle_data,
)
from zipline.utils.api_support import ZiplineAPI, set_algo_instance
from zipline.utils.calendars import get_calendar
from zipline.utils.calendars import get_calendar, register_calendar
from zipline.utils.context_tricks import CallbackManager
from zipline.utils.control_flow import nullctx
import zipline.utils.events
Expand Down Expand Up @@ -211,10 +210,12 @@ def make_equity_info(cls):
pd.DataFrame.from_dict(
{3: {'symbol': 'PLAY',
'start_date': '2002-01-01',
'end_date': '2004-01-01'},
'end_date': '2004-01-01',
'exchange': 'TEST'},
4: {'symbol': 'PLAY',
'start_date': '2005-01-01',
'end_date': '2006-01-01'}},
'end_date': '2006-01-01',
'exchange': 'TEST'}},
orient='index',
),
))
Expand All @@ -228,25 +229,33 @@ def make_futures_info(cls):
'root_symbol': 'CL',
'start_date': pd.Timestamp('2005-12-01', tz='UTC'),
'notice_date': pd.Timestamp('2005-12-20', tz='UTC'),
'expiration_date': pd.Timestamp('2006-01-20', tz='UTC')},
'expiration_date': pd.Timestamp('2006-01-20', tz='UTC'),
'exchange': 'TEST'
},
6: {
'root_symbol': 'CL',
'symbol': 'CLK06',
'start_date': pd.Timestamp('2005-12-01', tz='UTC'),
'notice_date': pd.Timestamp('2006-03-20', tz='UTC'),
'expiration_date': pd.Timestamp('2006-04-20', tz='UTC')},
'expiration_date': pd.Timestamp('2006-04-20', tz='UTC'),
'exchange': 'TEST',
},
7: {
'symbol': 'CLQ06',
'root_symbol': 'CL',
'start_date': pd.Timestamp('2005-12-01', tz='UTC'),
'notice_date': pd.Timestamp('2006-06-20', tz='UTC'),
'expiration_date': pd.Timestamp('2006-07-20', tz='UTC')},
'expiration_date': pd.Timestamp('2006-07-20', tz='UTC'),
'exchange': 'TEST',
},
8: {
'symbol': 'CLX06',
'root_symbol': 'CL',
'start_date': pd.Timestamp('2006-02-01', tz='UTC'),
'notice_date': pd.Timestamp('2006-09-20', tz='UTC'),
'expiration_date': pd.Timestamp('2006-10-20', tz='UTC')}
'expiration_date': pd.Timestamp('2006-10-20', tz='UTC'),
'exchange': 'TEST',
}
},
orient='index',
)
Expand Down Expand Up @@ -738,6 +747,7 @@ def test_set_symbol_lookup_date(self):
'symbol': 'DUP',
'start_date': date.value,
'end_date': (date + timedelta(days=1)).value,
'exchange': 'TEST',
}
for i, date in enumerate(dates)
]
Expand Down Expand Up @@ -781,10 +791,13 @@ class TestTransformAlgorithm(WithLogger,

@classmethod
def make_futures_info(cls):
return pd.DataFrame.from_dict(
{3: {'multiplier': 10, 'symbol': 'F'}},
orient='index',
)
return pd.DataFrame.from_dict({
3: {
'multiplier': 10,
'symbol': 'F',
'exchange': 'TEST'
}
}, orient='index')

@classmethod
def make_equity_daily_bar_data(cls):
Expand Down Expand Up @@ -990,7 +1003,8 @@ def test_minute_data(self, algo_class):
period_end = pd.Timestamp('2002-1-4', tz='UTC')
equities = pd.DataFrame([{
'start_date': start_session,
'end_date': period_end + timedelta(days=1)
'end_date': period_end + timedelta(days=1),
'exchange': "TEST",
}] * 2)
equities['symbol'] = ['A', 'B']
with TempDirectory() as tempdir, \
Expand Down Expand Up @@ -1439,6 +1453,8 @@ class TestAlgoScript(WithLogger,

@classmethod
def make_equity_info(cls):
register_calendar("TEST", get_calendar("NYSE"), force=True)

data = make_simple_equity_info(
cls.sids,
cls.START_DATE,
Expand Down Expand Up @@ -1773,6 +1789,7 @@ def test_without_kwargs(self):
Test that api methods on the data object can be called with positional
arguments.
"""

params = SimulationParameters(
start_session=pd.Timestamp("2006-01-10", tz='UTC'),
end_session=pd.Timestamp("2006-01-11", tz='UTC'),
Expand Down Expand Up @@ -1961,25 +1978,28 @@ def handle_data(algo, data):
""")

with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("ignore", PerformanceWarning)

algo = TradingAlgorithm(
script=algocode,
sim_params=sim_params,
env=self.env
)
algo.run(self.data_portal)

self.assertEqual(len(w), 2)
for i, warning in enumerate(w):
self.assertIsInstance(warning.message, UserWarning)
self.assertEqual(
warning.message.args[0],
'Got a time rule for the second positional argument '
'date_rule. You should use keyword argument '
'time_rule= when calling schedule_function without '
'specifying a date_rule'
)
# The warnings come from line 13 and 14 in the algocode
self.assertEqual(warning.lineno, 13 + i)
self.assertEqual(len(w), 2)

for i, warning in enumerate(w):
self.assertIsInstance(warning.message, UserWarning)
self.assertEqual(
warning.message.args[0],
'Got a time rule for the second positional argument '
'date_rule. You should use keyword argument '
'time_rule= when calling schedule_function without '
'specifying a date_rule'
)
# The warnings come from line 13 and 14 in the algocode
self.assertEqual(warning.lineno, 13 + i)

self.assertEqual(
algo.done_at_open,
Expand Down Expand Up @@ -2855,7 +2875,8 @@ def test_set_max_order_count(self):
1: {
'symbol': 'SYM',
'start_date': start,
'end_date': start + timedelta(days=6)
'end_date': start + timedelta(days=6),
'exchange': "TEST",
},
},
orient='index',
Expand Down Expand Up @@ -2984,6 +3005,8 @@ def test_asset_date_bounds(self):
'symbol': 'SYM',
'start_date': self.sim_params.start_session,
'end_date': '2020-01-01',
'exchange': "TEST",
'sid': 999,
}])
with TempDirectory() as tempdir, \
tmp_trading_env(equities=metadata) as env:
Expand All @@ -2995,7 +3018,7 @@ def test_asset_date_bounds(self):
env.asset_finder,
tempdir,
self.sim_params,
[0],
[999],
self.trading_calendar,
)
algo.run(data_portal)
Expand All @@ -3004,14 +3027,16 @@ def test_asset_date_bounds(self):
'symbol': 'SYM',
'start_date': '1989-01-01',
'end_date': '1990-01-01',
'exchange': "TEST",
'sid': 999,
}])
with TempDirectory() as tempdir, \
tmp_trading_env(equities=metadata) as env:
data_portal = create_data_portal(
env.asset_finder,
tempdir,
self.sim_params,
[0],
[999],
self.trading_calendar,
)
algo = SetAssetDateBoundsAlgorithm(
Expand All @@ -3025,14 +3050,16 @@ def test_asset_date_bounds(self):
'symbol': 'SYM',
'start_date': '2020-01-01',
'end_date': '2021-01-01',
'exchange': "TEST",
'sid': 999,
}])
with TempDirectory() as tempdir, \
tmp_trading_env(equities=metadata) as env:
data_portal = create_data_portal(
env.asset_finder,
tempdir,
self.sim_params,
[0],
[999],
self.trading_calendar,
)
algo = SetAssetDateBoundsAlgorithm(
Expand Down Expand Up @@ -4054,7 +4081,8 @@ def make_equity_info(cls):
'start_date': cls.start,
'end_date': cls.day_1,
'auto_close_date': cls.day_4,
'symbol': "ASSET1"
'symbol': "ASSET1",
'exchange': "TEST",
},
},
orient='index',
Expand Down
7 changes: 7 additions & 0 deletions tests/test_api_shim.py
Expand Up @@ -3,6 +3,7 @@
from mock import patch
import numpy as np
import pandas as pd
from pandas.io.common import PerformanceWarning

from zipline import TradingAlgorithm
from zipline.finance.trading import SimulationParameters
Expand Down Expand Up @@ -291,6 +292,7 @@ def test_sid_accessor(self):
deprecation warning.
"""
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("ignore", PerformanceWarning)
warnings.simplefilter("default", ZiplineDeprecationWarning)
algo = self.create_algo(sid_accessor_algo)
algo.run(self.data_portal)
Expand Down Expand Up @@ -319,6 +321,7 @@ def test_data_items(self):
in `data` is deprecated.
"""
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("ignore", PerformanceWarning)
warnings.simplefilter("default", ZiplineDeprecationWarning)
algo = self.create_algo(data_items_algo)
algo.run(self.data_portal)
Expand All @@ -343,6 +346,7 @@ def test_data_items(self):

def test_iterate_data(self):
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("ignore", PerformanceWarning)
warnings.simplefilter("default", ZiplineDeprecationWarning)

algo = self.create_algo(simple_algo)
Expand Down Expand Up @@ -373,6 +377,7 @@ def test_iterate_data(self):

def test_history(self):
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("ignore", PerformanceWarning)
warnings.simplefilter("default", ZiplineDeprecationWarning)

sim_params = self.sim_params.create_new(
Expand Down Expand Up @@ -414,6 +419,7 @@ def test_old_new_history_bts_paths(self):

def test_simple_transforms(self):
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("ignore", PerformanceWarning)
warnings.simplefilter("default", ZiplineDeprecationWarning)

sim_params = SimulationParameters(
Expand Down Expand Up @@ -484,6 +490,7 @@ def test_simple_transforms(self):

def test_manipulation(self):
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("ignore", PerformanceWarning)
warnings.simplefilter("default", ZiplineDeprecationWarning)

algo = self.create_algo(simple_algo)
Expand Down

0 comments on commit 79855ec

Please sign in to comment.