def calc_fixing_date(currency, value_date):
    '''
    This method returns the NDF fixing date for a given settlement date. Caller should make sure the input currency is a NDF pair
    '''

    if get_ndf_fixing_delivery_convention(currency) is None:
        raise ValueError(
            "Currency: %s not found in supported NDF currency pairs" %
            currency)
    if value_date.isoweekday() not in range(1, 6):
        raise ValueError(
            "Invalid value date: %s. Please make sure the date is NOT a weekend"
            % value_date)

    assetcurrencycountry = currency_to_countrycode(currency[:3])
    pricingcurrencycountry = currency_to_countrycode(currency[3:])
    fixing_date = value_date

    while get_fxspot_valuedate(
            price_date=fixing_date,
            assetcurrencycountry=assetcurrencycountry,
            pricingcurrencycountry=pricingcurrencycountry) > value_date:
        fixing_date -= timedelta(days=1) if fixing_date.isoweekday() in range(
            2, 6) else timedelta(days=3)
    return fixing_date
Example #2
0
def calc_fixing_date(currency, value_date):
    '''
    This method returns the NDF fixing date for a given settlement date. Caller should make sure the input currency is a NDF pair
    '''

    if len(currency) != 6:
        raise ValueError(
            "Invalid currency: %s, please enter a currency pair in the format like: EURUSD"
            % currency)
    if value_date.isoweekday() not in range(1, 6):
        raise ValueError(
            "Invalid value date: %s. Please make sure the date is a weekend" %
            value_date)

    assetcurrencycountry = currency_to_countrycode(currency[:3])
    pricingcurrencycountry = currency_to_countrycode(currency[3:])
    fixing_date = value_date

    while get_fxspot_valuedate(
            price_date=fixing_date,
            assetcurrencycountry=assetcurrencycountry,
            pricingcurrencycountry=pricingcurrencycountry) != value_date:
        fixing_date -= timedelta(days=1) if fixing_date.isoweekday() in range(
            2, 6) else timedelta(days=3)
    return fixing_date
Example #3
0
def calc_tenor_value_date(price_date, currency, tenor):
    """
    this method returns the settlement date corresponds to a fx forward tenor and pricing date and currency pair passed in. 
    e.g. passing in "1W", USDSGD, 2017-4-28 will return 2017-5-11  
    :return:
    """

    if not price_date:
        raise BadRequestError('Must specify price_date in querystring')

    if not tenor:
        raise BadRequestError('Must specify a tenor in querystring')
    tenor = str(tenor).upper()
    tenors = [
        'ON', 'TN', 'SP', 'SN', '1W', '2W', '3W', '1M', '2M', '3M', '4M', '5M',
        '6M', '7M', '8M', '9M', '10M', '12M', '15M', '18M', '21M', '2Y'
    ]
    if tenor not in tenors:
        raise BadRequestError(
            'Requested tenor is not supported for value date calculation')

    currencypair = currency
    if not currencypair:
        raise BadRequestError('Must specify a currency pair in querystring')

    currencypair = str(currencypair).upper()
    if len(currencypair) != 6:
        raise BadRequestError(
            'Currency pair format error, currency pair length is not 6 characters.'
        )
    assetcurrencycountry = currency_to_countrycode(currencypair[:3])
    pricingcurrencycountry = currency_to_countrycode(currencypair[3:])

    if not assetcurrencycountry:
        raise BadRequestError("%s is currently not supported currency." %
                              (assetcurrency))
    if not pricingcurrencycountry:
        raise BadRequestError("%s is currently not supported currency." %
                              (pricingcurrency))

    value_date = get_fxforward_valuedate(price_date, tenor,
                                         assetcurrencycountry,
                                         pricingcurrencycountry)
    return value_date
def calc_tenor_value_date(price_date, currency, tenor):
    """
    this method returns the settlement date corresponds to a fx forward tenor and pricing date and currency pair passed in. 
    e.g. passing in "1W", USDSGD, 2017-4-28 will return 2017-5-11  
    :return:
    """

    if not price_date:
        raise ValueError('Must specify price_date in querystring')

    if not tenor:
        raise ValueError('Must specify a tenor in querystring')
    tenor = str(tenor).upper()
    valid_tenor = tenor_validity(tenor)
    if not valid_tenor:
        raise ValueError(
            'Requested tenor: %s is not supported for value date calculation' %
            tenor)

    currencypair = currency
    if not currencypair:
        raise ValueError('Must specify a currency pair in querystring')

    currencypair = str(currencypair).upper()
    if len(currencypair) != 6:
        raise ValueError(
            'Currency pair format error, currency pair length is not 6 characters.'
        )
    assetcurrencycountry = currency_to_countrycode(currencypair[:3])
    pricingcurrencycountry = currency_to_countrycode(currencypair[3:])

    if not assetcurrencycountry:
        raise ValueError("%s is currently not supported currency." %
                         (assetcurrency))
    if not pricingcurrencycountry:
        raise ValueError("%s is currently not supported currency." %
                         (pricingcurrency))

    value_date = get_fxforward_valuedate(price_date, tenor,
                                         assetcurrencycountry,
                                         pricingcurrencycountry)
    return value_date