Exemplo n.º 1
0
    def test_from_amounts(self):
        pos = from_amounts(A('10.00 USD'))
        self.assertEqual(Position(A("10 USD")), pos)

        pos = from_amounts(A('10 HOOL'), A('510.00 USD'))
        self.assertEqual(
            Position(A("10 HOOL"), Cost(D('510'), 'USD', None, None)), pos)
Exemplo n.º 2
0
    def test_from_amounts(self):
        pos = from_amounts(A('10.00 USD'))
        self.assertEqual(Position(Lot("USD", None, None), D('10')), pos)

        pos = from_amounts(A('10 HOOL'), A('510.00 USD'))
        self.assertEqual(Position(Lot("HOOL", A('510 USD'), None), D('10')),
                         pos)
Exemplo n.º 3
0
def get_position_market_value(position_, date, price_map):
    """Compute the market value of the position at a particular date.

    If the price map does not contain price information, we avoid converting the
    position and return itself, unchanged.

    Args:
      position: An instance of Position
      date: A datetime.date instance, the date at which to market the instruments.
        If the date provided is None, the inventory is valued at the latest market
        prices.
      price_map: A price map, as created by beancount.ops.prices.
    Returns:
      An inventory of market values per currency.

    """
    lot = position_.lot
    cost_currency = lot.cost.currency if lot.cost else None
    if cost_currency:
        base_quote = (lot.currency, cost_currency)
        price_date, price_number = get_price(price_map, base_quote, date)
        if price_number is None:
            return position_
        else:
            new_amount = amount.Amount(position_.number * price_number,
                                       cost_currency)
    else:
        new_amount = amount.Amount(position_.number, lot.currency)
    return position.from_amounts(new_amount)