def __populate_current_attributes_for_existing_basket( self, gs_asset: GsAsset): self.__description = get(gs_asset, 'description', None) self.__gs_asset_type = get(gs_asset, 'type', None) self.__live_date = get(gs_asset, 'live_date', None) self.__ticker = get(gs_asset, 'xref.ticker', None) self.__clone_parent_id = get(gs_asset, 'parameters.clone_parent_id', None) self.__default_backcast = get(gs_asset, 'parameters.default_backcast', None) self.__flagship = get(gs_asset, 'parameters.flagship', None) self.__hedge_id = get(gs_asset, 'parameters.hedge_id', None) self.__return_type = get(gs_asset, 'parameters.index_calculation_type', None) last_positions = GsAssetApi.get_latest_positions(self.__id) self.__divisor = get(last_positions, 'divisor', None) last_initial_price = GsIndexApi.initial_price(gs_asset.id, DateLimit.TODAY.value) self.__initial_price = get(last_initial_price, 'price', None) report = self.__get_last_create_report() self.__include_price_history = get(report, 'parameters.include_price_history', None) self.__publish_to_bloomberg = get(report, 'parameters.publish_to_bloomberg', None) self.__publish_to_factset = get(report, 'parameters.publish_to_factset', None) self.__publish_to_reuters = get(report, 'parameters.publish_to_reuters', None)
def get_latest_position_set( self, position_type: PositionType = PositionType.CLOSE) -> PositionSet: if self.positioned_entity_type == EntityType.ASSET: response = GsAssetApi.get_latest_positions(self.id, position_type) return PositionSet.from_target(response) raise NotImplementedError
def get_latest_positions(self, position_type: PositionType = PositionType.CLOSE, format: ReturnFormat = ReturnFormat.DICT) -> Union[PositionSet, Dict, pd.DataFrame]: if self.positioned_entity_type == EntityType.ASSET: response = GsAssetApi.get_latest_positions(self.id, position_type) position_set = response if type(response) == PositionSet else PositionSet.from_dict(response) return self.__convert_position_set(position_set, format) raise MqTypeError(f'{self.__invalid_entity_message} {self.positioned_entity_type}')
def get_latest_position_set(self, position_type: PositionType = PositionType.CLOSE) -> PositionSet: if self.positioned_entity_type == EntityType.ASSET: response = GsAssetApi.get_latest_positions(self.id, position_type) return PositionSet.from_target(response) if self.positioned_entity_type == EntityType.PORTFOLIO: response = GsPortfolioApi.get_latest_positions(portfolio_id=self.id, position_type=position_type.value) return PositionSet.from_target(response) raise NotImplementedError
def from_asset_id(asset_id: str, date=None): asset = GsAssetApi.get_asset(asset_id) response = GsAssetApi.get_asset_positions_for_date(asset_id, date) if date else \ GsAssetApi.get_latest_positions(asset_id) response = response[0] if isinstance(response, tuple) else response positions = response.positions if isinstance(response, PositionSet) else response['positions'] instruments = GsAssetApi.get_instruments_for_positions(positions) ret = Portfolio(instruments, name=asset.name) ret.__id = asset_id return ret
def __finish_populating_attributes_for_existing_basket(self): """ Populates all values not originally fetched during initialization due to required API calls """ if self.__populate_api_attrs: position_set = GsAssetApi.get_latest_positions(self.id, PositionType.ANY) report = get(self, '__latest_create_report', self.__get_latest_create_report()) self.__divisor = get(position_set, 'divisor') self.__initial_price = get(GsIndexApi.initial_price(self.id, dt.date.today()), 'price') self.__parent_basket = None if self.__clone_parent_id is None else \ get(GsAssetApi.get_asset(self.__clone_parent_id), 'id') self.__position_set = PositionSet.from_target(position_set) self.__publish_to_bloomberg = get(report, 'parameters.publish_to_bloomberg') self.__publish_to_factset = get(report, 'parameters.publish_to_factset') self.__publish_to_reuters = get(report, 'parameters.publish_to_reuters') set_(self.__initial_state, 'divisor', self.__divisor) set_(self.__initial_state, 'initial_price', self.__initial_price) set_(self.__initial_state, 'position_set', self.__position_set) set_(self.__initial_state, 'publish_to_bloomberg', self.__publish_to_bloomberg) set_(self.__initial_state, 'publish_to_factset', self.__publish_to_factset) set_(self.__initial_state, 'publish_to_reuters', self.__publish_to_reuters) self.__initial_positions = set(deepcopy(self.__position_set.positions)) self.__populate_api_attrs = False
def __finish_initialization(self): """ Fetches remaining data not retrieved during basket initialization """ if has(self, 'id'): if not has(self, '__initial_positions'): position_set = GsAssetApi.get_latest_positions( self.id, PositionType.ANY) position_set = PositionSet.from_target(position_set) self.__position_set = position_set self.__divisor = get(position_set, 'divisor') self.__initial_positions = set( deepcopy(self.__position_set.positions)) set_(self.__initial_state, 'divisor', self.__divisor) set_(self.__initial_state, 'position_set', self.__position_set) if not has(self.__initial_state, 'initial_price'): initial_price = GsIndexApi.initial_price( self.id, dt.date.today()) self.__initial_price = get(initial_price, 'price') set_(self.__initial_state, 'initial_price', self.__initial_price) if not has(self.__initial_state, 'publish_to_bloomberg'): report = get(self, '__latest_create_report', self.__get_latest_create_report()) self.__publish_to_bloomberg = get( report, 'parameters.publish_to_bloomberg') self.__publish_to_factset = get( report, 'parameters.publish_to_factset') self.__publish_to_reuters = get( report, 'parameters.publish_to_reuters') set_(self.__initial_state, 'publish_to_bloomberg', self.__publish_to_bloomberg) set_(self.__initial_state, 'publish_to_factset', self.__publish_to_factset) set_(self.__initial_state, 'publish_to_reuters', self.__publish_to_reuters) if not has(self, '__entitlements'): self.__entitlements = BasketEntitlements.from_target( self.__initial_entitlements) self.__set_error_messages()