コード例 #1
0
    def __importDividents(self, folder):
        for name in os.listdir(folder):
            if not name.startswith('ShareDividends_') or not name.endswith(
                    '.xlsx'):
                continue
            excel = getExcel(os.path.join(folder, name))
            xls = excel.sheet_by_index(0)

            for idx in range(1, xls.nrows):
                row = xls.row(idx)
                if row[4].value != 'Cash Dividend':
                    raise Exception('Record not supported: %s' % (str(row)))

                d = datetime(
                    *xlrd.xldate_as_tuple(row[6].value, excel.datemode))
                fiat = row[9].value.split(' ', 1)[0]
                value = Decimal(fixNumber(row[9].value.replace(fiat, '')))

                if fiat not in row[11].value:
                    raise Exception(
                        'Dividend with difrent tax currency not supported: %s'
                        % (str(row)))

                tax = Decimal(fixNumber(row[11].value.replace(fiat, '')))
                percent = Decimal(fixNumber(row[10].value))

                afiat = row[2].value
                main = Action(d, EActionType.DIVIDEND,
                              Decimal(fixNumber(row[7].value)),
                              self.stock(name=row[3].value, currency=fiat))

                self._add(main)

                main2 = Action(d, EActionType.INCOME, value,
                               self.currency(fiat))

                main.addAction(main2)

                if afiat != fiat:
                    s = Action(d, EActionType.SELL, value * Decimal(-1),
                               self.currency(fiat))
                    main2.addAction(s)

                    s.addAction(
                        Action(d, EActionType.BUY,
                               Decimal(fixNumber(row[16].value)),
                               self.currency(afiat)))

                if not tax.is_zero():
                    main2.addAction(
                        Action(d, EActionType.TAX, tax, self.currency(fiat),
                               percent))
コード例 #2
0
    def __importCash(self, folder):
        for name in os.listdir(folder):
            if not name.startswith('CashTransactions') or not name.endswith(
                    '.xlsx'):
                continue

            excel = getExcel(os.path.join(folder, name))
            xls = excel.sheet_by_index(0)

            for idx in range(1, xls.nrows):
                row = xls.row(idx)
                d = datetime(
                    *xlrd.xldate_as_tuple(row[8].value, excel.datemode))
                inputValue = Decimal(
                    fixNumber(row[4].value.replace(',', '.').split(' ', 1)[0]))
                inputCurency = row[4].value.split(' ', 1)[1]
                outputValue = Decimal(
                    fixNumber(row[5].value.replace(',', '.').split(' ', 1)[0]))
                outputCurency = row[5].value.split(' ', 1)[1]

                if row[2].value == 'Depozyt zabezpieczający':
                    main = Action(d, EActionType.RECEIVE, inputValue,
                                  self.currency(inputCurency))

                    self._add(main)

                    if outputCurency != inputCurency:
                        sub = Action(d, EActionType.SELL,
                                     inputValue * Decimal(-1),
                                     self.currency(inputCurency))

                        main.addAction(sub)

                        sub.addAction(
                            Action(d, EActionType.BUY, outputValue,
                                   self.currency(outputCurency)))
                    continue

                if cleanText(row[2].value) == cleanText('Wycofanie środków'):

                    main = Action(
                        d, EActionType.SEND if row[3].value != "Custody Fee"
                        else EActionType.FEE, inputValue,
                        self.currency(inputCurency))
                    self._add(main)
コード例 #3
0
        def eraseTransation(time, symbol, row, transations):
            found = [
                idx for idx, x in enumerate(transations)
                if time.date() == x[0].date()
                and symbol == x[1] and row[F_TYPE] == x[2] and Decimal(
                    fixNumber(row[F_SUM])) == x[3] and row[F_ASSET] == x[4]
            ]
            if not found:
                return False

            del transations[found[0]]
            return True
コード例 #4
0
    def _import(self, folder):

        # import finance to get transationId to ISIN mapping
        isin_mapping = {}
        for name in os.listdir(folder):
            if not name.startswith('historiaFinansowa_') or not name.endswith('.csv'):
                continue

            csv = getCsv(os.path.join(folder, name))
            prev_dividend = None

            for row in csv:
                time = datetime.fromisoformat("-".join(reversed(row['Data operacji'].split('-'))))

                if row['Typ operacji'] == cleanText('Dywidendy') and row['Opis'].startswith(cleanText('DVCA Dywidenda pieniężna')):
                    isin = row['Opis'].split(':', 1)[0].split(' ')[-1].strip()
                    count =  Decimal(row['Opis'].split(':', 1)[1].split(' x ', 1)[0])
                    income = Decimal(fixNumber(row['Kwota']))
                    if 'rozliczenie' in row['Opis']:
                        main = Action(time,
                                      EActionType.DIVIDEND,
                                      count,
                                      self.stock(isin=isin, exchange='XWAR', currency='PLN'))

                        sub = Action(time,
                                     EActionType.INCOME,
                                     income,
                                     self.currency(row['Waluta']))

                        main.addAction(sub)
                        self._add(main)
                        prev_dividend = sub
                        continue

                    if 'podatek' in row['Opis'] and prev_dividend:
                        sub = Action(time,
                                     EActionType.TAX,
                                     income,
                                     self.currency(row['Waluta']))
                        prev_dividend.addAction(sub)
                        prev_dividend = None
                        continue

                if row['Typ operacji'] == '' and (row['Opis'] == cleanText('Saldo początkowe') or row['Opis'] == cleanText('Saldo końcowe')):
                    continue

                if row['Typ operacji'] == cleanText('Wpłaty/wypłaty'):
                    value = Decimal(fixNumber(row['Kwota']))
                    cur = row['Waluta']

                    self._add(Action(time,
                                     EActionType.RECEIVE if value > Decimal(0) else EActionType.SEND,
                                     value,
                                     self.currency(cur)))
                    continue

                if row['Typ operacji'] == cleanText('Blokady pod zlecenia') or row['Typ operacji'] == cleanText('Transakcje'):
                    data = row['Opis'].split(',', 2)
                    isin = data[-2].strip()
                    transation = data[-3].split(' ')[-1].strip()
                    isin_mapping[transation] = isin
                    continue

        for name in os.listdir(folder):
            if not name.startswith('historiaTransakcji_') or not name.endswith('.csv'):
                continue

            csv = getCsv(os.path.join(folder, name))
            for row in csv:
                d = [int(x) for x in row['Data transakcji'].replace('-', ' ').split(' ')]
                time = datetime(d[2], d[1], d[0], d[3], d[4], d[5])
                nr = row['Numer zlecenia']
                isin = isin_mapping[nr]
                k = row['Kierunek'] == 'Kupno'
                main = Action(time,
                              EActionType.BUY if k else EActionType.SELL,
                              Decimal(fixNumber(row[cleanText('Ilość')])) * (Decimal(1) if k else Decimal(-1)),
                              self.stock(isin=isin, ticker=row['Papier'], exchange='XWAR', currency='PLN'))

                cost = Action(time,
                              EActionType.PAYMENT if k else EActionType.INCOME,
                              Decimal(fixNumber(row[cleanText('Wartość')])) * (Decimal(-1) if k else Decimal(1)),
                              self.currency('PLN'))
                main.addAction(cost)

                fee = Action(time,
                             EActionType.FEE,
                             Decimal(fixNumber(row[cleanText('Prowizja')]))*Decimal(-1),
                             self.currency('PLN'))
                
                main.addAction(fee)
                self._add(main)
コード例 #5
0
    def _import(self, folder):

        # import finance to get transationId to ISIN mapping
        orders = []
        for name in os.listdir(folder):
            if not name.startswith('Historia operacji finansowych ') or not name.endswith('.csv'):
                continue

            csv = getCsv(os.path.join(folder, name))

            last_send_outside = None
            for row in reversed(csv):
                time = datetime.fromisoformat("-".join(reversed(row[cleanText('Data księgowania')].split(' ', 1)[0].split('.'))))
                before =  Decimal(fixNumber(row[cleanText('Saldo początkowe')]))
                after = Decimal(fixNumber(row[cleanText('Saldo końcowe')]))
                kwota = after - before

                if row['Typ operacji'] == cleanText('Uznania') and row['Opis'].startswith('Dywidenda: '):
                    isin = row['Opis'].split('(', 1)[0].strip().split(' ')[-1]
                    name = row['Opis'].split('(', 1)[1].split(')', 1)[0].strip()
                    main = Action(time,
                                  EActionType.DIVIDEND,
                                  Decimal(1),
                                  self.stock(isin=isin, ticker=name, currency='PLN'))

                    self._add(main)
                    main.addAction(Action(time,
                                          EActionType.INCOME,
                                          kwota,
                                          self.currency('PLN')))
                    continue

                if row['Typ operacji'] == cleanText('Uznania') and 'Dywid.' in row['Opis'] and len(row['Opis'].split(';')) == 3:
                    #K039 Dywid. 261 szt PJSC GAZPR US3682872078; brutto 0.413 USD/szt; USD/PLN 3.6752
                    isin = row['Opis'].split(';')[0].split(' ')[-1]
                    szt = Decimal(row['Opis'].split('szt ', 1)[0].strip().split(' ')[-1])
                    value = Decimal(row['Opis'].split('brutto ', 1)[1].split(' ')[0])
                    cur = row['Opis'].split('/szt', 1)[0].split(' ')[-1]
                    conv = Decimal(row['Opis'].split('/PLN ', 1)[1].strip())

                    main = Action(time,
                                  EActionType.DIVIDEND,
                                  szt,
                                  self.stock(isin=isin, currency=cur))
                    self._add(main)
                    
                    sub = Action(time,
                                 EActionType.INCOME,
                                 value*szt,
                                 self.currency(cur))

                    main.addAction(sub)

                    sub2 = Action(time,
                                  EActionType.SELL,
                                  kwota/conv*Decimal(-1),
                                  self.currency(cur))

                    sub.addAction(sub2)

                    sub2.addAction(Action(time,
                                          EActionType.BUY,
                                          kwota,
                                          self.currency('PLN')))

                    sub.addAction(Action(time,
                                         EActionType.TAX,
                                         kwota/conv-szt*value,
                                         self.currency(cur)))
                    continue
            
                if row['Typ operacji'] == cleanText('Obciążenia') and row['Opis'].startswith('Przelew na rachunek bankowy'):
                    # sending funds
                    main = Action(time,
                                  EActionType.SEND,
                                  kwota,
                                  self.currency(row['Opis'].split('/')[-1].strip()))
                    last_send_outside = main
                    self._add(main)
                    continue

                if row['Typ operacji'] == cleanText('Obciążenia') and row['Opis'].startswith(cleanText('Księgowanie prowizji od dyspozycji przelewu')) and last_send_outside:
                    # sending funds - fee
                    main = Action(time,
                                  EActionType.FEE,
                                  kwota,
                                  last_send_outside.asset)
                    last_send_outside.addAction(main)
                    last_send_outside = None
                    continue

                last_send_outside = None
                
                if row['Typ operacji'] == cleanText('Uznania') and row['Opis'].startswith('WYC.BK:'):
                    # new funds adding
                    main = Action(time,
                                  EActionType.RECEIVE,
                                  kwota,
                                  self.currency('PLN'))
                    self._add(main)
                    continue

                if row['Typ operacji'] == cleanText('Uznania') and row['Opis'].startswith('NOT:'):
                    # - money
                    orders.append((time, kwota, row['Opis'].split('PW:', 1)[1].strip()))
                    continue
                
                if row['Typ operacji'] == cleanText('Obciążenia') and row['Opis'].startswith('NOT:'):
                    # + money
                    orders.append((time, kwota, row['Opis'].split('PW:', 1)[1].strip()))
                    continue
                if row['Typ operacji'] == cleanText('Obciążenia') and row['Opis'] == cleanText('opłata za prowadzenie rachunku'):
                    main = Action(time,
                                  EActionType.FEE,
                                  kwota,
                                  self.currency('PLN'))
                    self._add(main)
                    continue

                raise Exception('Unsupported record: %s' % (row))

        orders.sort(key=lambda x : x[0])

        transations = []
        for name in os.listdir(folder):
            if not name.startswith('Historia transakcji ') or not name.endswith('.csv'):
                continue

            csv = getCsv(os.path.join(folder, name))
            for row in csv:
                d = [int(x) for x in row['Czas transakcji'].replace(':', ' ').replace('.', ' ').split(' ')]
                time = datetime(d[2], d[1], d[0], d[3], d[4], d[5])
                transations.append((time, row))

        transations.sort(key=lambda x : x[0])
        for time, row in transations:
            currency = row['Waluta rozliczenia']
            count = Decimal(fixNumber(row['Liczba']))
            value = Decimal(fixNumber(row['Kurs']))
            stockCurrency = row['Waluta']
            sumValue = Decimal(fixNumber(row[cleanText('Wartość')]))
            fee = Decimal(fixNumber(row['Prowizja']))
        
            k = row['K/S'] == 'K'

            order = orders.pop(0)
            if order[0].date() != time.date() or sumValue * (Decimal(-1) if k else Decimal(1)) != order[1]:
                raise Exception("Finance and Transation history don't match: %s != %s" % (str(order), str(row)))

            if fee:
                feeOrder = orders.pop(0)
                if feeOrder[0].date() != time.date() or -fee != feeOrder[1] or feeOrder[2] != order[2]:
                    raise Exception("Finance and Transation history don't match: %s != %s" % (str(feeOrder), str(row)))

            main = Action(time,
                          EActionType.BUY if k else EActionType.SELL,
                          count * (Decimal(1) if k else Decimal(-1)),
                          self.stock(isin=order[2], ticker=row['Walor'], exchange=row[cleanText('Giełda')], currency=stockCurrency))

            self._add(main)

            if fee:
                f = Action(time,
                           EActionType.FEE,
                           -fee,
                           self.currency(currency))
                main.addAction(f)

            if stockCurrency != currency:
                sub = Action(time,
                             EActionType.PAYMENT if k else EActionType.INCOME,
                             value * count * (Decimal(-1) if k else Decimal(1)),
                             self.currency(stockCurrency))

                main.addAction(sub)
                
                sub2 = Action(time,
                              EActionType.BUY if k else EActionType.SELL,
                              value * count * (Decimal(1) if k else Decimal(-1)),
                              self.currency(stockCurrency))

                sub.addAction(sub2)

                sub3 = Action(time,
                              EActionType.SELL if k else EActionType.BUY,
                              sumValue * (Decimal(-1) if k else Decimal(1)),
                              self.currency(currency))

                sub2.addAction(sub3)
            else:
                sub = Action(time,
                             EActionType.PAYMENT if k else EActionType.INCOME,
                             sumValue * (Decimal(-1) if k else Decimal(1)),
                             self.currency(currency))
                main.addAction(sub)

        if orders:
            raise Exception('Not all orders consumed: %s' % (str(orders)))
コード例 #6
0
    def __importTransations(self, folder):
        for name in os.listdir(folder):
            if not name.startswith('TradesExecuted_') or not name.endswith(
                    '.xlsx'):
                continue

            excel = getExcel(os.path.join(folder, name))
            xls = excel.sheet_by_index(1)

            for idx in range(1, xls.nrows):
                row = xls.row(idx)
                name = row[2].value.split('(', 1)[0].strip()
                isin = None if 'ISIN:' not in row[2].value else row[
                    2].value.split('ISIN:', 1)[1].split(')')[0].strip()
                ticker = row[11].value.split(
                    ':', 1)[0] if ':' in row[11].value else row[11].value
                ex = row[11].value.split(
                    ':', 1)[1] if ':' in row[11].value else None

                d = datetime(
                    *xlrd.xldate_as_tuple(row[3].value, excel.datemode))

                count = Decimal(fixNumber(row[6].value))
                value = Decimal(fixNumber(row[8].value))

                blockedAcount = Decimal(fixNumber(row[20].value))
                blockedClient = Decimal(fixNumber(row[19].value))

                accountCurrency = row[18].value
                clientCurrency = row[21].value

                k = row[4].value == 'Bought'

                if accountCurrency != clientCurrency:
                    raise Exception(
                        'Transations bettwen %s - %s were not tested & implemented'
                        % (accountCurrency, clientCurrency))

                if row[16].value == 'FxSpot':

                    main = Action(
                        d, EActionType.FOREX, count,
                        self.stock(None, ticker, ex, clientCurrency, name))

                    if not blockedClient.is_zero():
                        main.addAction(
                            Action(
                                d, EActionType.PAYMENT
                                if k else EActionType.INCOME, blockedClient,
                                self.currency(clientCurrency)))
                    self._add(main)
                    continue

                main = Action(
                    d, EActionType.BUY if k else EActionType.SELL, count,
                    self.stock(isin, ticker, ex, clientCurrency, name))

                self._add(main)

                sub = Action(d, EActionType.SELL if k else EActionType.BUY,
                             value, self.currency(clientCurrency))
                main.addAction(sub)

                cost = blockedClient - value

                if cost:
                    sub2 = Action(d, EActionType.FEE, cost,
                                  self.currency(clientCurrency))
                    main.addAction(sub2)
コード例 #7
0
    def _import(self, folder):

        transations = []

        C_TIME = 0
        C_COUNT = 8
        C_ISIN = 4
        C_SYMBOL = 3
        C_CURRENCY = 7
        C_TYPE = 5
        C_VOLUME = 12
        C_SIDE = 2
        C_COMMISSION = 9
        C_COMMISSION_CURRENCY = 10

        for name in os.listdir(folder):
            if not name.startswith('Trades_') or not name.endswith('.csv'):
                continue

            csv = getCsv(os.path.join(folder, name), '\t', 'utf-16')
            if not csv:
                continue

            for row in reversed(csv):
                d = [
                    int(x) for x in row[C_TIME].replace('-', ' ').replace(
                        ':', ' ').split(' ')
                ]
                time = datetime(d[0], d[1], d[2], d[3], d[4], d[5])

                k = row[C_SIDE] == 'buy'

                main = Action(
                    time, EActionType.BUY if k else EActionType.SELL,
                    Decimal(fixNumber(row[C_COUNT])) *
                    (Decimal(1) if k else Decimal(-1)),
                    self.stock(
                        None if row[C_ISIN] == 'None' else row[C_ISIN],
                        row[C_SYMBOL].split(
                            '.', 1)[0], None if '.' not in row[C_SYMBOL] else
                        row[C_SYMBOL].split('.', 1)[1], row[C_CURRENCY])
                    if row[C_TYPE] != 'FOREX' else self.currency(
                        row[C_SYMBOL].split('/')[0]))
                self._add(main)

                sub = Action(
                    time, EActionType.PAYMENT if k else EActionType.INCOME,
                    Decimal(fixNumber(row[C_VOLUME])) *
                    (Decimal(-1) if k else Decimal(1)),
                    self.currency(row[C_CURRENCY]))

                main.addAction(sub)

                fee = Decimal(fixNumber(row[C_COMMISSION]))
                transation = []
                if fee:
                    main.addAction(
                        Action(time, EActionType.FEE, fee * Decimal(-1),
                               self.currency(row[C_COMMISSION_CURRENCY])))
                    transations.append(
                        (time, row[C_SYMBOL], 'COMMISSION', fee * Decimal(-1),
                         row[C_COMMISSION_CURRENCY]))

                transations.append(
                    (time, row[C_SYMBOL], 'TRADE', sub.count, str(sub.asset)))
                transations.append((time, row[C_SYMBOL], 'TRADE', main.count,
                                    str(main.asset)))

        financial = []

        F_WHEN = 5
        F_SYMBOL = 2
        F_TYPE = 4
        F_ASSET = 7
        F_COMMENT = 9
        F_SUM = 6

        for name in os.listdir(folder):
            if not name.startswith('Financial_') or not name.endswith('.csv'):
                continue

            csv = getCsv(os.path.join(folder, name), '\t', 'utf-16')
            if not csv:
                continue

            last = (None, None)
            for row in reversed(csv):
                d = [
                    int(x) for x in row[F_WHEN].replace('-', ' ').replace(
                        ':', ' ').split(' ')
                ]
                time = datetime(d[0], d[1], d[2], d[3], d[4], d[5])
                financial.append([time, row[F_SYMBOL], row])

        financial.sort(key=lambda x: x[0])

        def eraseTransation(time, symbol, row, transations):
            found = [
                idx for idx, x in enumerate(transations)
                if time.date() == x[0].date()
                and symbol == x[1] and row[F_TYPE] == x[2] and Decimal(
                    fixNumber(row[F_SUM])) == x[3] and row[F_ASSET] == x[4]
            ]
            if not found:
                return False

            del transations[found[0]]
            return True

        # process autoconversions first
        autoconversions = [
            x for x in financial if x[2][F_TYPE] == 'AUTOCONVERSION'
        ]

        while autoconversions:
            time, symbol, row = autoconversions[0]
            del autoconversions[0]
            if autoconversions and autoconversions[0][2][F_SYMBOL] == row[
                    F_SYMBOL] and autoconversions[0][2][F_WHEN] == row[F_WHEN]:
                row2 = autoconversions[0][2]
                del autoconversions[0]
                plus = row2 if Decimal(fixNumber(row2[F_SUM])) > Decimal(
                    fixNumber(row[F_SUM])) else row
                minus = row2 if Decimal(fixNumber(row2[F_SUM])) < Decimal(
                    fixNumber(row[F_SUM])) else row

                main = Action(time, EActionType.PAYMENT,
                              Decimal(fixNumber(minus[F_SUM])),
                              self.currency(minus[F_ASSET]))

                sub = Action(time, EActionType.BUY,
                             Decimal(fixNumber(plus[F_SUM])),
                             self.currency(plus[F_ASSET]))
                sub.addAction(main)
                self._add(sub)
                continue

            raise Exception("Not suported row: %s" % (str(row)))

        financial = [x for x in financial if x[2][F_TYPE] != 'AUTOCONVERSION']

        while financial:
            time, symbol, row = financial[0]
            if row[F_TYPE] == 'TRADE' or row[F_TYPE] == 'COMMISSION':
                if not eraseTransation(time, symbol, row, transations):
                    print(transations)
                    raise Exception("Not consumed financial row: %s" %
                                    (str(row)))
                del financial[0]
                continue

            del financial[0]

            if row[F_TYPE] == 'FUNDING/WITHDRAWAL' or row[
                    F_TYPE] == 'SUBACCOUNT TRANSFER':
                value = Decimal(fixNumber(row[F_SUM]))
                main = Action(
                    time, EActionType.RECEIVE
                    if value > Decimal(0) else EActionType.SEND, value,
                    self.currency(row[F_ASSET]))
                self._add(main)
                continue

            if (row[F_TYPE] == 'TAX' and financial
                    and financial[0][2][F_TYPE] == 'DIVIDEND'
                    and financial[0][2][F_SYMBOL] == symbol
                    and financial[0][2][F_WHEN] == row[F_WHEN]):

                tax = Action(
                    time, EActionType.TAX, Decimal(fixNumber(row[F_SUM])),
                    self.currency(row[F_ASSET]),
                    Decimal(
                        fixNumber(
                            financial[0][2][F_COMMENT].split('(')[-1].split(
                                '%)', 1)[0])))

                row = financial[0][2]
                del financial[0]

                main = Action(
                    time, EActionType.DIVIDEND,
                    Decimal(
                        fixNumber(row[F_COMMENT].split('shares',
                                                       1)[0].strip())),
                    self.stock(ticker=symbol.split('.', 1)[0],
                               exchange=symbol.split('.', 1)[1],
                               currency=row[F_ASSET]))

                income = Action(time, EActionType.INCOME,
                                Decimal(fixNumber(row[F_SUM])),
                                self.currency(row[F_ASSET]))

                income.addAction(tax)
                main.addAction(income)
                self._add(main)
                continue

            if row[F_TYPE] == 'DIVIDEND':
                main = Action(
                    time, EActionType.DIVIDEND,
                    Decimal(
                        fixNumber(row[F_COMMENT].split('shares',
                                                       1)[0].strip())),
                    self.stock(ticker=symbol.split('.', 1)[0],
                               exchange=symbol.split('.', 1)[1],
                               currency=row[F_ASSET]))
                income = Action(time, EActionType.INCOME,
                                Decimal(fixNumber(row[F_SUM])),
                                self.currency(row[F_ASSET]))
                main.addAction(income)
                self._add(main)
                continue

            if (row[F_TYPE] == 'EXERCISE' and financial
                    and financial[0][2][F_TYPE] == row[F_TYPE]
                    and financial[0][2][F_COMMENT] == row[F_COMMENT]
                    and financial[0][2][F_SYMBOL] == row[F_SYMBOL]
                    and row[F_COMMENT].endswith(' Exercised Rights')):
                financial[0][2][F_TYPE] = 'TRADE'
                row[F_TYPE] = 'TRADE'
                financial = [(time, symbol, row)] + financial
                continue

            if (row[F_TYPE] == 'CORPORATE ACTION' and financial
                    and financial[0][2][F_TYPE] == 'CORPORATE ACTION'
                    and financial[0][2][F_WHEN] == row[F_WHEN]
                    and financial[0][2][F_COMMENT] == row[F_COMMENT]
                    and row[F_COMMENT] == "%s -> %s" %
                (financial[0][2][F_SYMBOL], symbol)):

                self._assets.changeName(
                    financial[0][2][F_SYMBOL].split('.', 1)[0],
                    financial[0][2][F_SYMBOL].split('.', 1)[1],
                    symbol.split('.', 1)[0],
                    symbol.split('.', 1)[1])
                del financial[0]
                continue

            if row[F_TYPE] == 'CORPORATE ACTION' and row[F_COMMENT].endswith(
                    ' Rights'):
                self._add(
                    Action(
                        time, EActionType.BUY, Decimal(fixNumber(row[F_SUM])),
                        self.stock(ticker=symbol.split('.', 1)[0],
                                   exchange=symbol.split('.', 1)[1])))
                continue

            if (row[F_TYPE] == 'STOCK SPLIT'
                    and "Stock Split " in row[F_COMMENT] and len(financial) > 1
                    and financial[0][2][F_TYPE] == 'STOCK SPLIT'
                    and financial[0][2][F_SYMBOL] == row[F_SYMBOL]
                    and financial[1][2][F_TYPE] == 'STOCK SPLIT'
                    and financial[1][2][F_SYMBOL] == row[F_SYMBOL]):

                row_cash = row if 'Fractional Share Payment' in row[
                    F_COMMENT] else None
                if not row_cash:
                    row_cash = financial[0][
                        2] if 'Fractional Share Payment' in financial[0][2][
                            F_COMMENT] else financial[1][2]

                row_old = row if row[F_SYMBOL] == row[F_ASSET] and int(
                    row[F_SUM]) < 0 else None
                if not row_old:
                    row_old = financial[0][2] if financial[0][2][
                        F_ASSET] == row[F_SYMBOL] and int(
                            financial[0][2][F_SUM]) < 0 else financial[1][2]

                row_new = row if row[F_SYMBOL] == row[F_ASSET] and int(
                    row[F_SUM]) > 0 else None
                if not row_new:
                    row_new = financial[0][2] if financial[0][2][
                        F_ASSET] == row[F_SYMBOL] and int(
                            financial[0][2][F_SUM]) > 0 else financial[1][2]

                split = row_old[F_COMMENT].replace('Stock Split ',
                                                   '').split(" for ", 1)
                sold = Decimal(
                    int(row_old[F_SUM]) + int(row_new[F_SUM]) * int(split[1]))
                split = Decimal(split[0]) / Decimal(split[1])
                asset = self.stock(ticker=symbol.split('.', 1)[0],
                                   exchange=symbol.split('.', 1)[1],
                                   currency=row_cash[F_ASSET])

                def getTime(when):
                    d = [
                        int(x) for x in row[F_WHEN].replace('-', ' ').replace(
                            ':', ' ').split(' ')
                    ]
                    return datetime(d[0], d[1], d[2], d[3], d[4], d[5])

                main = Action(getTime(row_old[F_WHEN]), EActionType.SELL, sold,
                              asset)
                income = Action(getTime(row_cash[F_WHEN]), EActionType.INCOME,
                                Decimal(fixNumber(row_cash[F_SUM])),
                                self.currency(row_cash[F_ASSET]))

                main.addAction(income)
                self._add(main)
                self._split(asset, max(time, financial[0][0], financial[1][0]),
                            split)
                del financial[0]
                del financial[0]
                continue

            if (row[F_TYPE] == 'STOCK SPLIT'
                    and "Stock Split " in row[F_COMMENT] and financial
                    and financial[0][2][F_TYPE] == 'STOCK SPLIT'
                    and financial[0][2][F_COMMENT] == row[F_COMMENT]
                    and financial[0][2][F_ASSET] == row[F_ASSET]):

                split = row[F_COMMENT].replace('Stock Split ',
                                               '').split(" for ", 1)
                split = Decimal(split[0]) / Decimal(split[1])
                asset = self.stock(ticker=symbol.split('.', 1)[0],
                                   exchange=symbol.split('.', 1)[1])

                self._split(asset, time, split)
                del financial[0]
                continue

            raise Exception("Not suported row: %s" % (str(row)))

        if transations:
            raise Exception("No all transations consumed: %s" %
                            (str(transations)))