Browse Source

type hints and docs

find_closest_changes
Gourav Kumar 2 years ago
parent
commit
583ca98e51
  1. 28
      pyfacts/pyfacts.py

28
pyfacts/pyfacts.py

@ -262,7 +262,7 @@ class TimeSeries(TimeSeriesCore):
return_period_unit: Literal["years", "months", "days"] = "years",
return_period_value: int = 1,
date_format: str = None,
) -> float:
) -> Tuple[datetime.datetime, float]:
"""Method to calculate returns for a certain time-period as on a particular date
Parameters
@ -295,7 +295,7 @@ class TimeSeries(TimeSeriesCore):
* fail: Raise a ValueError
* nan: Return nan as the value
compounding : bool, optional
annual_compounded_returns : bool, optional
Whether the return should be compounded annually.
return_period_unit : 'years', 'months', 'days'
@ -321,14 +321,14 @@ class TimeSeries(TimeSeriesCore):
Example
--------
>>> calculate_returns(datetime.date(2020, 1, 1), years=1)
>>> ts.calculate_returns(datetime.date(2020, 1, 1), years=1)
(datetime.datetime(2020, 1, 1, 0, 0), .0567)
"""
as_on_delta, prior_delta = _preprocess_match_options(as_on_match, prior_match, closest)
prev_date = as_on - relativedelta(**{return_period_unit: return_period_value})
current = _find_closest_date(self.data, as_on, closest_max_days, as_on_delta, if_not_found)
prev_date = as_on - relativedelta(**{return_period_unit: return_period_value})
if current[1] != str("nan"):
previous = _find_closest_date(self.data, prev_date, closest_max_days, prior_delta, if_not_found)
@ -368,16 +368,16 @@ class TimeSeries(TimeSeriesCore):
End date for the returns calculation.
frequency : str, optional
Frequency at which the returns should be calcualated.
Frequency at which the returns should be calculated.
Valid values are {D, W, M, Q, H, Y}
as_on_match : str, optional
The match mode to be used for the as on date.
If not specified, the value for the closes parameter will be used.
If not specified, the value for the closest parameter will be used.
prior_match : str, optional
The match mode to be used for the prior date, i.e., the date against which the return will be calculated.
If not specified, the value for the closes parameter will be used.
If not specified, the value for the closest parameter will be used.
closest : previous | next | exact
The default match mode for dates.
@ -395,7 +395,7 @@ class TimeSeries(TimeSeriesCore):
For instance, if the input date is before the starting of the first date of the time series,
but match mode is set to previous. A DateOutOfRangeError will be raised in such cases.
compounding : bool, optional
annual_compounded_returns : bool, optional
Should the returns be compounded annually.
return_period_unit : years | month | days
@ -410,7 +410,7 @@ class TimeSeries(TimeSeriesCore):
Returns
-------
Returs the rolling returns as a TimeSeries object.
Returns the rolling returns as a TimeSeries object.
Raises
------
@ -431,7 +431,7 @@ class TimeSeries(TimeSeriesCore):
raise ValueError(f"Invalid argument for frequency {frequency}")
if from_date is None:
from_date = self.start_date + relativedelta(
days=int(_interval_to_years(return_period_unit, return_period_value) * 365 + 1)
days=math.ceil(_interval_to_years(return_period_unit, return_period_value) * 365)
)
if to_date is None:
@ -476,7 +476,7 @@ class TimeSeries(TimeSeriesCore):
) -> float:
"""Calculates the volatility of the time series.add()
The volatility is calculated as the standard deviaion of periodic returns.
The volatility is calculated as the standard deviation of periodic returns.
The periodicity of returns is based on the periodicity of underlying data.
Parameters:
@ -761,10 +761,10 @@ class TimeSeries(TimeSeriesCore):
Parameters:
-----------
other: TimeSeries
Another object of TimeSeries class whose dates need to be syncronized
Another object of TimeSeries class whose dates need to be synchronized
fill_method: ffill | bfill, default ffill
Method to use to fill missing values in time series when syncronizing
Method to use to fill missing values in time series when synchronizing
Returns:
--------
@ -903,7 +903,7 @@ def read_csv(
header = data[read_start_row]
print(header)
# fmt: off
# Black and pylance disagree on the foratting of the following line, hence formatting is disabled
# Black and pylance disagree on the formatting of the following line, hence formatting is disabled
data = data[(read_start_row + 1):read_end_row]
# fmt: on

Loading…
Cancel
Save