improved limit calculation
Added basic test for limit
This commit is contained in:
parent
60f25de710
commit
32e4f25f59
@ -266,6 +266,7 @@ class TimeSeries(TimeSeriesCore):
|
|||||||
|
|
||||||
prev_date = as_on - relativedelta(**{interval_type: interval_value})
|
prev_date = as_on - relativedelta(**{interval_type: interval_value})
|
||||||
current = _find_closest_date(self.data, as_on, closest_max_days, as_on_delta, if_not_found)
|
current = _find_closest_date(self.data, as_on, closest_max_days, as_on_delta, if_not_found)
|
||||||
|
if current[1] != str("nan"):
|
||||||
previous = _find_closest_date(self.data, prev_date, closest_max_days, prior_delta, if_not_found)
|
previous = _find_closest_date(self.data, prev_date, closest_max_days, prior_delta, if_not_found)
|
||||||
|
|
||||||
if current[1] == str("nan") or previous[1] == str("nan"):
|
if current[1] == str("nan") or previous[1] == str("nan"):
|
||||||
|
@ -233,3 +233,8 @@ class TestReturns:
|
|||||||
returns1 = ts.calculate_returns("2020-04-10", interval_type='days', interval_value=90, date_format='%Y-%m-%d')
|
returns1 = ts.calculate_returns("2020-04-10", interval_type='days', interval_value=90, date_format='%Y-%m-%d')
|
||||||
returns2 = ts.calculate_returns("04-10-2020", interval_type='days', interval_value=90)
|
returns2 = ts.calculate_returns("04-10-2020", interval_type='days', interval_value=90)
|
||||||
assert round(returns1[1], 4) == round(returns2[1], 4) == 5.727
|
assert round(returns1[1], 4) == round(returns2[1], 4) == 5.727
|
||||||
|
|
||||||
|
def test_limits(self):
|
||||||
|
ts = TimeSeries(self.data, frequency='M')
|
||||||
|
with pytest.raises(DateNotFoundError):
|
||||||
|
ts.calculate_returns("2020-04-25", interval_type='days', interval_value=90, closest_max_days=10)
|
||||||
|
Loading…
Reference in New Issue
Block a user