Ejemplo n.º 1
0
    def test_edit_instrument_property(self):

        property_value = models.PropertyValue(label_value="Insurance")
        property_key = f"Instrument/{TestDataUtilities.tutorials_scope}/CustomSector"
        identifier_type = "Figi"
        identifier = "BBG00KTDTF73"

        # update the instrument
        self.instruments_api.upsert_instruments_properties(
            upsert_instrument_property_request=[
                models.UpsertInstrumentPropertyRequest(
                    identifier_type=identifier_type,
                    identifier=identifier,
                    properties=[
                        models.ModelProperty(key=property_key,
                                             value=property_value)
                    ])
            ])

        # get the instrument with value
        instrument = self.instruments_api.get_instrument(
            identifier_type=identifier_type,
            identifier=identifier,
            property_keys=[property_key])

        self.assertGreaterEqual(len(instrument.properties), 1)

        prop = list(
            filter(
                lambda p: p.key == property_key and p.value.label_value ==
                property_value.label_value, instrument.properties))

        self.assertEqual(
            len(prop), 1,
            f"cannot find property key=${property_key} value={property_value}")
    def upsert_ratings_property(self, figi, fitch_value=None, moodys_value=None):

        properties = {
            f"Instrument/{scope}/FitchRating": fitch_value,
            f"Instrument/{scope}/MoodysRating": moodys_value,
        }

        # upsert property definition
        for key in properties:
            if properties[key] is not None:
                property_request = [
                    models.UpsertInstrumentPropertyRequest(
                        identifier_type="Figi",
                        identifier=figi,
                        properties=[
                            models.ModelProperty(
                                key=key,
                                value=models.PropertyValue(
                                    metric_value=models.MetricValue(
                                        value=properties[key]
                                    )
                                ),
                            )
                        ],
                    )
                ]

                self.instruments_api.upsert_instruments_properties(
                    upsert_instrument_property_request=property_request
                )
Ejemplo n.º 3
0
    def test_create_portfolio_with_properties(self):

        _, scope, property_code, _ = self.id_generator.generate_scope_and_code(
            "property_definition",
            scope=TestDataUtilities.tutorials_scope,
            code_prefix="fund-style-",
            annotations=["Portfolio"])

        data_type_id = models.ResourceId("system", "string")

        #   property definition
        property_definition = models.CreatePropertyDefinitionRequest(
            domain="Portfolio",
            scope=TestDataUtilities.tutorials_scope,
            code=property_code,
            value_required=False,
            display_name="Fund Style",
            life_time="Perpetual",
            data_type_id=data_type_id)

        #   create the property definition
        property_definition_result = self.property_definitions_api.create_property_definition(
            create_property_definition_request=property_definition)

        #  property value
        property_value = "Active"
        portfolio_property = models.ModelProperty(
            key=property_definition_result.key,
            value=models.PropertyValue(label_value=property_value))

        _, scope, portfolio_code = self.id_generator.generate_scope_and_code(
            "portfolio",
            scope=TestDataUtilities.tutorials_scope,
            code_prefix="portfolio-")

        #  details of the portfolio to be created
        request = models.CreateTransactionPortfolioRequest(
            display_name=portfolio_code,
            code=portfolio_code,
            base_currency="GBP",

            # set the property value when creating the portfolio
            properties={property_definition_result.key: portfolio_property})

        # create the portfolio
        portfolio = self.transaction_portfolios_api.create_portfolio(
            scope=scope, create_transaction_portfolio_request=request)

        portfolio_code = portfolio.id.code
        self.assertEqual(portfolio_code, request.code)

        portfolio_properties = self.portfolios_api.get_portfolio_properties(
            TestDataUtilities.tutorials_scope, portfolio_code)

        self.assertEqual(len(portfolio_properties.properties), 1)
        self.assertEqual(
            portfolio_properties.properties[
                property_definition_result.key].value.label_value,
            property_value)
def property_def(full_property, label_value):
    prop = models.ModelProperty(
        key=full_property, value=models.PropertyValue(label_value=label_value))

    return prop
    def test_create_portfolio_with_mv_property(self):
        # Details of property to be created
        effective_date = datetime(year=2018, month=1, day=1, tzinfo=pytz.utc)
        scope = "MultiValueProperties"
        code = "MorningstarQuarterlyRating"
        portfolio_code = "Portfolio-MVP"

        multi_value_property_definition = models.CreatePropertyDefinitionRequest(
            domain="Portfolio",
            scope=scope,
            code=code,
            display_name=code,
            constraint_style="Collection",
            data_type_id=lusid.ResourceId(scope="system", code="string"),
        )

        # create property definition
        try:
            self.property_definitions_api.create_property_definition(
                create_property_definition_request=
                multi_value_property_definition)
        except lusid.ApiException as e:
            if json.loads(e.body)["name"] == "PropertyAlreadyExists":
                logging.info(
                    f"Property {multi_value_property_definition.domain}/{multi_value_property_definition.scope}/{multi_value_property_definition.display_name} already exists"
                )
        finally:
            self.id_generator.add_scope_and_code(
                "property_definition", multi_value_property_definition.scope,
                multi_value_property_definition.code, ["Portfolio"])

        schedule = [
            '{ "2019-12-31" : "5"}',
            '{ "2020-03-31" : "4"}',
            '{ "2020-06-30" : "3"}',
            '{ "2020-09-30" : "3"}',
        ]

        # Details of new portfolio to be created
        create_portfolio_request = models.CreateTransactionPortfolioRequest(
            code=portfolio_code,
            display_name=portfolio_code,
            base_currency="GBP",
            created=effective_date,
        )

        # create portfolio
        try:
            self.transaction_portfolios_api.create_portfolio(
                scope=scope,
                create_transaction_portfolio_request=create_portfolio_request,
            )
        except lusid.ApiException as e:
            if json.loads(e.body)["name"] == "PortfolioWithIdAlreadyExists":
                logging.info(
                    f"Portfolio {create_portfolio_request.code} already exists"
                )
        finally:
            self.id_generator.add_scope_and_code("portfolio", scope,
                                                 portfolio_code)

        self.portfolios_api.upsert_portfolio_properties(
            scope=scope,
            code=portfolio_code,
            request_body={
                f"Portfolio/{scope}/{code}":
                models.ModelProperty(
                    key=f"Portfolio/{scope}/{code}",
                    value=models.PropertyValue(
                        label_value_set=models.LabelValueSet(values=schedule)),
                )
            },
        )

        # get properties for assertions
        portfolio_properties = self.portfolios_api.get_portfolio_properties(
            scope=scope, code=portfolio_code).properties
        label_value_set = portfolio_properties[
            f"Portfolio/MultiValueProperties/{code}"].value.label_value_set.values
        self.assertCountEqual(label_value_set, schedule)