Esempio n. 1
0
def sumarize(quote):
    logging.info('Sumarizing trading code %s', quote['CODNEG'])

    if quote['QUATOT'] == 0 and quote['VOLTOT'] == 0 and quote['PREULT'] == 0:
        raise Exception('Quote {0} with no negociation in period: {1}'.format(quote['CODNEG'], quote))

    company = getCompanyByCod(quote['CODNEG'])
    if company is None: 
        raise Exception('Company with trading code {0} not found, ignoring...'.format(quote['CODNEG']))
    
    year = datetime.strptime(quote['DTPREG'][:10], '%Y-%m-%d').year
    fd = getFdByIdAndYear(es, company['id'], year, 'PRO')
    if fd is None:
        fd = getFdByIdAndYear(es, company['id'], year - 1)
        if fd is None:
            raise Exception('Company with trading code {0} not found, ignoring...'.format(quote['CODNEG']))
    
    normalizeFd(company, fd)
    company.update(quote)
    preco = getPrice(quote)
    company['CODNEG'] = quote['CODNEG']
    company['PRECO'] = preco
    company['ESPECI'] = quote['ESPECI']
    company['P/L'] = divSafe(preco, company['LPA'])
    company['P/VPA'] = divSafe(preco, company['VPA'])
    #company['DivYield'] = divSafe(company['DPA'], preco)
    return company
Esempio n. 2
0
def buildForecastData(companyid, qda, qdp, year):
    logging.info('Building Forecast of year %s', year)
    ffd = getFdByIdAndYear(es, companyid, year, 'PRO')
    #if ffd is None:
    ffd = qda[0].copy()
    ffd['ptype'] = 'PRO'
    ffd['period'] = str(year)
    
    ffd['LL'] = sum([getNewer(qda, qdp, year, i, 'LL') for i in range(1,5)])
    ffd['RL'] = sum([getNewer(qda, qdp, year, i, 'RL') for i in range(1,5)])
    #ffd['DIV'] = sum([getNewer(qda, qdp, year, i, 'DIV') for i in range(1,5)])
    return ffd 
Esempio n. 3
0
def forecast(companyid, year):
    logging.info('Normalizing company %s', companyid)

    if getFdByIdAndYear(es, companyid, year) !=  None:
        raise Exception('Company {0} already have DTF for year {1}, skipping...'.format(companyid, year))

    qda = getQuarterData(companyid, year)
    if len(qda) == 0:
        raise Exception('No quarter data for company {0} and year {1}, skipping...'.format(companyid, year))

    qdp = getQuarterData(companyid, year-1)
    buildFourthQuarter(companyid, qdp, year-1)
    return buildForecastData(companyid, qda, qdp, year) 
Esempio n. 4
0
def buildFourthQuarter(companyid, qd, year):
    logging.info('Building Fourth Quarter for compnay %s and year %s', companyid, year)
    period = '{0}12'.format(year)
    #fqd = filter(lambda x: x['period'] == period, qd)
    #if len(fqd) > 0: return
    qdtotal = getFdByIdAndYear(es, companyid, year)
    if qdtotal is None:
        raise Exception('error building fourth quarter for company %s: DFP not found for year %s', companyid, year)
    fqd = qdtotal.copy()
    fqd['period'] = period
    fqd['ptype'] = 'ITR' 
    fqd['RL'] = qdtotal['RL'] - sum(getIoQ(qd, year, i, 'RL') for i in range(1, 4))
    fqd['LL'] = qdtotal['LL'] - sum(getIoQ(qd, year, i, 'LL') for i in range(1, 4))
    #fqd['DIV'] = qdtotal['DIV'] - sum(getIoQ(qd, year, i, 'DIV') for i in range(1, 4))
    qd.append(fqd)
    saveInfos(es, fqd)