示例#1
0
def test_portfolio_balance(account_checking, account_savings, account_sp500,
                           asset_krw, asset_sp500):
    """Ensures a portfolio, which is essentially a collection of accounts,
    calculates its balance correctly.
    """
    portfolio = Portfolio()
    portfolio.base_asset = asset_krw
    portfolio.add_accounts(account_checking, account_savings, account_sp500)

    assert portfolio.balance(parse_date('2016-05-20')) == {}

    deposit(account_checking, asset_krw, 1500, parse_date('2016-05-01'))
    deposit(account_savings, asset_krw, 3000, parse_date('2016-05-01'))
    deposit(account_sp500, asset_sp500, 120, parse_date('2016-05-01'))

    assert portfolio.balance(parse_date('2016-05-20')) \
        == {asset_krw: 4500, asset_sp500: 120}

    deposit(account_savings, asset_krw, 4000, parse_date('2016-05-02'))
    deposit(account_savings, asset_krw, 5000, parse_date('2016-05-03'))

    assert portfolio.balance(parse_date('2016-05-20')) \
        == {asset_krw: 13500, asset_sp500: 120}

    balance_adjustment(account_savings, asset_krw, 10000,
                       parse_date('2016-05-04'))

    assert portfolio.balance(parse_date('2016-05-20')) \
        == {asset_krw: 11500, asset_sp500: 120}

    db.session.delete(portfolio)
    db.session.commit()
示例#2
0
def test_portfolio_balance(account_checking, account_savings, account_sp500,
                           asset_krw, asset_sp500):
    portfolio = Portfolio()
    portfolio.base_asset = asset_krw
    portfolio.add_accounts(account_checking, account_savings, account_sp500)

    assert portfolio.balance(parse_date('2016-05-20')) == {}

    Record.create(created_at=parse_date('2016-05-01'),
                  account=account_checking,
                  asset=asset_krw,
                  quantity=1500)
    Record.create(created_at=parse_date('2016-05-01'),
                  account=account_savings,
                  asset=asset_krw,
                  quantity=3000)
    Record.create(created_at=parse_date('2016-05-01'),
                  account=account_sp500,
                  asset=asset_sp500,
                  quantity=120)

    assert portfolio.balance(parse_date('2016-05-20')) \
        == {asset_krw: 4500, asset_sp500: 120}

    Record.create(created_at=parse_date('2016-05-02'),
                  account=account_savings,
                  asset=asset_krw,
                  quantity=4000)
    Record.create(created_at=parse_date('2016-05-03'),
                  account=account_savings,
                  asset=asset_krw,
                  quantity=5000)

    assert portfolio.balance(parse_date('2016-05-20')) \
        == {asset_krw: 13500, asset_sp500: 120}

    Record.create(created_at=parse_date('2016-05-04'),
                  account=account_savings,
                  asset=asset_krw,
                  quantity=10000,
                  type=RecordType.balance_adjustment)

    assert portfolio.balance(parse_date('2016-05-20')) \
        == {asset_krw: 11500, asset_sp500: 120}

    db.session.delete(portfolio)
    db.session.commit()
示例#3
0
def test_portfolio_balance(account_checking, account_savings, account_sp500,
                           asset_krw, asset_sp500):
    portfolio = Portfolio()
    portfolio.base_asset = asset_krw
    portfolio.add_accounts(account_checking, account_savings, account_sp500)

    assert portfolio.balance(parse_date('2016-05-20')) == {}

    Record.create(
        created_at=parse_date('2016-05-01'), account=account_checking,
        asset=asset_krw, quantity=1500)
    Record.create(
        created_at=parse_date('2016-05-01'), account=account_savings,
        asset=asset_krw, quantity=3000)
    Record.create(
        created_at=parse_date('2016-05-01'), account=account_sp500,
        asset=asset_sp500, quantity=120)

    assert portfolio.balance(parse_date('2016-05-20')) \
        == {asset_krw: 4500, asset_sp500: 120}

    Record.create(
        created_at=parse_date('2016-05-02'), account=account_savings,
        asset=asset_krw, quantity=4000)
    Record.create(
        created_at=parse_date('2016-05-03'), account=account_savings,
        asset=asset_krw, quantity=5000)

    assert portfolio.balance(parse_date('2016-05-20')) \
        == {asset_krw: 13500, asset_sp500: 120}

    Record.create(
        created_at=parse_date('2016-05-04'), account=account_savings,
        asset=asset_krw, quantity=10000, type=RecordType.balance_adjustment)

    assert portfolio.balance(parse_date('2016-05-20')) \
        == {asset_krw: 11500, asset_sp500: 120}

    db.session.delete(portfolio)
    db.session.commit()