Skip to content

Commit

Permalink
chore: update test group dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
chilango74 committed Dec 12, 2023
1 parent 6bbeda4 commit da519ca
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 27 deletions.
22 changes: 8 additions & 14 deletions main.py
Original file line number Diff line number Diff line change
@@ -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)
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()
3 changes: 1 addition & 2 deletions okama/asset_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion okama/macro.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
18 changes: 10 additions & 8 deletions tests/test_macro.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit da519ca

Please sign in to comment.