예제 #1
0
def _calculate_current_cost(holding, today):
    """Calculates current cost of a holding (in a local currency)."""

    rate_archive = RateArchive()
    cur_rates = rate_archive.get_approx(holding["currency"], today)
    if cur_rates is not None:
        # TODO: bank interest
        holding["current_cost"] = holding["current_amount"] * cur_rates[1]
예제 #2
0
def _calculate_holding_info(holding, today):
    """Calculates various info about a holding."""

    _calculate_past_cost(holding, today)
    _calculate_rate_profit(holding, today)
    _calculate_current_amount(holding, today)
    _calculate_current_cost(holding, today)
    _calculate_pure_profit(holding, today)


    rate_archive = RateArchive()

    for completion in holding.get("completions", []):
        if completion["date"] <= today:
            holding["amount"] += completion["amount"]

    cur_rates = rate_archive.get_approx(holding["currency"], today)
    if cur_rates is not None:
        holding["cost"] = holding["amount"] * cur_rates[1]