Пример #1
0
    def _create(self):
        # If a priceables portfolio, try resolving to MQ portfolio
        if self.__priceables:
            self.save()
            self.priceables = None
            return

        # If a positions portfolio, create using MQ API
        port = GsPortfolioApi.create_portfolio(
            portfolio=MQPortfolio(name=self.name,
                                  currency=self.currency,
                                  entitlements=self.entitlements.to_target()))
        PositionedEntity.__init__(self, port.id, EntityType.PORTFOLIO)
        Entity.__init__(self, port.id, EntityType.PORTFOLIO)
        self.__id = port.id
        self._PositionedEntity__entity_type = EntityType.PORTFOLIO
        self.entitlements = Entitlements.from_target(port.entitlements)
        self.currency = Currency(port.currency)

        # If the portfolio contains positions, upload them to the MQ portfolio and schedule reports
        if self.position_sets:
            position_sets = self.position_sets
            self.position_sets = None
            self.update_positions(position_sets, False)
            self._schedule_first_reports(
                [pos_set.date for pos_set in position_sets])
            self.position_sets = None
Пример #2
0
    def __init__(self,
                 priceables: Optional[Union[PriceableImpl,
                                            Iterable[PriceableImpl],
                                            dict]] = (),
                 name: Optional[str] = 'Portfolio ' +
                 dt.datetime.today().strftime("%d %b, %Y"),
                 position_sets: Optional[List] = None,
                 currency: Optional[Currency] = Currency.USD,
                 entitlements: Entitlements = None,
                 *,
                 portfolio_id: str = None):
        """
        Creates a portfolio object which can be used to hold instruments

        :param priceables: constructed with an instrument, portfolio, iterable of either, or a dictionary where
            key is name and value is a priceable
        """
        PriceableImpl.__init__(self)
        Entity.__init__(self, portfolio_id, EntityType.PORTFOLIO)
        self.__name = name
        self.__id = portfolio_id
        self.__currency = currency
        self.__need_to_schedule_reports = False
        self.__entitlements = entitlements if entitlements else Entitlements()
        self.__position_sets = position_sets

        # Can't initialize a portfolio with both priceables or position sets
        if priceables and position_sets:
            raise ValueError(
                'Cannot initialize a portfolio with both position sets and priceables. Please pick one.'
            )

        if portfolio_id:
            # Can't add positions to an existing portfolio within the constructor
            if position_sets:
                raise ValueError(
                    'Cannot add positions to an existing portfolio at construction.'
                    'Please initialize the portfolio without the position sets and then update positions using the '
                    'update_positions(position_sets) function.')
            PositionedEntity.__init__(self, portfolio_id, EntityType.PORTFOLIO)

        if isinstance(priceables, dict):
            priceables_list = []
            for name, priceable in priceables.items():
                priceable.name = name
                priceables_list.append(priceable)
            self.priceables = priceables_list
        else:
            self.priceables = priceables