Browse Source

corrected return calc test, writing sortino tests

find_closest_changes
Gourav Kumar 2 years ago
parent
commit
c4e1d8b586
  1. 4
      tests/test_pyfacts.py
  2. 22
      tests/test_stats.py

4
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)

22
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,

Loading…
Cancel
Save