コード例 #1
0
ファイル: position_tracker.py プロジェクト: StratiFi/zipline
    def execute_transaction(self, txn):
        # Update Position
        # ----------------
        sid = txn.sid

        if sid not in self.positions:
            position = Position(sid)
            self.positions[sid] = position
        else:
            position = self.positions[sid]
        position.update(txn)

        if position.amount == 0:
            # if this position now has 0 shares, remove it from our internal
            # bookkeeping.
            del self.positions[sid]

            # GD FIXING ISSUE OF MIXING MULTIPLE MULTIPLIERS
            # FIXME TODO check that this is ok forever..
            del self._position_value_multipliers[sid]
            del self._position_exposure_multipliers[sid]

            try:
                # if this position exists in our user-facing dictionary,
                # remove it as well.
                del self._positions_store[sid]
            except KeyError:
                pass
        else:
            self._update_asset(sid)
コード例 #2
0
    def execute_transaction(self, txn):
        # Update Position
        # ----------------
        sid = txn.sid

        if sid not in self.positions:
            position = Position(sid)
            self.positions[sid] = position
        else:
            position = self.positions[sid]

        position.update(txn)

        if position.amount == 0:
            # if this position now has 0 shares, remove it from our internal
            # bookkeeping.
            del self.positions[sid]

            try:
                # if this position exists in our user-facing dictionary,
                # remove it as well.
                del self._positions_store[sid]
            except KeyError:
                pass

        self._update_asset(sid)
コード例 #3
0
ファイル: position_tracker.py プロジェクト: rsr2425/zipline
    def execute_transaction(self, txn):
        # Update Position
        # ----------------
        sid = txn.sid

        if sid not in self.positions:
            position = Position(sid)
            self.positions[sid] = position
        else:
            position = self.positions[sid]

        position.update(txn)

        if position.amount == 0:
            # if this position now has 0 shares, remove it from our internal
            # bookkeeping.
            del self.positions[sid]

            try:
                # if this position exists in our user-facing dictionary,
                # remove it as well.
                del self._positions_store[sid]
            except KeyError:
                pass

        self._update_asset(sid)
コード例 #4
0
ファイル: position_tracker.py プロジェクト: StratiFi/zipline
    def execute_transaction(self, txn):
        # Update Position
        # ----------------
        sid = txn.sid

        if sid not in self.positions:
            position = Position(sid)
            self.positions[sid] = position
        else:
            position = self.positions[sid]
        position.update(txn)

        if position.amount == 0:
            # if this position now has 0 shares, remove it from our internal
            # bookkeeping.
            del self.positions[sid]

            # GD FIXING ISSUE OF MIXING MULTIPLE MULTIPLIERS
            # FIXME TODO check that this is ok forever..
            del self._position_value_multipliers[sid]
            del self._position_exposure_multipliers[sid]

            try:
                # if this position exists in our user-facing dictionary,
                # remove it as well.
                del self._positions_store[sid]
            except KeyError:
                pass
        else:
            self._update_asset(sid)
コード例 #5
0
ファイル: position_tracker.py プロジェクト: rsr2425/zipline
    def update_position(self, sid, amount=None, last_sale_price=None, last_sale_date=None, cost_basis=None):
        if sid not in self.positions:
            position = Position(sid)
            self.positions[sid] = position
        else:
            position = self.positions[sid]

        if amount is not None:
            position.amount = amount
            self._update_asset(sid=sid)
        if last_sale_price is not None:
            position.last_sale_price = last_sale_price
        if last_sale_date is not None:
            position.last_sale_date = last_sale_date
        if cost_basis is not None:
            position.cost_basis = cost_basis
コード例 #6
0
    def execute_transaction(self, txn):
        # Update Position
        # ----------------
        asset = txn.asset

        if asset not in self.positions:
            position = Position(asset)
            self.positions[asset] = position
        else:
            position = self.positions[asset]

        position.update(txn)

        if position.amount == 0:
            del self.positions[asset]

            try:
                # if this position exists in our user-facing dictionary,
                # remove it as well.
                del self._positions_store[asset]
            except KeyError:
                pass
コード例 #7
0
ファイル: position_tracker.py プロジェクト: FranSal/zipline
    def execute_transaction(self, txn):
        # Update Position
        # ----------------
        asset = txn.asset

        if asset not in self.positions:
            position = Position(asset)
            self.positions[asset] = position
        else:
            position = self.positions[asset]

        position.update(txn)

        if position.amount == 0:
            del self.positions[asset]

            try:
                # if this position exists in our user-facing dictionary,
                # remove it as well.
                del self._positions_store[asset]
            except KeyError:
                pass
コード例 #8
0
    def pay_dividends(self, next_trading_day):
        """
        Returns a cash payment based on the dividends that should be paid out
        according to the accumulated bookkeeping of earned, unpaid, and stock
        dividends.
        """
        net_cash_payment = 0.0

        try:
            payments = self._unpaid_dividends[next_trading_day]
            # Mark these dividends as paid by dropping them from our unpaid
            del self._unpaid_dividends[next_trading_day]
        except KeyError:
            payments = []

        # representing the fact that we're required to reimburse the owner of
        # the stock for any dividends paid while borrowing.
        for payment in payments:
            net_cash_payment += payment['amount']

        # Add stock for any stock dividends paid.  Again, the values here may
        # be negative in the case of short positions.
        try:
            stock_payments = self._unpaid_stock_dividends[next_trading_day]
        except:
            stock_payments = []

        for stock_payment in stock_payments:
            payment_asset = stock_payment['payment_asset']
            share_count = stock_payment['share_count']
            # note we create a Position for stock dividend if we don't
            # already own the asset
            if payment_asset in self.positions:
                position = self.positions[payment_asset]
            else:
                position = self.positions[payment_asset] = \
                    Position(payment_asset)

            position.amount += share_count
            self._update_asset(payment_asset)

        return net_cash_payment
コード例 #9
0
    def update_position(self, asset, amount=None, last_sale_price=None,
                        last_sale_date=None, cost_basis=None):
        if asset not in self.positions:
            position = Position(asset)
            self.positions[asset] = position
        else:
            position = self.positions[asset]

        if amount is not None:
            position.amount = amount
        if last_sale_price is not None:
            position.last_sale_price = last_sale_price
        if last_sale_date is not None:
            position.last_sale_date = last_sale_date
        if cost_basis is not None:
            position.cost_basis = cost_basis
コード例 #10
0
    def update_position(self, sid, amount=None, last_sale_price=None,
                        last_sale_date=None, cost_basis=None):
        if sid not in self.positions:
            position = Position(sid)
            self.positions[sid] = position
        else:
            position = self.positions[sid]

        if amount is not None:
            position.amount = amount
            self._update_asset(sid=sid)
        if last_sale_price is not None:
            position.last_sale_price = last_sale_price
        if last_sale_date is not None:
            position.last_sale_date = last_sale_date
        if cost_basis is not None:
            position.cost_basis = cost_basis