type hints and docs
This commit is contained in:
parent
b1305ca89d
commit
583ca98e51
@ -262,7 +262,7 @@ class TimeSeries(TimeSeriesCore):
|
|||||||
return_period_unit: Literal["years", "months", "days"] = "years",
|
return_period_unit: Literal["years", "months", "days"] = "years",
|
||||||
return_period_value: int = 1,
|
return_period_value: int = 1,
|
||||||
date_format: str = None,
|
date_format: str = None,
|
||||||
) -> float:
|
) -> Tuple[datetime.datetime, float]:
|
||||||
"""Method to calculate returns for a certain time-period as on a particular date
|
"""Method to calculate returns for a certain time-period as on a particular date
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
@ -295,7 +295,7 @@ class TimeSeries(TimeSeriesCore):
|
|||||||
* fail: Raise a ValueError
|
* fail: Raise a ValueError
|
||||||
* nan: Return nan as the value
|
* nan: Return nan as the value
|
||||||
|
|
||||||
compounding : bool, optional
|
annual_compounded_returns : bool, optional
|
||||||
Whether the return should be compounded annually.
|
Whether the return should be compounded annually.
|
||||||
|
|
||||||
return_period_unit : 'years', 'months', 'days'
|
return_period_unit : 'years', 'months', 'days'
|
||||||
@ -321,14 +321,14 @@ class TimeSeries(TimeSeriesCore):
|
|||||||
|
|
||||||
Example
|
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)
|
(datetime.datetime(2020, 1, 1, 0, 0), .0567)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
as_on_delta, prior_delta = _preprocess_match_options(as_on_match, prior_match, closest)
|
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)
|
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"):
|
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)
|
||||||
|
|
||||||
@ -368,16 +368,16 @@ class TimeSeries(TimeSeriesCore):
|
|||||||
End date for the returns calculation.
|
End date for the returns calculation.
|
||||||
|
|
||||||
frequency : str, optional
|
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}
|
Valid values are {D, W, M, Q, H, Y}
|
||||||
|
|
||||||
as_on_match : str, optional
|
as_on_match : str, optional
|
||||||
The match mode to be used for the as on date.
|
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
|
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.
|
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
|
closest : previous | next | exact
|
||||||
The default match mode for dates.
|
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,
|
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.
|
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.
|
Should the returns be compounded annually.
|
||||||
|
|
||||||
return_period_unit : years | month | days
|
return_period_unit : years | month | days
|
||||||
@ -410,7 +410,7 @@ class TimeSeries(TimeSeriesCore):
|
|||||||
|
|
||||||
Returns
|
Returns
|
||||||
-------
|
-------
|
||||||
Returs the rolling returns as a TimeSeries object.
|
Returns the rolling returns as a TimeSeries object.
|
||||||
|
|
||||||
Raises
|
Raises
|
||||||
------
|
------
|
||||||
@ -431,7 +431,7 @@ class TimeSeries(TimeSeriesCore):
|
|||||||
raise ValueError(f"Invalid argument for frequency {frequency}")
|
raise ValueError(f"Invalid argument for frequency {frequency}")
|
||||||
if from_date is None:
|
if from_date is None:
|
||||||
from_date = self.start_date + relativedelta(
|
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:
|
if to_date is None:
|
||||||
@ -476,7 +476,7 @@ class TimeSeries(TimeSeriesCore):
|
|||||||
) -> float:
|
) -> float:
|
||||||
"""Calculates the volatility of the time series.add()
|
"""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.
|
The periodicity of returns is based on the periodicity of underlying data.
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
@ -761,10 +761,10 @@ class TimeSeries(TimeSeriesCore):
|
|||||||
Parameters:
|
Parameters:
|
||||||
-----------
|
-----------
|
||||||
other: TimeSeries
|
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
|
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:
|
Returns:
|
||||||
--------
|
--------
|
||||||
@ -903,7 +903,7 @@ def read_csv(
|
|||||||
header = data[read_start_row]
|
header = data[read_start_row]
|
||||||
print(header)
|
print(header)
|
||||||
# fmt: off
|
# 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]
|
data = data[(read_start_row + 1):read_end_row]
|
||||||
# fmt: on
|
# fmt: on
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user