From 66ccd2a3f89a630519f6c108baaf24c9613861f4 Mon Sep 17 00:00:00 2001 From: = <=> Date: Thu, 24 Feb 2022 11:28:16 +0530 Subject: [PATCH] added interval_to_years function --- fincal/core.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/fincal/core.py b/fincal/core.py index de53cb5..a6d1772 100644 --- a/fincal/core.py +++ b/fincal/core.py @@ -114,6 +114,18 @@ def _parse_date(date: str, date_format: str = None): return date +def _interval_to_years(interval_type: Literal['years', 'months', 'day'], interval_value: int) -> int: + """Converts any time period to years for use with compounding functions""" + + day_conversion_factor = { + 'years': 1, + 'months': 12, + 'days': 365 + } + years = interval_value/day_conversion_factor[interval_type] + return years + + class _IndexSlicer: """Class to create a slice using iloc in TimeSeriesCore"""