Skip to content

Commit

Permalink
test: update tests for new FX data format
Browse files Browse the repository at this point in the history
  • Loading branch information
chilango74 committed Aug 9, 2022
1 parent 805195a commit 8800429
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 105 deletions.
2 changes: 1 addition & 1 deletion okama/common/make_asset_list.py
Expand Up @@ -270,7 +270,7 @@ def _get_single_asset_dividends(self, tick: str, remove_forecast: bool = True) -

def _get_assets_dividends(self, remove_forecast=True) -> pd.DataFrame:
"""
Get monthly dividend time series for all assets.
Get monthly dividend time series for all assets. Dividend values are adjusted to base currency.
If `remove_forecast=True` all forecasted (future) data is removed from the time series.
"""
Expand Down
152 changes: 56 additions & 96 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Expand Up @@ -36,7 +36,7 @@ joblib = "^1.1.0"
[tool.poetry.dev-dependencies]
pytest = "^6.0.0"
jupyter = { version = "^1.0.0", optional = true }
ipykernel = { version = "^6.13.0", optional = true }
ipykernel = { version = "^6.15.0", optional = true }
black = {extras = ["jupyter"], version = "^22.3.0"}
#sphinx dependencies
sphinx = { version = "^3", optional = true }
Expand Down
Binary file modified tests/data/asset_list_describe.pkl
Binary file not shown.
4 changes: 2 additions & 2 deletions tests/test_asset_list.py
Expand Up @@ -65,9 +65,9 @@ def test_currencies(self):
"asset list": "USD",
}
assert self.currencies.names == {
"RUBUSD.FX": "RUBUSD",
"RUBUSD.FX": "Russian Rouble/US Dollar FX Cross Rate",
"EURUSD.FX": "EURUSD",
"CNYUSD.FX": "CNYUSD",
"CNYUSD.FX": "Chinese Renminbi/US Dollar FX Cross Rate",
}
assert self.currencies.describe().iloc[1, -1] == approx(0.02485, rel=1e-2)

Expand Down
11 changes: 6 additions & 5 deletions tests/test_portfolio.py
Expand Up @@ -111,21 +111,22 @@ def test_close_monthly(portfolio_not_rebalanced):

def test_get_assets_dividends(portfolio_dividends):
assert portfolio_dividends._get_assets_dividends().iloc[-1, 0] == approx(0, abs=1e-2)
assert portfolio_dividends._get_assets_dividends().iloc[-1, 1] == approx(32.77, rel=1e-2) # T.US 2020-01
# T.US 2020-01=$0.3927 , RUBUSD=63.03 ( http://joxi.ru/823dnYWizBvEOA )
assert portfolio_dividends._get_assets_dividends().iloc[-1, 1] == approx(24.75, rel=1e-2)
assert portfolio_dividends._get_assets_dividends().iloc[-1, 2] == approx(0, rel=1e-2)


def test_number_of_securities(portfolio_not_rebalanced, portfolio_dividends):
assert portfolio_not_rebalanced.number_of_securities.iloc[-1, 0] == approx(8.88, rel=1e-2) # RUB.FX
assert portfolio_not_rebalanced.number_of_securities.iloc[-1, 1] == approx(0.2787, abs=1e-2) # MCFTR.INDX
# with dividends
assert portfolio_dividends.number_of_securities.iloc[-1, 0] == approx(3.90, rel=1e-2) # SBER.MOEX
assert portfolio_dividends.number_of_securities.iloc[-1, 1] == approx(0.41, abs=1e-2) # T.US
assert portfolio_dividends.number_of_securities.iloc[-1, 2] == approx(0.38, abs=1e-2) # GNS.LSE
assert portfolio_dividends.number_of_securities.iloc[-1, 0] == approx(3.97, rel=1e-2) # SBER.MOEX
assert portfolio_dividends.number_of_securities.iloc[-1, 1] == approx(0.425, abs=1e-2) # T.US
assert portfolio_dividends.number_of_securities.iloc[-1, 2] == approx(0.392, abs=1e-2) # GNS.LSE


def test_dividends(portfolio_dividends):
assert portfolio_dividends.dividends.iloc[-1] == approx(13.71, rel=1e-2)
assert portfolio_dividends.dividends.iloc[-1] == approx(10.54, rel=1e-2)


def test_dividend_yield(portfolio_dividends):
Expand Down

0 comments on commit 8800429

Please sign in to comment.