Ejemplo n.º 1
0
def update_end_date(track, intraday):
    container_id = 'trackscontainer_' + str(track.effective_container_id)
    track_id = 'track_' + str(track.id)
    last_value = client[container_id][track_id].find_one({},{'_id': -1})
    if last_value!=None:
        track.end_date = from_epoch(last_value['_id'])
        track.save()
Ejemplo n.º 2
0
def get_track_content(track, ascending = True, divisor = 1.0):
    LOGGER.info('Loading track content')
    container_id = 'trackscontainer_' + str(track.effective_container_id)
    track_id = 'track_' + str(track.id)
    raw_values = client[container_id][track_id].find().sort('_id',1 if ascending else -1)
    LOGGER.info('Track content loaded from ' + container_id + '.' + track_id + ' with ' + str(client[container_id][track_id].count()) + ' elements.')
    return [{'date':from_epoch(value[u'_id']), 'value': value[u'value']/divisor} for value in raw_values]
Ejemplo n.º 3
0
def get_valuation_content_display(content, start_date=None, end_date=None):
    key_start = 0
    if start_date!=None:
        key_start = epoch_time(start_date)
    key_end = float('inf')
    if end_date!=None:
        key_end = epoch_time(end_date)
    all_values = {from_epoch(long(key_date)).strftime('%Y-%m-%d'): content[key_date] for key_date in sorted(content.keys()) if key_start<=long(key_date) and key_end>=long(key_date)}
    return all_values
Ejemplo n.º 4
0
 def generate_tracks(self, container, frequency, valuation):
     LOGGER.info("Computing tracks of " + container.name + " with frequency " + frequency.name)
     perf_type = Attributes.objects.get(identifier='NUM_TYPE_PERF', active=True)
     nav_type = Attributes.objects.get(identifier='NUM_TYPE_NAV', active=True)
     final_status = Attributes.objects.get(identifier='NUM_STATUS_FINAL', active=True)
     official_type = Attributes.objects.get(identifier='PRICE_TYPE_OFFICIAL', active=True)
     finale_company = CompanyContainer.objects.get(name='FinaLE Engine')
     
     nav_track = get_track(container, {'track_type': 'NUM_TYPE_NAV', 'track_frequency':frequency.identifier, 'track_default': False, 'track_datasource': 'DATASOURCE_FINALE'})
     perf_track = get_track(container, {'track_type': 'NUM_TYPE_PERF', 'track_frequency':frequency.identifier, 'track_default': False, 'track_datasource': 'DATASOURCE_FINALE'})
     
     nav_content = []
     perf_content = []
     
     if nav_track==None:
         nav_track = TrackContainer()
         nav_track.effective_container = container
         nav_track.type = nav_type
         nav_track.quality = official_type
         nav_track.source = finale_company
         nav_track.status = final_status
         nav_track.frequency = frequency
         nav_track.frequency_reference = None
         nav_track.save()
     if perf_track==None:
         perf_track = TrackContainer()
         perf_track.effective_container = container
         perf_track.type = perf_type
         perf_track.quality = official_type
         perf_track.source = finale_company
         perf_track.status = final_status
         perf_track.frequency = frequency
         perf_track.frequency_reference = None
         perf_track.save()
     perf_key = PERF_MAPPING[frequency.identifier][0]
     if container.inception_date==None:
         nav_content.append({'date': datetime.datetime(2013,12,31), 'value': 100.0})
     else:
         nav_content.append({'date': dt.combine(dates.AddDay(container.inception_date, -1), dt.min.time()), 'value': 100.0})
         previous = 100.0
     for key_date in sorted(valuation.keys()):
         working_date = dt.combine(from_epoch(long(key_date)), dt.min.time())
         if get_work_date(working_date, frequency)==working_date:
             perf_content.append({'date': working_date, 'value': valuation[key_date]['performances']['mdietz'][perf_key]/100.0})
             previous = previous * (1.0 + valuation[key_date]['performances']['mdietz'][perf_key]/100.0)
             nav_content.append({'date': working_date, 'value':previous})
         
     set_track_content(perf_track, perf_content, True)
     set_track_content(nav_track, nav_content, True)
Ejemplo n.º 5
0
def compute_underlying_security(portfolios, tracks, spots, portfolio, operation, inner_security, key_date, work_date=None):
    portfolio_id = str(portfolio.id)
    inner_container = SecurityContainer.objects.get(id=inner_security)
    if not tracks.has_key(inner_security):
        track = get_main_track_content(inner_container)
        tracks[inner_security] = track
    value = get_closest_value(tracks[inner_security], operation.value_date if work_date==None else work_date)
    if value==None:
        LOGGER.error("No NAV available for " + inner_container.name + " as of " + str(from_epoch(long(key_date))))
        return None
    divisor = get_price_divisor(inner_container)
    portfolios[portfolio_id][key_date][inner_security]['price'] = value['value']
    portfolios[portfolio_id][key_date][inner_security]['price_divisor'] = divisor
    spot_pf = 1.0
    if inner_container.currency.short_name!=portfolio.currency.short_name and (not spots.has_key(inner_container.currency.short_name) or not spots[inner_container.currency.short_name].has_key(portfolio.currency.short_name)):
        spot_track = get_exchange_rate(inner_container.currency.short_name, portfolio.currency.short_name)
        if not spots.has_key(inner_container.currency.short_name):
            spots[inner_container.currency.short_name] = {}
        spots[inner_container.currency.short_name][portfolio.currency.short_name] = spot_track
    if inner_container.currency.short_name!=portfolio.currency.short_name and spots.has_key(inner_container.currency.short_name) and spots[inner_container.currency.short_name].has_key(portfolio.currency.short_name):
        value = get_closest_value(spots[inner_container.currency.short_name][portfolio.currency.short_name], operation.value_date if work_date==None else work_date)
        if value!=None:
            spot_pf = value['value']
        else:
            LOGGER.error("No SPOT available for " + inner_container.currency.short_name + '/' + portfolio.currency.short_name + " as of " + str(from_epoch(long(key_date))))
            return None
    portfolios[portfolio_id][key_date][inner_security]['price_pf'] = portfolios[portfolio_id][key_date][inner_security]['price'] * spot_pf
    portfolios[portfolio_id][key_date][inner_security]['price_pf_divisor'] = portfolios[portfolio_id][key_date][inner_security]['price'] * spot_pf / divisor
    portfolios[portfolio_id][key_date][inner_security]['spot_pf'] = spot_pf
    portfolios[portfolio_id][key_date][inner_security]['price_date'] = value['date'].strftime('%Y-%m-%d')