Example #1
0
    def get_fx_prices(self, fx_code:str) ->fxPrices:
        """
        Get a historical series of FX prices

        :param fx_code: currency code, in the form EURUSD
        :return: fxData object
        """
        currency1, currency2 = get_fx_tuple_from_code(fx_code)

        if currency1 == currency2:
            # Trivial, just a bunch of 1's
            fx_data = DEFAULT_RATE_SERIES

        elif currency2 == DEFAULT_CURRENCY:
            # We ought to have data
            fx_data = self._get_standard_fx_prices(fx_code)

        elif currency1 == DEFAULT_CURRENCY:
            # inversion
            fx_data = self._get_fx_prices_for_inversion(fx_code)

        else:
            # Try a cross rate
            fx_data = self._get_fx_cross(fx_code)

        return fx_data
Example #2
0
    def _get_fx_cross(self, fx_code: str) ->fxPrices:
        """
        Get a currency cross rate XXXYYY, eg not XXXUSD or USDXXX or XXXXXX

        :return: fxPrices
        """
        currency1, currency2 = get_fx_tuple_from_code(fx_code)
        currency1_vs_default = self._get_fx_prices_vs_default(currency1)
        currency2_vs_default = self._get_fx_prices_vs_default(currency2)

        if currency1_vs_default.empty or currency2_vs_default.empty:
            return fxPrices.create_empty()

        (aligned_c1, aligned_c2) = currency1_vs_default.align(
            currency2_vs_default, join="outer"
        )

        fx_rate_series = aligned_c1.ffill() / aligned_c2.ffill()

        return fx_rate_series
Example #3
0
    def _get_fx_prices_for_inversion(self, fx_code: str) -> fxPrices:
        """
        Get a historical series of FX prices, must be USDXXX

        :param currency2
        :return: fxData
        """
        currency1, currency2 = get_fx_tuple_from_code(fx_code)
        assert currency1 == DEFAULT_CURRENCY

        raw_fx_data = self._get_fx_prices_vs_default(currency2)
        if raw_fx_data.empty:
            self.log.warn(
                "Data for %s is missing, needed to calculate %s" %
                (currency2 + DEFAULT_CURRENCY, DEFAULT_CURRENCY + currency2))
            return raw_fx_data

        inverted_fx_data = 1.0 / raw_fx_data

        return inverted_fx_data
Example #4
0
    def _get_standard_fx_prices(self, fx_code: str) -> fxPrices:
        currency1, currency2 = get_fx_tuple_from_code(fx_code)
        assert currency2==DEFAULT_CURRENCY
        fx_data = self._get_fx_prices_vs_default(currency1)

        return fx_data