From c4e1d8b58687abf48a387558a23bdf379695fb44 Mon Sep 17 00:00:00 2001 From: Gourav Kumar Date: Sun, 24 Jul 2022 08:48:03 +0530 Subject: [PATCH] corrected return calc test, writing sortino tests --- tests/test_pyfacts.py | 4 ++-- tests/test_stats.py | 22 ++++++++++------------ 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/tests/test_pyfacts.py b/tests/test_pyfacts.py index f5fe63a..b06fd9b 100644 --- a/tests/test_pyfacts.py +++ b/tests/test_pyfacts.py @@ -3,8 +3,8 @@ import datetime import pytest from pyfacts import ( AllFrequencies, - PyfactsOptions, Frequency, + PyfactsOptions, TimeSeries, create_date_series, ) @@ -248,7 +248,7 @@ class TestReturns: with pytest.raises(DateNotFoundError): ts.calculate_returns("2020-04-04", return_period_unit="days", return_period_value=90, as_on_match="exact") with pytest.raises(DateNotFoundError): - ts.calculate_returns("2020-04-04", return_period_unit="months", return_period_value=3, prior_match="exact") + ts.calculate_returns("2020-04-08", return_period_unit="months", return_period_value=1, prior_match="exact") def test_date_formats(self, create_test_data): ts_data = create_test_data(AllFrequencies.D, skip_weekends=True) diff --git a/tests/test_stats.py b/tests/test_stats.py index 70a9b47..27be677 100644 --- a/tests/test_stats.py +++ b/tests/test_stats.py @@ -106,18 +106,16 @@ class TestSortino: ) assert round(sortino_ratio, 4) == 1.2564 - # def test_sharpe_weekly_freq(self, create_test_data): - # data = create_test_data(num=261, frequency=pft.AllFrequencies.W, mu=0.6, sigma=0.7) - # ts = pft.TimeSeries(data, "W") - # sharpe_ratio = pft.sharpe_ratio( - # ts, - # risk_free_rate=0.052, - # from_date="2017-01-08", - # to_date="2021-12-31", - # return_period_unit="days", - # return_period_value=7, - # ) - # assert round(sharpe_ratio, 4) == 0.4533 + def test_sortino_weekly_freq(self, create_test_data): + data = create_test_data(num=500, frequency=pft.AllFrequencies.W, mu=0.12, sigma=0.06) + ts = pft.TimeSeries(data, "W") + sortino = pft.sortino_ratio( + ts, + risk_free_rate=0.06, + return_period_unit="years", + return_period_value=1, + ) + assert round(sortino, 4) == -5.5233 # sharpe_ratio = pft.sharpe_ratio( # ts,