Esempio n. 1
0
def get_exchange_rate(source_currency, destination_currency):
    currency = SecurityContainer.objects.filter(name__startswith=source_currency + destination_currency)
    if currency.exists():
        currency = currency[0]
    else:
        threaded.bloomberg_data_query('NO_NEED', [source_currency + destination_currency + ' Curncy'], True)
        currency = SecurityContainer.objects.get(name__startswith=source_currency + destination_currency)
    divisor = get_price_divisor(currency)
    return get_main_track_content(currency, True, False, divisor)
Esempio n. 2
0
def get_exchange_rate_price(source_currency, destination_currency, value_date):
    currency = SecurityContainer.objects.filter(name__startswith=source_currency + destination_currency)
    if not currency.exists():
        threaded.bloomberg_data_query('NO_NEED', [source_currency + destination_currency + ' Curncy'], True)
    currency = SecurityContainer.objects.filter(name__startswith=source_currency + destination_currency)
    if currency.exists():
        value = get_closest_value(get_main_track_content(currency[0]), dt.combine(value_date, dt.min.time()))
        if value==None:
            return 1.0
        else:
            return value['value']
Esempio n. 3
0
def get_security_price(isin_code,bloomberg_code, value_date):
    securities = []
    if isin_code!=None and isin_code!='':
        securities = SecurityContainer.objects.filter(aliases__alias_type__name='ISIN', aliases__alias_value=isin_code)
    elif bloomberg_code!=None and bloomberg_code!='':
        securities = SecurityContainer.objects.filter(aliases__alias_type__name='BLOOMBERG', aliases__alias_value=bloomberg_code)
    if len(securities)==0 and ((bloomberg_code!=None and bloomberg_code!='') or (isin_code!=None and isin_code!='')):
        threaded.bloomberg_data_query('NO_NEED', [isin_code if bloomberg_code==None or bloomberg_code=='' else bloomberg_code], True)
        if isin_code!=None and isin_code!='':
            securities = SecurityContainer.objects.filter(aliases__alias_type__name='ISIN', aliases__alias_value=isin_code)
        elif bloomberg_code!=None and bloomberg_code!='':
            securities = SecurityContainer.objects.filter(aliases__alias_type__name='BLOOMBERG', aliases__alias_value=bloomberg_code)
    if len(securities)==0:
        LOGGER.warn("Security cannot be found:" + str(isin_code) + "/" + str(bloomberg_code))
        return 1.0
    else:
        value = get_closest_value(get_main_track_content(securities[0]), dt.combine(value_date, dt.min.time()))
        if value==None:
            return 1.0
        else:
            return value['value']