Repository: quantopian/zipline
File: zipline/algorithm.py (Python)

Code before:
            self._initialize = kwargs.pop('initialize', noop)
            self._handle_data = kwargs.pop('handle_data', noop)
            self._before_trading_start = kwargs.pop(
                'before_trading_start',
                None,
            )
            self._analyze = kwargs.pop('analyze', None)

        self.event_manager.add_event(
            zipline.utils.events.Event(
                zipline.utils.events.Always(),
                # We pass handle_data.__func__ to get the unbound method.
                # We will explicitly pass the algorithm to bind it again.
                self.handle_data.__func__,
            ),
            prepend=True,
        )

        # Alternative way of setting data_frequency for backwards
        # compatibility.
        if 'data_frequency' in kwargs:
            self.data_frequency = kwargs.pop('data_frequency')

        capital_base = self.sim_params.capital_base
        if capital_base <= 0:
            assert capital_base <= 0, \
                "initial capital base must be greater than zero"
            raise ZeroCapitalError

        # Prepare the algo for initialization
        self.initialized = False
        self.initialize_args = args
        self.initialize_kwargs = kwargs

        self.benchmark_sid = kwargs.pop('benchmark_sid', None)

        # A dictionary of capital changes, keyed by timestamp, indicating the
        # target/delta of the capital changes, along with values
        self.capital_changes = kwargs.pop('capital_changes', {})

        # A dictionary of the actual capital change deltas, keyed by timestamp
        self.capital_change_deltas = {}

        self.restrictions = NoRestrictions()

    def init_engine(self, get_loader):
        """
        Construct and store a PipelineEngine from loader.

        If get_loader is None, constructs an ExplodingPipelineEngine
        """

Review comment (suggestion):
So this is probably unnecessary, since the message inside the error that you're raising is the same as this. Either you probably want that assert, in which case, you're going to get an `AssertionError` with that message, or you want to raise the `ZeroCapitalError`, in which case you could probably pass the text that you wanted displayed to the error class, if you had wanted that to be variable in this context (the thing you're doing with your assert). In this case the assertion is basically serving the same purpose as the if statement, and you don't really need both.

Code after:
            self._initialize = kwargs.pop('initialize', noop)
            self._handle_data = kwargs.pop('handle_data', noop)
            self._before_trading_start = kwargs.pop(
                'before_trading_start',
                None,
            )
            self._analyze = kwargs.pop('analyze', None)

        self.event_manager.add_event(
            zipline.utils.events.Event(
                zipline.utils.events.Always(),
                # We pass handle_data.__func__ to get the unbound method.
                # We will explicitly pass the algorithm to bind it again.
                self.handle_data.__func__,
            ),
            prepend=True,
        )

        # Alternative way of setting data_frequency for backwards
        # compatibility.
        if 'data_frequency' in kwargs:
            self.data_frequency = kwargs.pop('data_frequency')

        capital_base = self.sim_params.capital_base
        if capital_base <= 0:
            raise ZeroCapitalError()

        # Prepare the algo for initialization
        self.initialized = False
        self.initialize_args = args
        self.initialize_kwargs = kwargs

        self.benchmark_sid = kwargs.pop('benchmark_sid', None)

        # A dictionary of capital changes, keyed by timestamp, indicating the
        # target/delta of the capital changes, along with values
        self.capital_changes = kwargs.pop('capital_changes', {})

        # A dictionary of the actual capital change deltas, keyed by timestamp
        self.capital_change_deltas = {}

        self.restrictions = NoRestrictions()

    def init_engine(self, get_loader):
        """
        Construct and store a PipelineEngine from loader.

        If get_loader is None, constructs an ExplodingPipelineEngine
        """
        if get_loader is not None:
            self.engine = SimplePipelineEngine(