mirror of
https://github.com/wassname/catalyst.git
synced 2026-06-27 19:14:36 +08:00
use dt.normalize() in pd>=0.20
This commit is contained in:
@@ -16,7 +16,6 @@ import warnings
|
||||
from contextlib import contextmanager
|
||||
from functools import wraps
|
||||
|
||||
from pandas.tslib import normalize_date
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
|
||||
@@ -564,7 +563,7 @@ cdef class BarData:
|
||||
})
|
||||
|
||||
cdef bool _is_stale_for_asset(self, asset, dt, adjusted_dt, data_portal):
|
||||
session_label = normalize_date(dt) # FIXME
|
||||
session_label = dt.normalize_date() # FIXME
|
||||
|
||||
if not asset.is_alive_for_session(session_label):
|
||||
return False
|
||||
|
||||
@@ -21,7 +21,6 @@ import logbook
|
||||
import pytz
|
||||
import pandas as pd
|
||||
from contextlib2 import ExitStack
|
||||
from pandas.tseries.tools import normalize_date
|
||||
import numpy as np
|
||||
|
||||
from itertools import chain, repeat
|
||||
@@ -1345,7 +1344,7 @@ class TradingAlgorithm(object):
|
||||
# Make sure the asset exists, and that there is a last price for it.
|
||||
# FIXME: we should use BarData's can_trade logic here, but I haven't
|
||||
# yet found a good way to do that.
|
||||
normalized_date = normalize_date(self.datetime)
|
||||
normalized_date = self.datetime.normalize()
|
||||
|
||||
if normalized_date < asset.start_date:
|
||||
raise CannotOrderDelistedAsset(
|
||||
@@ -1392,7 +1391,7 @@ class TradingAlgorithm(object):
|
||||
)
|
||||
|
||||
if asset.auto_close_date:
|
||||
day = normalize_date(self.get_datetime())
|
||||
day = self.get_datetime().normalize()
|
||||
|
||||
if day > min(asset.end_date, asset.auto_close_date):
|
||||
# If we are after the asset's end date or auto close date, warn
|
||||
@@ -2475,7 +2474,7 @@ class TradingAlgorithm(object):
|
||||
"""
|
||||
Internal implementation of `pipeline_output`.
|
||||
"""
|
||||
today = normalize_date(self.get_datetime())
|
||||
today = self.get_datetime().normalize()
|
||||
data = NO_DATA = object()
|
||||
try:
|
||||
data = self._pipeline_cache.unwrap(today)
|
||||
|
||||
@@ -20,7 +20,6 @@ import numpy as np
|
||||
from numpy import float64, int64, nan
|
||||
import pandas as pd
|
||||
from pandas import isnull
|
||||
from pandas.tslib import normalize_date
|
||||
from six import iteritems
|
||||
from six.moves import reduce
|
||||
|
||||
@@ -439,7 +438,7 @@ class DataPortal(object):
|
||||
(isinstance(asset, (Asset, ContinuousFuture))))
|
||||
|
||||
def _get_fetcher_value(self, asset, field, dt):
|
||||
day = normalize_date(dt)
|
||||
day = dt.normalize()
|
||||
|
||||
try:
|
||||
return \
|
||||
@@ -1130,7 +1129,7 @@ class DataPortal(object):
|
||||
if self._asset_start_dates[sid] > dt:
|
||||
raise NoTradeDataAvailableTooEarly(
|
||||
sid=sid,
|
||||
dt=normalize_date(dt),
|
||||
dt=dt.normalize(),
|
||||
start_dt=start_date
|
||||
)
|
||||
|
||||
@@ -1138,7 +1137,7 @@ class DataPortal(object):
|
||||
if self._asset_end_dates[sid] < dt:
|
||||
raise NoTradeDataAvailableTooLate(
|
||||
sid=sid,
|
||||
dt=normalize_date(dt),
|
||||
dt=dt.normalize(),
|
||||
end_dt=end_date
|
||||
)
|
||||
|
||||
@@ -1262,7 +1261,7 @@ class DataPortal(object):
|
||||
if self._extra_source_df is None:
|
||||
return []
|
||||
|
||||
day = normalize_date(dt)
|
||||
day = dt.normalize()
|
||||
|
||||
if day in self._extra_source_df.index:
|
||||
assets = self._extra_source_df.loc[day]['sid']
|
||||
|
||||
@@ -21,7 +21,6 @@ from abc import (
|
||||
from numpy import concatenate
|
||||
from lru import LRU
|
||||
from pandas import isnull
|
||||
from pandas.tslib import normalize_date
|
||||
from toolz import sliding_window
|
||||
|
||||
from six import with_metaclass
|
||||
@@ -93,8 +92,8 @@ class HistoryCompatibleUSEquityAdjustmentReader(object):
|
||||
The adjustments as a dict of loc -> Float64Multiply
|
||||
"""
|
||||
sid = int(asset)
|
||||
start = normalize_date(dts[0])
|
||||
end = normalize_date(dts[-1])
|
||||
start = dts[0].normalize()
|
||||
end = dts[-1].normalize()
|
||||
adjs = {}
|
||||
if field != 'volume':
|
||||
mergers = self._adjustments_reader.get_adjustments_for_sid(
|
||||
|
||||
@@ -49,7 +49,6 @@ from pandas import (
|
||||
to_datetime,
|
||||
Timestamp,
|
||||
)
|
||||
from pandas.tslib import iNaT
|
||||
from six import (
|
||||
iteritems,
|
||||
string_types,
|
||||
@@ -422,7 +421,7 @@ class BcolzDailyBarWriter(object):
|
||||
)
|
||||
|
||||
full_table.attrs['first_trading_day'] = (
|
||||
earliest_date if earliest_date is not None else iNaT
|
||||
earliest_date if earliest_date is not None else NaT
|
||||
)
|
||||
|
||||
full_table.attrs['first_row'] = first_row
|
||||
|
||||
@@ -62,7 +62,6 @@ from __future__ import division
|
||||
import logbook
|
||||
|
||||
import pandas as pd
|
||||
from pandas.tseries.tools import normalize_date
|
||||
|
||||
from catalyst.finance.performance.period import PerformancePeriod
|
||||
from catalyst.errors import NoFurtherDataError
|
||||
@@ -344,7 +343,7 @@ class PerformanceTracker(object):
|
||||
"""
|
||||
self.position_tracker.sync_last_sale_prices(dt, False, data_portal)
|
||||
self.update_performance()
|
||||
todays_date = normalize_date(dt)
|
||||
todays_date = dt.normalize()
|
||||
account = self.get_account(False)
|
||||
|
||||
bench_returns = self.all_benchmark_returns.loc[todays_date:dt]
|
||||
|
||||
@@ -18,7 +18,6 @@ import logbook
|
||||
import numpy as np
|
||||
|
||||
import pandas as pd
|
||||
from pandas.tseries.tools import normalize_date
|
||||
|
||||
from six import iteritems
|
||||
|
||||
@@ -80,7 +79,7 @@ class RiskMetricsCumulative(object):
|
||||
# on the first day.
|
||||
self.day_before_start = self.start_session - self.sessions.freq
|
||||
|
||||
last_day = normalize_date(sim_params.end_session)
|
||||
last_day = sim_params.end_session.normalize()
|
||||
if last_day not in self.sessions:
|
||||
last_day = pd.tseries.index.DatetimeIndex(
|
||||
[last_day]
|
||||
|
||||
@@ -16,7 +16,6 @@ from functools import partial
|
||||
|
||||
import logbook
|
||||
import pandas as pd
|
||||
from pandas.tslib import normalize_date
|
||||
from six import string_types
|
||||
from sqlalchemy import create_engine
|
||||
|
||||
@@ -164,8 +163,8 @@ class SimulationParameters(object):
|
||||
# chop off any minutes or hours on the given start and end dates,
|
||||
# as we only support session labels here (and we represent session
|
||||
# labels as midnight UTC).
|
||||
self._start_session = normalize_date(start_session)
|
||||
self._end_session = normalize_date(end_session)
|
||||
self._start_session = start_session.normalize()
|
||||
self._end_session = end_session.normalize()
|
||||
self._capital_base = capital_base
|
||||
|
||||
self._emission_rate = emission_rate
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
# limitations under the License.
|
||||
from contextlib2 import ExitStack
|
||||
from logbook import Logger, Processor
|
||||
from pandas.tslib import normalize_date
|
||||
from catalyst.protocol import BarData
|
||||
from catalyst.utils.api_support import ZiplineAPI
|
||||
from six import viewkeys
|
||||
@@ -229,7 +228,7 @@ class AlgorithmSimulator(object):
|
||||
elif action == SESSION_END:
|
||||
# End of the session.
|
||||
if emission_rate == 'daily':
|
||||
handle_benchmark(normalize_date(dt))
|
||||
handle_benchmark(dt).normalize()
|
||||
execute_order_cancellation_policy()
|
||||
|
||||
yield self._get_daily_message(dt, algo, algo.perf_tracker)
|
||||
|
||||
@@ -117,9 +117,9 @@ def create_dividend(sid, payment, declared_date, ex_date, pay_date):
|
||||
'net_amount': payment,
|
||||
'payment_sid': None,
|
||||
'ratio': None,
|
||||
'declared_date': pd.tslib.normalize_date(declared_date),
|
||||
'ex_date': pd.tslib.normalize_date(ex_date),
|
||||
'pay_date': pd.tslib.normalize_date(pay_date),
|
||||
'declared_date': pd.tslib.declared_date.normalize(),
|
||||
'ex_date': pd.tslib.ex_date.normalize(),
|
||||
'pay_date': pd.tslib.pay_date.normalize(),
|
||||
'type': DATASOURCE_TYPE.DIVIDEND,
|
||||
'source_id': 'MockDividendSource'
|
||||
})
|
||||
@@ -134,9 +134,9 @@ def create_stock_dividend(sid, payment_sid, ratio, declared_date,
|
||||
'ratio': ratio,
|
||||
'net_amount': None,
|
||||
'gross_amount': None,
|
||||
'dt': pd.tslib.normalize_date(declared_date),
|
||||
'ex_date': pd.tslib.normalize_date(ex_date),
|
||||
'pay_date': pd.tslib.normalize_date(pay_date),
|
||||
'dt': pd.tslib.declared_date.normalize(),
|
||||
'ex_date': pd.tslib.ex_date.normalize(),
|
||||
'pay_date': pd.tslib.pay_date.normalize(),
|
||||
'type': DATASOURCE_TYPE.DIVIDEND,
|
||||
'source_id': 'MockDividendSource'
|
||||
})
|
||||
|
||||
@@ -263,8 +263,8 @@ def _run(handle_data,
|
||||
# We still need to support bundles for other misc data, but we
|
||||
# can handle this later.
|
||||
|
||||
if start != pd.tslib.normalize_date(start) or \
|
||||
end != pd.tslib.normalize_date(end):
|
||||
if start != pd.tslib.start.normalize() or \
|
||||
end != pd.tslib.end.normalize():
|
||||
# todo: add to Sim_Params the option to start & end at specific times
|
||||
log.warn(
|
||||
"Catalyst currently starts and ends on the start and "
|
||||
|
||||
@@ -21,7 +21,6 @@ import datetime
|
||||
from math import sqrt
|
||||
|
||||
from nose_parameterized import parameterized
|
||||
from pandas.tslib import normalize_date
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
import pytz
|
||||
@@ -1108,8 +1107,8 @@ class OrdersStopTestCase(WithSimParams,
|
||||
)),
|
||||
)
|
||||
days = pd.date_range(
|
||||
start=normalize_date(self.minutes[0]),
|
||||
end=normalize_date(self.minutes[-1])
|
||||
start=self.minutes[0].normalize(),
|
||||
end=self.minutes[-1].normalize()
|
||||
)
|
||||
with tmp_bcolz_equity_minute_bar_reader(
|
||||
self.trading_calendar, days, assets) as reader:
|
||||
|
||||
@@ -27,7 +27,6 @@ from pandas import (
|
||||
Series,
|
||||
Timestamp,
|
||||
)
|
||||
from pandas.tseries.tools import normalize_date
|
||||
from six import iteritems, itervalues
|
||||
|
||||
from catalyst.algorithm import TradingAlgorithm
|
||||
@@ -530,7 +529,7 @@ class PipelineAlgorithmTestCase(WithBcolzEquityDailyBarReaderFromCSVs,
|
||||
attach_pipeline(pipeline, 'test')
|
||||
|
||||
def handle_data(context, data):
|
||||
today = normalize_date(get_datetime())
|
||||
today = get_datetime().normalize()
|
||||
results = pipeline_output('test')
|
||||
expect_over_300 = {
|
||||
AAPL: today < self.AAPL_split_date,
|
||||
|
||||
@@ -395,7 +395,6 @@ def handle_data(context, data):
|
||||
|
||||
algocode = """
|
||||
from pandas import Timestamp
|
||||
from pandas.tseries.tools import normalize_date
|
||||
from catalyst.api import fetch_csv, record, sid, get_datetime
|
||||
|
||||
def initialize(context):
|
||||
@@ -411,7 +410,7 @@ def initialize(context):
|
||||
context.bar_count = 0
|
||||
|
||||
def handle_data(context, data):
|
||||
expected = context.expected_sids[normalize_date(get_datetime())]
|
||||
expected = context.expected_sids[get_datetime().normalize()]
|
||||
actual = data.fetcher_assets
|
||||
for stk in expected:
|
||||
if stk not in actual:
|
||||
|
||||
Reference in New Issue
Block a user