Ejemplo n.º 1
0
    def register_zero_curves(self, market_data, forward_curves_list, discount_curve_list):
        """
        Registers zero rate curves provided by the MarketData instance to the
        OpenRedukti valuation service

        Args:
            market_data (MarketData): MarketData instance that provides the zero rate curves
            forward_curves_list: The curve definition ids that will be registered as Forward Curves
            discount_curve_list:  The curve definition ids that will be registered as Discount Curves

        Returns:
            None
        """
        if not isinstance(market_data, MarketData):
            raise ValueError('market_data must be of MarketData type')
        print('Registering zero curves')
        request = services_pb2.Request()
        for id in forward_curves_list:
            zc = market_data.find_zero_curve_by_id(id)
            if zc is None:
                raise ValueError('Could not find zero curve ' + str(id))
            request.set_zero_curves_request.forward_curves.append(zc)
        for id in discount_curve_list:
            zc = market_data.find_zero_curve_by_id(id)
            if zc is None:
                raise ValueError('Could not find zero curve ' + str(id))
            request.set_zero_curves_request.discount_curves.append(zc)
        request.set_zero_curves_request.as_of_date = market_data.business_date().serial()
        request.set_zero_curves_request.cycle = 0
        request.set_zero_curves_request.qualifier = enums.MDQ_NORMAL
        request.set_zero_curves_request.scenario = 0
        request.set_zero_curves_request.curve_group = market_data.curve_group()
        response = self._adapter.serve(request)
        if response.header.response_code != 0:
            raise RuntimeError(response.header.response_message)
Ejemplo n.º 2
0
    def hello(self, echo_string):
        """Invokes the hello service

        Args:
            echo_string: An input string that will be echoed back by the server

        Returns:
            An instance of HelloReply message
        """
        request = services_pb2.Request()
        request.hello_request.name = echo_string
        response = self._adapter.serve(request)
        if response.header.response_code != 0:
            raise RuntimeError(response.header.response_message)
        return response.hello_reply.message
Ejemplo n.º 3
0
    def reset_valuation_service(self):
        """Resets all cached market data held by the OpenRedukti valuation service

        Returns:
            None

        Raises:
            RuntimeError if there was a problem
        """
        request = services_pb2.Request()
        request.reset_valuation_service_request.SetInParent()
        response = self._adapter.serve(request)
        if response.header.response_code != 0:
            raise RuntimeError(response.header.response_message)
        return None
Ejemplo n.º 4
0
    def register_index_definition(self, index_definition):
        """Registers an index definition with the server

        Args:
            index_definition (index_pb2.IndexDefinition): An instance of index_pb2.IndexDefinition

        Returns:
            None
        """
        if not isinstance(index_definition, index.IndexDefinition):
            raise ValueError('index_definition must be of index.IndexDefinition type')
        request = services_pb2.Request()
        request.register_index_definition_request.index_definition = index_definition
        response = self._adapter.serve(request)
        if response.header.response_code != 0:
            raise RuntimeError(response.header.response_message)
Ejemplo n.º 5
0
    def register_curve_definitions(self, market_data):
        """
        Registers curve definitions provided by the MarketData instance to the
        OpenRedukti Valuation service.

        Args:
            market_data (MarketData): MarketData instance that provides the curve definitions
        """
        if not isinstance(market_data, MarketData):
            raise ValueError('market_data must be of MarketData type')
        print('Registering curve definitions')
        request = services_pb2.Request()
        request.register_curve_definitions_request.curve_definitions.extend(market_data.curve_definitions())
        response = self._adapter.serve(request)
        if response.header.response_code != 0:
            raise RuntimeError(response.header.response_message)
Ejemplo n.º 6
0
    def register_curve_mappings(self, curve_group, curve_mappings):
        """Registers the list of curve mappings with the OpenRedukti valuation server

        Args:
            curve_group: Curve group
            curve_mappings: The list of curve mappings, each mapping must be of type valuation_pb2.CurveMapping.

        Returns:
            None
        """
        print('Registering curve mappings')
        request = services_pb2.Request()
        request.set_curve_mappings_request.curve_group = curve_group
        request.set_curve_mappings_request.mappings.extend(curve_mappings)
        response = self._adapter.serve(request)
        if response.header.response_code != 0:
            raise RuntimeError(response.header.response_message)
Ejemplo n.º 7
0
    def shutdown_valuation_service(self):
        """Shuts down the valuation service

        Note that if you invoke this the valuation server will shutdown
        and will need to restarted

        Returns:
            None
        """
        if self._adapter.is_local():
            # Local instance, shutdown has no meaning
            return
        request = services_pb2.Request()
        request.shutdown_request.password = "******"
        response = self._adapter.serve(request)
        if response.header.response_code != 0:
            raise RuntimeError(response.header.response_message)
Ejemplo n.º 8
0
    def build_curves(self, market_data):
        """Invokes the curve building service and returns the resulting yield curves

        Args:
            market_data: MarketData instance that will be used to source curve definitions and market quotes (par rates)

        Returns:
            A list of yield curves upon success
        """
        if not isinstance(market_data, MarketData):
            raise ValueError('market_data must be of MarketData type')
        request = services_pb2.Request()
        request.bootstrap_curves_request.business_date = market_data._business_date.serial()
        request.bootstrap_curves_request.curve_definitions.extend(market_data._curve_definitions)
        request.bootstrap_curves_request.par_curve_set.CopyFrom(market_data._par_curve_set)
        print('Building curves, please wait.')
        response = self._adapter.serve(request)
        if response.header.response_code != 0:
            raise RuntimeError(response.header.response_message)
        return market_data.init_zero_curves(response.bootstrap_curves_reply)
Ejemplo n.º 9
0
    def register_fixings(self, market_data):
        """
        Registers fixings provided by the market data instance to the OpenRedukti
        Valuation service.

        Args:
            market_data (MarketData): MarketData instance that is the provider of fixings data

        Returns:
            None
        """
        if not isinstance(market_data, MarketData):
            raise ValueError('market_data must be of MarketData type')
        print('Registering fixings')
        fixings_by_index = market_data.fixings()
        for entry in fixings_by_index.values():
            request = services_pb2.Request()
            request.set_fixings_request.fixings_by_index_tenor.CopyFrom(entry)
            response = self._adapter.serve(request)
            if response.header.response_code != 0:
                raise RuntimeError(response.header.response_message)
Ejemplo n.º 10
0
    def get_valuation(self, pricing_context, cfcollection):
        """Request Valuation for a set of cashflows

        Args:
            pricing_context (valuation_pb2.PricingContext): Pricing Context that defines various parameters
            cfcollection (cashflow_pb2.CFCollection): cashflow collection instance that contains the cashflows to be evaluated

        Returns:
            The valuation service reply
        """
        if not isinstance(pricing_context, valuation.PricingContext):
            raise ValueError('pricing_context must of of type valuation_pb2.PricingContext')
        if not isinstance(cfcollection, cashflows.CFCollection):
            raise ValueError('cfcollection must be of type cashflow_pb2.CFCollection')
        print('Requesting valuation')
        request = services_pb2.Request()
        request.valuation_request.pricing_context.CopyFrom(pricing_context)
        request.valuation_request.cashflows.CopyFrom(cfcollection)
        response = self._adapter.serve(request)
        if response.header.response_code != 0:
            raise RuntimeError(response.header.response_message)
        return response.valuation_reply
Ejemplo n.º 11
0
    def register_calendar(self, business_center_id, holidays_list):
        """Registers a calendar for specified business center id

        Note that a calendar can only be registered at system start
        This is because calendars may be joined with other calendars and therefore
        once a calendar is in use it cannot be safely replaced

        Args:
            business_center_id (enums_pb2.BusinessCenter): Business Center id for which calendar is being registered
            holidays_list: List containing redukti.Date objects

        Returns:
            None
        """
        request = services_pb2.Request()
        for day in holidays_list:
            if not isinstance(day, redukti.Date):
                raise ValueError('Holidays must be a list of redukti.Date objects')
            request.register_calendar_request.holidays.append(day.serial())
        request.register_calendar_request.business_center = business_center_id
        print('Registering calendar ' + str(business_center_id))
        response = self._adapter.serve(request)
        if response.header.response_code != 0:
            raise RuntimeError(response.header.response_message)