From b5aa5d22d457d8705895465b5c5f0d20d6d18457 Mon Sep 17 00:00:00 2001 From: Gourav Kumar Date: Mon, 4 Apr 2022 00:48:55 +0530 Subject: [PATCH] Added tests for expand --- tests/test_fincal.py | 54 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/tests/test_fincal.py b/tests/test_fincal.py index f5f4aeb..8aab63a 100644 --- a/tests/test_fincal.py +++ b/tests/test_fincal.py @@ -298,6 +298,60 @@ class TestReturns: with pytest.raises(DateNotFoundError): ts.calculate_returns("2020-11-25", return_period_unit="days", return_period_value=90, closest_max_days=10) + def test_rolling_returns(self): + # Yet to be written + return True + + +class TestExpand: + def test_weekly_to_daily(self): + ts_data = create_test_data(AllFrequencies.W, 10) + ts = TimeSeries(ts_data, "W") + expanded_ts = ts.expand("D", "ffill") + assert len(expanded_ts) == 64 + assert expanded_ts.frequency.name == "daily" + assert expanded_ts.iloc[0][1] == expanded_ts.iloc[1][1] + + def test_weekly_to_daily_no_weekends(self): + ts_data = create_test_data(AllFrequencies.W, 10) + ts = TimeSeries(ts_data, "W") + expanded_ts = ts.expand("D", "ffill", skip_weekends=True) + assert len(expanded_ts) == 45 + assert expanded_ts.frequency.name == "daily" + assert expanded_ts.iloc[0][1] == expanded_ts.iloc[1][1] + + def test_monthly_to_daily(self): + ts_data = create_test_data(AllFrequencies.M, 6) + ts = TimeSeries(ts_data, "M") + expanded_ts = ts.expand("D", "ffill") + assert len(expanded_ts) == 152 + assert expanded_ts.frequency.name == "daily" + assert expanded_ts.iloc[0][1] == expanded_ts.iloc[1][1] + + def test_monthly_to_daily_no_weekends(self): + ts_data = create_test_data(AllFrequencies.M, 6) + ts = TimeSeries(ts_data, "M") + expanded_ts = ts.expand("D", "ffill", skip_weekends=True) + assert len(expanded_ts) == 109 + assert expanded_ts.frequency.name == "daily" + assert expanded_ts.iloc[0][1] == expanded_ts.iloc[1][1] + + def test_monthly_to_weekly(self): + ts_data = create_test_data(AllFrequencies.M, 6) + ts = TimeSeries(ts_data, "M") + expanded_ts = ts.expand("W", "ffill") + assert len(expanded_ts) == 22 + assert expanded_ts.frequency.name == "weekly" + assert expanded_ts.iloc[0][1] == expanded_ts.iloc[1][1] + + def test_yearly_to_monthly(self): + ts_data = create_test_data(AllFrequencies.Y, 5) + ts = TimeSeries(ts_data, "Y") + expanded_ts = ts.expand("M", "ffill") + assert len(expanded_ts) == 49 + assert expanded_ts.frequency.name == "monthly" + assert expanded_ts.iloc[0][1] == expanded_ts.iloc[1][1] + class TestReturnsAgain: data = [