From da519ca2931470453367965b53137bc5ec922969 Mon Sep 17 00:00:00 2001 From: Sergey Kikevich Date: Tue, 12 Dec 2023 17:16:17 +0300 Subject: [PATCH] chore: update test group dependencies --- main.py | 22 ++++++++-------------- okama/asset_list.py | 3 +-- okama/macro.py | 2 +- pyproject.toml | 5 +++-- tests/test_macro.py | 18 ++++++++++-------- 5 files changed, 23 insertions(+), 27 deletions(-) diff --git a/main.py b/main.py index 823577a..153f5e4 100644 --- a/main.py +++ b/main.py @@ -1,17 +1,11 @@ import matplotlib.pyplot as plt import okama as ok -# indexes = ["RGBITR.INDX", "MCFTR.INDX", "GC.COMM"] -# ef = ok.EfficientFrontier(indexes, ccy="RUB", full_frontier=True, inflation=False, n_points=50) -# ef.plot_cml(rf_return=0.15, y_axe="cagr") -# plt.show() -# -# pf = ok.Portfolio(["SPY.US", "BND.US"], weights=[.5, .5], rebalancing_period="month") -# pf.wealth_index_with_assets.plot() -# plt.show() - -# al = ok.AssetList(["SBERP.MOEX", "LKOH.MOEX"], ccy='RUB') - -# print(al.get_mean_dividend_yield()) - -print(ok.Portfolio().dividend_yield) \ No newline at end of file +indexes = ["RGBITR.INDX", "MCFTR.INDX", "GC.COMM"] +ef = ok.EfficientFrontier(indexes, ccy="RUB", full_frontier=True, inflation=False, n_points=50) +ef.plot_cml(rf_return=0.15, y_axe="cagr") +plt.show() + +pf = ok.Portfolio(["SPY.US", "BND.US"], weights=[.5, .5], rebalancing_period="month") +pf.wealth_index_with_assets.plot() +plt.show() diff --git a/okama/asset_list.py b/okama/asset_list.py index b084ba7..8647610 100644 --- a/okama/asset_list.py +++ b/okama/asset_list.py @@ -994,7 +994,7 @@ def dividend_paying_years(self) -> pd.DataFrame: df = pd.concat([df, s2], axis=1, copy="false") return df - def get_dividend_mean_growth_rate(self, period: int=5) -> pd.Series: + def get_dividend_mean_growth_rate(self, period: int = 5) -> pd.Series: """ Calculate geometric mean of annual dividends growth rate time series for a given trailing period. @@ -1070,7 +1070,6 @@ def get_dividend_mean_yield(self, period: int = 5) -> pd.Series: dtype: float64 """ - self._validate_period(period) dt0 = self.last_date dt = helpers.Date.subtract_years(dt0, period) diff --git a/okama/macro.py b/okama/macro.py index 6952aca..a682b4e 100644 --- a/okama/macro.py +++ b/okama/macro.py @@ -98,7 +98,7 @@ def set_values_monthly(self, date: str, value: float): or corrected data. """ okama.common.validators.validate_real("value", value) - self._values_monthly[pd.Period(date, freq='M')] = value + self._values_monthly[pd.Period(date, freq="M")] = value self._set_first_last_dates() def describe(self, years: Tuple[int, ...] = (1, 5, 10)) -> pd.DataFrame: diff --git a/pyproject.toml b/pyproject.toml index 57ab36c..fb37c37 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,7 +29,7 @@ classifiers = [ [tool.poetry.dependencies] python = ">=3.9,<4.0.0" -pandas = "2.1.3" +pandas = "^2.0.0" scipy = "^1.9.0" matplotlib = "^3.5.1" requests = "<=2.31.0" # Windows has an issue with 2.32.0 @@ -40,8 +40,9 @@ optional = false [tool.poetry.group.test.dependencies] pytest = "^6.0.0" -black = "^23.11.0" +black = {extras = ["jupyter"], version = "^23.12.0"} pytest-xdist = "^3.5.0" +flake8 = "^6.1.0" [tool.poetry.group.docs] optional = true diff --git a/tests/test_macro.py b/tests/test_macro.py index f3b5458..6dac06f 100644 --- a/tests/test_macro.py +++ b/tests/test_macro.py @@ -70,17 +70,19 @@ def test_values_monthly(self): error_case_ids = ["invalid_date_format", "nonexistent_date", "invalid_value_type"] - @pytest.mark.parametrize("date, value", - [("2022-06", 100.0), ("2025-01", 200.0), (pd.Timestamp.now().strftime('%Y-%m'), 150.0), - ("2024-02", 300.0)]) + @pytest.mark.parametrize( + "date, value", + [("2022-06", 100.0), ("2025-01", 200.0), (pd.Timestamp.now().strftime("%Y-%m"), 150.0), ("2024-02", 300.0)], + ) def test_set_values_monthly_happy_path(self, date, value): # Arrange instance = MyClass() self.infl_rub.set_values_monthly(date, value) - assert self.infl_rub.values_monthly[pd.Period(date, freq='M')] == value + assert self.infl_rub.values_monthly[pd.Period(date, freq="M")] == value - @pytest.mark.parametrize("date, value, expected_exception", - [("12,2023", 100.0, ValueError), ("2023-13", 100.0, ValueError), - ("2023-12", "one hundred", TypeError)], - ids=error_case_ids) + @pytest.mark.parametrize( + "date, value, expected_exception", + [("12,2023", 100.0, ValueError), ("2023-13", 100.0, ValueError), ("2023-12", "one hundred", TypeError)], + ids=error_case_ids, + ) def test_set_values_monthly_error_cases(self, date, value, expected_exception): with pytest.raises(expected_exception): self.infl_rub.set_values_monthly(date, value)