corrected return calc test, writing sortino tests

This commit is contained in:
Gourav Kumar 2022-07-24 08:48:03 +05:30
parent db8377f0ef
commit c4e1d8b586
2 changed files with 12 additions and 14 deletions

View File

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

View File

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