Skip to content

Commit

Permalink
naming series
Browse files Browse the repository at this point in the history
  • Loading branch information
tschm committed Dec 20, 2023
1 parent 15d0873 commit 034a9f9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
3 changes: 2 additions & 1 deletion tests/test_applications/test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,6 @@ def test_case(columns, index, prices):
# )
# nav is the net asset value equity and cash, 1) 2000 2) 2000 3) 2000 4) 1000
pd.testing.assert_series_equal(
portfolio.nav, pd.Series(index=index, data=[2000.0, 2000.0, 2000.0, 1000.0])
portfolio.nav,
pd.Series(index=index, data=[2000.0, 2000.0, 2000.0, 1000.0], name="NAV"),
)
8 changes: 6 additions & 2 deletions tests/test_applications/test_portfolio.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ def test_from_cash_position_prices(prices):
)

profit = (portfolio.cashposition.shift(1) * portfolio.returns).sum(axis=1)
pd.testing.assert_series_equal(portfolio.nav, profit.cumsum() + portfolio.aum)
pd.testing.assert_series_equal(
portfolio.nav, profit.cumsum() + portfolio.aum, check_names=False
)


def test_from_cash_returns(prices):
Expand All @@ -46,4 +48,6 @@ def test_from_cash_returns(prices):
)

profit = (portfolio.cashposition.shift(1) * portfolio.returns).sum(axis=1)
pd.testing.assert_series_equal(portfolio.nav, profit.cumsum() + portfolio.aum)
pd.testing.assert_series_equal(
portfolio.nav, profit.cumsum() + portfolio.aum, check_names=False
)
2 changes: 1 addition & 1 deletion tests/test_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def test_build_empty(builder, prices):
pd.testing.assert_frame_equal(portfolio.prices, prices)
pd.testing.assert_frame_equal(portfolio.units, np.NaN * prices)
pd.testing.assert_series_equal(
portfolio.profit, pd.Series(index=prices.index, data=0.0)
portfolio.profit, pd.Series(index=prices.index, data=0.0, name="Profit")
)


Expand Down
18 changes: 7 additions & 11 deletions tests/test_portfolio.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,6 @@ def portfolio(prices, nav):

return Portfolio(prices=prices, units=units, aum=nav)

# positions = pd.DataFrame(index=prices.index, columns=prices.columns, data=1.0)
# b = EquityBuilder(prices, initial_cash=1e6)

# for t, state in b:
# b.position = positions.loc[t[-1]]

# return b.build()


def test_assets(portfolio, prices):
"""
Expand Down Expand Up @@ -107,11 +99,13 @@ def test_drawdown(portfolio):
:param portfolio: the portfolio object (fixture)
"""
pd.testing.assert_series_equal(
portfolio.highwater, portfolio.nav.expanding(min_periods=1).max()
portfolio.highwater,
portfolio.nav.expanding(min_periods=1).max(),
check_names=False,
)

drawdown = 1.0 - portfolio.nav / portfolio.highwater
pd.testing.assert_series_equal(portfolio.drawdown, drawdown)
pd.testing.assert_series_equal(portfolio.drawdown, drawdown, check_names=False)


def test_monotonic():
Expand Down Expand Up @@ -176,7 +170,9 @@ def test_profit(portfolio):
:param portfolio: the portfolio object (fixture)
"""
pd.testing.assert_series_equal(
portfolio.profit, portfolio.equity.sum(axis=1).diff().fillna(0.0)
portfolio.profit,
portfolio.equity.sum(axis=1).diff().fillna(0.0),
check_names=False,
)


Expand Down

0 comments on commit 034a9f9

Please sign in to comment.