# Path: alephnull/protocol.py
# class Event(object):
# 
#     def __init__(self, initial_values=None):
#         if initial_values:
#             self.__dict__ = initial_values
# 
#     def __getitem__(self, name):
#         return getattr(self, name)
# 
#     def __setitem__(self, name, value):
#         setattr(self, name, value)
# 
#     def __delitem__(self, name):
#         delattr(self, name)
# 
#     def keys(self):
#         return self.__dict__.keys()
# 
#     def __eq__(self, other):
#         return self.__dict__ == other.__dict__
# 
#     def __contains__(self, name):
#         return name in self.__dict__
# 
#     def __repr__(self):
#         return "Event({0})".format(self.__dict__)
# 
# Path: alephnull/finance/trading.py
# class TradingEnvironment(object):
# class SimulationParameters(object):
#     def __init__(
#         self,
#         load=None,
#         bm_symbol='^GSPC',
#         exchange_tz="US/Eastern",
#         max_date=None,
#         extra_dates=None
#     ):
#     def __enter__(self, *args, **kwargs):
#     def __exit__(self, exc_type, exc_val, exc_tb):
#     def normalize_date(self, test_date):
#     def utc_dt_in_exchange(self, dt):
#     def exchange_dt_in_utc(self, dt):
#     def is_market_hours(self, test_date):
#     def is_trading_day(self, test_date):
#     def next_trading_day(self, test_date):
#     def days_in_range(self, start, end):
#     def next_open_and_close(self, start_date):
#     def get_open_and_close(self, day):
#     def market_minutes_for_day(self, midnight):
#     def trading_day_distance(self, first_date, second_date):
#     def get_index(self, dt):
#     def __init__(self, period_start, period_end,
#                  capital_base=10e3,
#                  emission_rate='daily',
#                  data_frequency='daily'):
#     def calculate_first_open(self):
#     def calculate_last_close(self):
#     def days_in_period(self):
#     def __repr__(self):


import functools
import logbook
import numpy
import pandas as pd
from numbers import Integral
from alephnull.utils.data import RollingPanel
from alephnull.protocol import Event
from alephnull.finance import trading
from . utils import check_window_length
            sids = set(event.data.keys())
        else:
            sids = self.static_sids

        # the panel sent to the transform code will have
        # columns masked with this set of sids. This is how
        # we guarantee that all (and only) the sids sent to the
        # algorithm's handle_data and passed to the batch
        # transform. See the get_data method to see it applied.
        # N.B. that the underlying panel grows monotonically
        # if the set of sids changes over time.
        self.latest_sids = sids
        # Create rolling panel if not existant
        if self.rolling_panel is None:
            self._init_panels(sids)

        # Store event in rolling frame
        self.rolling_panel.add_frame(event.dt,
                                     pd.DataFrame(event.data,
                                                  index=self.field_names,
                                                  columns=sids))

        # update trading day counters
        # we may get events from non-trading sources which occurr on
        # non-trading days. The book-keeping for market close and
        # trading day counting should only consider trading days.
        if trading.environment.is_trading_day(event.dt):
            _, mkt_close = trading.environment.get_open_and_close(event.dt)
            if self.bars == 'daily':
                # Daily bars have their dt set to midnight.

# Path: alephnull/protocol.py
# class Event(object):
# 
#     def __init__(self, initial_values=None):
#         if initial_values:
#             self.__dict__ = initial_values
# 
#     def __getitem__(self, name):
#         return getattr(self, name)
# 
#     def __setitem__(self, name, value):
#         setattr(self, name, value)
# 
#     def __delitem__(self, name):
#         delattr(self, name)
# 
#     def keys(self):
#         return self.__dict__.keys()
# 
#     def __eq__(self, other):
#         return self.__dict__ == other.__dict__
# 
#     def __contains__(self, name):
#         return name in self.__dict__
# 
#     def __repr__(self):
#         return "Event({0})".format(self.__dict__)
# 
# Path: alephnull/finance/trading.py
# class TradingEnvironment(object):
# class SimulationParameters(object):
#     def __init__(
#         self,
#         load=None,
#         bm_symbol='^GSPC',
#         exchange_tz="US/Eastern",
#         max_date=None,
#         extra_dates=None
#     ):
#     def __enter__(self, *args, **kwargs):
#     def __exit__(self, exc_type, exc_val, exc_tb):
#     def normalize_date(self, test_date):
#     def utc_dt_in_exchange(self, dt):
#     def exchange_dt_in_utc(self, dt):
#     def is_market_hours(self, test_date):
#     def is_trading_day(self, test_date):
#     def next_trading_day(self, test_date):
#     def days_in_range(self, start, end):
#     def next_open_and_close(self, start_date):
#     def get_open_and_close(self, day):
#     def market_minutes_for_day(self, midnight):
#     def trading_day_distance(self, first_date, second_date):
#     def get_index(self, dt):
#     def __init__(self, period_start, period_end,
#                  capital_base=10e3,
#                  emission_rate='daily',
#                  data_frequency='daily'):
#     def calculate_first_open(self):
#     def calculate_last_close(self):
#     def days_in_period(self):
#     def __repr__(self):


# Path: alephnull/transforms/batch_transform.py
import functools
import logbook
import numpy
import pandas as pd
from numbers import Integral
from alephnull.utils.data import RollingPanel
from alephnull.protocol import Event
from alephnull.finance import trading
from . utils import check_window_length

            sids = set(event.data.keys())
        else:
            sids = self.static_sids

        # the panel sent to the transform code will have
        # columns masked with this set of sids. This is how
        # we guarantee that all (and only) the sids sent to the
        # algorithm's handle_data and passed to the batch
        # transform. See the get_data method to see it applied.
        # N.B. that the underlying panel grows monotonically
        # if the set of sids changes over time.
        self.latest_sids = sids
        # Create rolling panel if not existant
        if self.rolling_panel is None:
            self._init_panels(sids)

        # Store event in rolling frame
        self.rolling_panel.add_frame(event.dt,
                                     pd.DataFrame(event.data,
                                                  index=self.field_names,
                                                  columns=sids))

        # update trading day counters
        # we may get events from non-trading sources which occurr on
        # non-trading days. The book-keeping for market close and
        # trading day counting should only consider trading days.
        if trading.environment.is_trading_day(event.dt):
            _, mkt_close = trading.environment.get_open_and_close(event.dt)
            if self.bars == 'daily':
                # Daily bars have their dt set to midnight.

                mkt_close = trading.environment.normalize_date(mkt_close)