예제 #1
0
    def pd_acct_balances(self, company_id, dates, paths=None, acct_list=None, excl_contra=None, excl_interco=False, cp=None, with_tags=None, excl_tags=None):

        if not acct_list:
            if paths:
                accts = list(itertools.chain(*[api_func('gl', 'path_accounts', p) for p in paths]))
                acct_list = [x['id'] for x in accts]
            else:
                acct_list = [x['id'] for x in api_func('gl', 'path_accounts', '')]

        dates_dict = dict((dt, utils.get_dates_dict(dates[dt])) for dt in dates)

        with_counterparties = [cp.id] if cp else None
        date_indexed_account_balances = self.gl_strategy.account_balances_for_dates(company_id, acct_list, dates_dict, with_counterparties, excl_interco, excl_contra, with_tags, excl_tags)

        # filter empties
        for dt in date_indexed_account_balances:
            d = date_indexed_account_balances[dt]
            date_indexed_account_balances[dt] = {k:d[k] for k in d if d[k] != 0.0}

        output = pd.DataFrame(date_indexed_account_balances)

        if paths:
            a = [[x['id'] for x in api_func('gl', 'path_accounts', path)] for path in paths]
            accts_list = list(itertools.chain(*a))
            return output[output.index.isin(acct_list)]
        elif acct_list:
            filtered_output = output[output.index.isin(acct_list)]
            return filtered_output

        return output
예제 #2
0
    def pd_path_balances(self, company_id, dates, paths, filter_zeros=True, assets=False, excl_contra=None, excl_interco=False, with_tags=None, excl_tags=None):

        path_accts = dict((p, [x['id'] for x in api_func('gl', 'path_accounts', p)]) for p in paths)
        acct_list = list(itertools.chain(*[path_accts[p] for p in paths]))

        dates_dict = dict((dt, utils.get_dates_dict(dates[dt])) for dt in dates)
        date_indexed_account_balances = self.gl_strategy.account_balances_for_dates(company_id, acct_list, dates_dict, None, excl_interco, excl_contra, with_tags, excl_tags)

        data = {}
        for dt in date_indexed_account_balances:
            account_balances = date_indexed_account_balances[dt]

            tuples = []
            for path in paths:
                path_sum = 0
                for account_id in path_accts[path]:
                    if account_id in account_balances:
                        path_sum -= account_balances[account_id]
                tuples.append((path, path_sum))

            data[dt] = dict(tuples)

        output = pd.DataFrame(data)

        if filter_zeros:
            output['empty'] = output.apply(lambda row: np.all(row.values == 0.0), axis=1)
            output = output[output['empty']==False]
            output.drop('empty', axis=1, inplace=True)

        # adjust assets sign
        if assets:
            asset_factor = output.index.map(lambda x: -1.0 if x[:6] == 'assets' else 1.0)
            for col in output.columns:
                output[col] = output[col] * asset_factor
        return output
예제 #3
0
    def pd_path_balances(self,
                         company_id,
                         dates,
                         paths,
                         filter_zeros=True,
                         assets=False,
                         excl_contra=None,
                         excl_interco=False,
                         with_tags=None,
                         excl_tags=None):

        path_accts = dict(
            (p, [x['id'] for x in api_func('gl', 'path_accounts', p)])
            for p in paths)
        acct_list = list(itertools.chain(*[path_accts[p] for p in paths]))

        dates_dict = dict(
            (dt, utils.get_dates_dict(dates[dt])) for dt in dates)
        date_indexed_account_balances = self.gl_strategy.account_balances_for_dates(
            company_id, acct_list, dates_dict, None, excl_interco, excl_contra,
            with_tags, excl_tags)

        data = {}
        for dt in date_indexed_account_balances:
            account_balances = date_indexed_account_balances[dt]

            tuples = []
            for path in paths:
                path_sum = 0
                for account_id in path_accts[path]:
                    if account_id in account_balances:
                        path_sum -= account_balances[account_id]
                tuples.append((path, path_sum))

            data[dt] = dict(tuples)

        output = pd.DataFrame(data)

        if filter_zeros:
            output['empty'] = output.apply(
                lambda row: np.all(row.values == 0.0), axis=1)
            output = output[output['empty'] == False]
            output.drop('empty', axis=1, inplace=True)

        # adjust assets sign
        if assets:
            asset_factor = output.index.map(lambda x: -1.0
                                            if x[:6] == 'assets' else 1.0)
            for col in output.columns:
                output[col] = output[col] * asset_factor
        return output
예제 #4
0
    def pd_acct_balances(self,
                         company_id,
                         dates,
                         paths=None,
                         acct_list=None,
                         excl_contra=None,
                         excl_interco=False,
                         cp=None,
                         with_tags=None,
                         excl_tags=None):

        if not acct_list:
            if paths:
                accts = list(
                    itertools.chain(
                        *[api_func('gl', 'path_accounts', p) for p in paths]))
                acct_list = [x['id'] for x in accts]
            else:
                acct_list = [
                    x['id'] for x in api_func('gl', 'path_accounts', '')
                ]

        dates_dict = dict(
            (dt, utils.get_dates_dict(dates[dt])) for dt in dates)

        with_counterparties = [cp.id] if cp else None
        date_indexed_account_balances = self.gl_strategy.account_balances_for_dates(
            company_id, acct_list, dates_dict, with_counterparties,
            excl_interco, excl_contra, with_tags, excl_tags)

        # filter empties
        for dt in date_indexed_account_balances:
            d = date_indexed_account_balances[dt]
            date_indexed_account_balances[dt] = {
                k: d[k]
                for k in d if d[k] != 0.0
            }

        output = pd.DataFrame(date_indexed_account_balances)

        if paths:
            a = [[x['id'] for x in api_func('gl', 'path_accounts', path)]
                 for path in paths]
            accts_list = list(itertools.chain(*a))
            return output[output.index.isin(acct_list)]
        elif acct_list:
            filtered_output = output[output.index.isin(acct_list)]
            return filtered_output

        return output