def test_portfolio(account_hf, asset_hf1, account_checking, asset_krw): portfolio = Portfolio() portfolio.base_asset = asset_krw portfolio.add_accounts(account_hf, account_checking) deposit(account_checking, asset_krw, 500000, parse_date("2015-12-04")) with Transaction.create() as t: deposit(account_checking, asset_krw, -500000, parse_date("2015-12-04"), t) deposit(account_hf, asset_hf1, 1, parse_date("2015-12-04"), t) # The net asset value shall not be available at this point with pytest.raises(AssetValueUnavailableException): net_worth = portfolio.net_worth(evaluated_at=parse_date("2015-12-04"), granularity=Granularity.day) # Initial asset value AssetValue.create( evaluated_at=parse_date("2015-12-04"), asset=asset_hf1, base_asset=asset_krw, granularity=Granularity.day, close=500000, ) net_worth = portfolio.net_worth(evaluated_at=parse_date("2015-12-04"), granularity=Granularity.day) assert 500000 == net_worth # 1st payment interest, tax, returned = 3923, 740, 30930 deposit(account_checking, asset_krw, returned, parse_date("2016-01-08")) # Remaining principle value after the 1st payment AssetValue.create( evaluated_at=parse_date("2016-01-08"), asset=asset_hf1, base_asset=asset_krw, granularity=Granularity.day, close=472253, ) net_worth = portfolio.net_worth(evaluated_at=parse_date("2016-01-08"), granularity=Granularity.day) assert 500000 + (interest - tax) == net_worth # 2nd payment deposit(account_checking, asset_krw, 25016, parse_date("2016-02-05")) # Remaining principle value after the 2nd payment AssetValue.create( evaluated_at=parse_date("2016-02-05"), asset=asset_hf1, base_asset=asset_krw, granularity=Granularity.day, close=450195, ) db.session.delete(portfolio) db.session.commit()
def test_portfolio(account_hf, asset_hf1, account_checking, asset_krw): portfolio = Portfolio() portfolio.base_asset = asset_krw portfolio.add_accounts(account_hf, account_checking) with Transaction.create() as t: Record.create( created_at=parse_date('2015-12-04'), transaction=t, account=account_checking, asset=asset_krw, quantity=500000) Record.create( created_at=parse_date('2015-12-04'), transaction=t, account=account_checking, asset=asset_krw, quantity=-500000) Record.create( created_at=parse_date('2015-12-04'), transaction=t, account=account_hf, asset=asset_hf1, quantity=1) # The net asset value shall not be available at this point with pytest.raises(AssetValueUnavailableException): net_worth = portfolio.net_worth(evaluated_at=parse_date('2015-12-04'), granularity=Granularity.day) # Initial asset value AssetValue.create( evaluated_at=parse_date('2015-12-04'), asset=asset_hf1, base_asset=asset_krw, granularity=Granularity.day, close=500000) net_worth = portfolio.net_worth(evaluated_at=parse_date('2015-12-04'), granularity=Granularity.day) assert 500000 == net_worth # 1st payment interest, tax, returned = 3923, 740, 30930 with Transaction.create() as t: Record.create( created_at=parse_date('2016-01-08'), transaction=t, account=account_checking, asset=asset_krw, quantity=returned) # Remaining principle value after the 1st payment AssetValue.create( evaluated_at=parse_date('2016-01-08'), asset=asset_hf1, base_asset=asset_krw, granularity=Granularity.day, close=472253) net_worth = portfolio.net_worth(evaluated_at=parse_date('2016-01-08'), granularity=Granularity.day) assert 500000 + (interest - tax) == net_worth # 2nd payment with Transaction.create() as t: Record.create( created_at=parse_date('2016-02-05'), transaction=t, account=account_checking, asset=asset_krw, quantity=25016) # Remaining principle value after the 2nd payment AssetValue.create( evaluated_at=parse_date('2016-02-05'), asset=asset_hf1, base_asset=asset_krw, granularity=Granularity.day, close=450195) db.session.delete(portfolio) db.session.commit()
def test_portfolio(account_hf, asset_hf1, account_checking, asset_krw): portfolio = Portfolio() portfolio.base_asset = asset_krw portfolio.add_accounts(account_hf, account_checking) with Transaction.create() as t: Record.create(created_at=parse_date('2015-12-04'), transaction=t, account=account_checking, asset=asset_krw, quantity=500000) Record.create(created_at=parse_date('2015-12-04'), transaction=t, account=account_checking, asset=asset_krw, quantity=-500000) Record.create(created_at=parse_date('2015-12-04'), transaction=t, account=account_hf, asset=asset_hf1, quantity=1) # The net asset value shall not be available at this point with pytest.raises(AssetValueUnavailableException): net_worth = portfolio.net_worth(evaluated_at=parse_date('2015-12-04'), granularity=Granularity.day) # Initial asset value AssetValue.create(evaluated_at=parse_date('2015-12-04'), asset=asset_hf1, base_asset=asset_krw, granularity=Granularity.day, close=500000) net_worth = portfolio.net_worth(evaluated_at=parse_date('2015-12-04'), granularity=Granularity.day) assert 500000 == net_worth # 1st payment interest, tax, returned = 3923, 740, 30930 with Transaction.create() as t: Record.create(created_at=parse_date('2016-01-08'), transaction=t, account=account_checking, asset=asset_krw, quantity=returned) # Remaining principle value after the 1st payment AssetValue.create(evaluated_at=parse_date('2016-01-08'), asset=asset_hf1, base_asset=asset_krw, granularity=Granularity.day, close=472253) net_worth = portfolio.net_worth(evaluated_at=parse_date('2016-01-08'), granularity=Granularity.day) assert 500000 + (interest - tax) == net_worth # 2nd payment with Transaction.create() as t: Record.create(created_at=parse_date('2016-02-05'), transaction=t, account=account_checking, asset=asset_krw, quantity=25016) # Remaining principle value after the 2nd payment AssetValue.create(evaluated_at=parse_date('2016-02-05'), asset=asset_hf1, base_asset=asset_krw, granularity=Granularity.day, close=450195) db.session.delete(portfolio) db.session.commit()