Ejemplo n.º 1
0
def getPosition(lines):
    """
	[Iterable] lines => [Iterable] positions
	
	lines: from the Excel worksheet containing the holdings

	Return an iterable object on the list of holding positions. Each position
	is a dictionary.
	"""
    nonEmptyString = lambda s: s != ''
    position = lambda headers, values: dict(zip(headers, values))
    nonEmptyLine = lambda L: False if len(L) == 0 else nonEmptyString(L[0])
    headerLine = lambda L: L[0] == 'Trader Name' if len(L) > 0 else False
    nomuraOnly = lambda p: p['Trader Name'] == '40017-B'
    toDateString = lambda f: fromExcelOrdinal(f).strftime('%d%m%Y')

    def updateValue(p):
        p['As of Date'] = toDateString(p['As of Date'])
        p['Settlement Date'] = toDateString(p['Settlement Date'])
        return p

    headers = list(takewhile(nonEmptyString, firstOf(headerLine, lines)))
    return map(
        updateValue,
        filter(nomuraOnly,
               map(partial(position, headers), takewhile(nonEmptyLine,
                                                         lines))))
Ejemplo n.º 2
0
 def toDatetimeString(value):
     if isinstance(value, float):
         return datetime.strftime(fromExcelOrdinal(value), '%Y-%m-%d')
     else:
         try:
             return datetime.strftime(datetime.strptime(value, '%m/%d/%Y'),
                                      '%Y-%m-%d')
         except ValueError:
             return datetime.strftime(datetime.strptime(value, '%d/%m/%Y'),
                                      '%Y-%m-%d')
Ejemplo n.º 3
0
def loadLiquiditySpecialCaseFromFile(file):
    """
	[String] file => [Dictionary] id -> [Dictionary] liquidity data
	"""
    toDate = lambda x: \
     fromExcelOrdinal(x) if isinstance(x, float) else \
     datetime.strptime(x, '%m/%d/%Y')

    updatePosition = lambda position: mergeDict(
        position, {'CALC_MATURITY': toDate(position['CALC_MATURITY'])})


    return \
    compose(
     dict
      , partial(map, lambda p: (p['ID'], p))
      , partial(map, updatePosition)
      , getRawPositionsFromFile
    )(file)
Ejemplo n.º 4
0
	[String] file => [Iterable] lines

	Read an Excel file, convert its first sheet into lines, each line is
	a list of the columns in the row.
"""
fileToLines = lambda file: \
 worksheetToLines(open_workbook(file).sheet_by_index(0))
"""
	[List] line => [String] date (yyyy-mm-dd)

	First item in the line is the date. Most of the time the date is
	read a float number, but sometimes it is a string (dd/mm/yyyy)
"""
dateFromLine = lambda line: \
 (lambda x: \
  fromExcelOrdinal(x).strftime('%Y-%m-%d') \
  if isinstance(x, float) else \
  (lambda items: \
   items[2] + '-' + items[1] + '-' + items[0]
           )(x.split('/'))
    )(line[0])



isCashFile = lambda fn: \
 fn.split('\\')[-1].startswith('Cash Stt')



folderFromFilename = lambda fn: \
 (lambda s: '_'.join(s.split()))(fn.split('\\')[-2])
Ejemplo n.º 5
0
     dict
      , partial(map, lambda p: (p['SECURITIES'], p))
      , partial(map, updateSecurityId)
      , partial(map, partial(valmap, toNumberOrStripQuote))
      , lambda t: map(partial(toPosition, t[0]), t[1])
      , lambda lines: (list(map(stipDoubleQuote, pop(lines))), lines)
      , takeInBetween
      , partial(map, lambda line: line.split(separator))
      , fileToLines
      , lambda file: lognContinue('getLqaData(): from file: {0}'.format(file), file)
      , getLqaDataFile
    )(date, mode)


""" [Float] excel date value => [String] date string (yyyymmdd) """
toDateString = lambda x: datetime.strftime(fromExcelOrdinal(x), '%Y%m%d')


@lru_cache(maxsize=3)
def getFX(date, targetCurrency):
    """
	[String] date (yyyymmdd),
	[String] targetCurrency
		=> [Dictionary] currency -> exchange rate

	Exchange rate: to get 1 unit of target currency, how many units of another 
	currency is needed.

	For example, d = loadFXTableFromFile('20200430', 'USD')

	Then
Ejemplo n.º 6
0
 mergeDictionary( p
       , { 'Fund': toStringIfFloat(p['Trader Name'])
         , 'Ticker & Exc': p['Ticker and Exchange Code']
         , 'ISIN': p['ISIN Number']
         , 'Shrt Name': p['Short Name']
         , 'Crcy': p['Currency']
         , 'B/S': p['Buy/Sell']
         , 'Amount Pennies': p['Amount (Pennies)']
         , 'Price': p['Trade price']
         , 'Settle Amount': p['Settlement Total in Settlemen']
         , 'Bkr Comm': p['Transaction Cost 1 Amount']
         , 'Stamp Duty': p['Transaction Cost 2 Amount']
         , 'Exch Fee': p['Transaction Cost 3 Amount']
         , 'Trans. Levy': p['Transaction Cost 4 Amount']
         , 'Misc Fee': p['Transaction Cost 5 Amount']
         , 'As of Dt': datetime.strftime( fromExcelOrdinal(p['As of Date'])
              , '%Y-%m-%d')
         , 'Stl Date': datetime.strftime( fromExcelOrdinal(p['Settlement Date'])
              , '%Y-%m-%d')
         , 'Accr Int': p['Accrued Interest']
         , 'FACC Long Name': p['Firm Account Long Name']
         , 'L1 Tag Nm': 'Trading' if p['Level 1 Tag Name'] == 'AFS' and p['Trader Name'] == '11490-B' \
             else p['Level 1 Tag Name']
         }
       )


def lognContinue(msg, x):
    logger.debug(msg)
    return x