def holdings(self, aggregation_key=None): holdings_list = get_final_holdings( self.entries, (self.account_types.assets, self.account_types.liabilities), self.price_map, self.date_last ) if aggregation_key: holdings_list = aggregate_holdings_by(holdings_list, aggregation_key) return holdings_list
def test_holdings_zero_position(load_doc): """ 2012-07-02 ! "I received 1 new share in dividend, without paying" Assets:Stocks:NYA 1 NYA {0 EUR} Income:Dividends:NYA -0 EUR 2014-11-13 balance Assets:Stocks:NYA 1 NYA """ entries, _, _ = load_doc price_map = prices.build_price_map(entries) holdings = get_final_holdings(entries, ('Assets', 'Liabilities'), price_map) assert len(holdings) == 1 assert holdings[0].cost.currency == 'EUR'
def test_holdings_with_prices(load_doc): """ 2013-04-05 * Equity:Unknown Assets:Cash 50000 USD 2013-04-01 * Assets:Account1 15 HOOL {518.73 USD} Assets:Cash 2013-06-01 price HOOL 578.02 USD """ entries, _, _ = load_doc price_map = prices.build_price_map(entries) holdings = get_final_holdings(entries, ('Assets'), price_map) holdings = sorted(map(tuple, holdings)) assert holdings == [ ('Assets:Account1', A('15 HOOL'), Cost(D('518.73'), 'USD', None, None), D('578.02'), None, None), ('Assets:Cash', A('42219.05 USD'), None, None, None, None), ]
def test_get_final_holdings(load_doc): """ 2013-04-05 * Equity:Unknown Assets:Cash 50000 USD 2013-04-01 * Assets:Account1 15 HOOL {518.73 USD} Assets:Cash 2013-04-02 * Assets:Account1 10 HOOL {523.46 USD} Assets:Cash 2013-04-03 * Assets:Account1 -4 HOOL {518.73 USD} Assets:Cash 2013-04-02 * Assets:Account2 20 ITOT {85.195 USD} Assets:Cash 2013-04-03 * Assets:Account3 50 HOOL {540.00 USD} @ 560.00 USD Assets:Cash 2013-04-10 * Assets:Cash 5111 USD Liabilities:Loan """ entries, _, _ = load_doc holdings = get_final_holdings(entries) holdings = sorted(map(tuple, holdings)) assert holdings == [ ('Assets:Account1', A('10 HOOL'), Cost(D('523.46'), 'USD', None, None), None, None, None), ('Assets:Account1', A('11 HOOL'), Cost(D('518.73'), 'USD', None, None), None, None, None), ('Assets:Account2', A('20 ITOT'), Cost(D('85.195'), 'USD', None, None), None, None, None), ('Assets:Account3', A('50 HOOL'), Cost(D('540.00'), 'USD', None, None), None, None, None), ('Assets:Cash', A('15466.470 USD'), None, None, None, None), ('Equity:Unknown', A('-50000 USD'), None, None, None, None), ('Liabilities:Loan', A('-5111 USD'), None, None, None, None), ] holdings = get_final_holdings(entries, ('Assets')) holdings = sorted(map(tuple, holdings)) assert holdings == [ ('Assets:Account1', A('10 HOOL'), Cost(D('523.46'), 'USD', None, None), None, None, None), ('Assets:Account1', A('11 HOOL'), Cost(D('518.73'), 'USD', None, None), None, None, None), ('Assets:Account2', A('20 ITOT'), Cost(D('85.195'), 'USD', None, None), None, None, None), ('Assets:Account3', A('50 HOOL'), Cost(D('540.00'), 'USD', None, None), None, None, None), ('Assets:Cash', A('15466.470 USD'), None, None, None, None), ]