QFSeries¶

class
qf_lib.containers.series.qf_series.
QFSeries
(data: object = None, index: object = None, dtype: object = None, name: object = None, copy: object = False, fastpath: object = False)[source]¶ Bases:
pandas.core.series.Series
,qf_lib.containers.time_indexed_container.TimeIndexedContainer
Base class for all timeindexed series used in the quantfin project.
Methods
exponential_average
(lambda_coeff)Calculates the exponential average of a series.
Attempts to infer the frequency of this series.
min_max_normalized
(original_min_value, …)Normalizes the data using minmax scaling: it maps all the data to the [0;1] range, so that 0 corresponds to the minimal value in the original series and 1 corresponds to the maximal value.
rolling_window
(window_size, func, …)Looks at a number of windows of size
window_size
and transforms the data in those windows based on the specifiedfunc
.rolling_window_with_benchmark
(benchmark, …)Looks at a number of windows of size
window_size
and transforms the data in those windows based on the specifiedfunc
.Converts timeseries to the timeseries of logarithmic returns.
to_prices
(initial_price, …)Converts a timeseries into series of prices.
Converts timeseries to the timeseries of simple returns.
Calculates the total cumulative return for the series.

exponential_average
(lambda_coeff: float = 0.94) → qf_lib.containers.series.qf_series.QFSeries[source]¶ Calculates the exponential average of a series.
 Parameters
lambda_coeff – lambda coefficient
 Returns
exponential average of the series
 Return type

get_frequency
() → qf_lib.common.enums.frequency.Frequency[source]¶ Attempts to infer the frequency of this series. The analysis uses pandas’ infer_freq, as well as a heuristic to reduce the amount of
Irregular
results.See the implementation of the Frequency.infer_freq function for more information.

min_max_normalized
(original_min_value: float = None, original_max_value: float = None) → qf_lib.containers.series.qf_series.QFSeries[source]¶ Normalizes the data using minmax scaling: it maps all the data to the [0;1] range, so that 0 corresponds to the minimal value in the original series and 1 corresponds to the maximal value. It is also possible to specify values which should correspond to 0 and 1 after applying the normalization. It is useful if the same normalization parameters are used to normalize different data.
 Parameters
original_min_value – value which should correspond to 0 after applying the normalization
original_max_value – value which should correspond to 1 after applying the normalization
 Returns
series of normalized values
 Return type
normalized_series

rolling_window
(window_size: int, func: Callable[[Union[QFSeries, numpy.ndarray]], float], step: int = 1, optimised: bool = False) → qf_lib.containers.series.qf_series.QFSeries[source]¶ Looks at a number of windows of size
window_size
and transforms the data in those windows based on the specifiedfunc
.The window indices are stepped at a rate specified by
step
. Parameters
window_size – The size of the window to look at specified as the number of data points.
func – The function to call during each iteration. When
other
isNone
this function should take oneQFSeries
and return a value (Usually a number such as afloat
). Otherwise, this function should take twoQFSeries
arguments and return a value.step – The amount of data points to step through after each iteration, i.e. how much to move the window by in each iteration.
optimised – Whether the more efficient pandas algorithm should be used for the rolling window application. Note: This has some limitations: The
step
must be 1 andfunc
will get anndarray
parameter which only contains values and no index.
 Returns
A
QFSeries
containing the transformed data. Return type

rolling_window_with_benchmark
(benchmark: qf_lib.containers.series.qf_series.QFSeries, window_size: int, func: Callable[[QFSeries], float], step: int = 1) → qf_lib.containers.series.qf_series.QFSeries[source]¶ Looks at a number of windows of size
window_size
and transforms the data in those windows based on the specifiedfunc
.The window indices are stepped at a rate specified by
step
. This function runs a “correlated” rolling window iteration. Thefunc
must accept two arguments, one from each series. Parameters
benchmark – The benchmark to compare to.
window_size – The size of the window to look at specified as the number of data points.
func – The function to call during each iteration. When
other
isNone
this function should take twoQFSeries
arguments and return a value. (Usually a number such as afloat
).step – The amount of data points to step through after each iteration, i.e. how much to move the window by in each iteration.
 Returns
A
QFSeries
containing the transformed data. Return type

to_log_returns
() → LogReturnsSeries[source]¶ Converts timeseries to the timeseries of logarithmic returns. First date of prices in the returns timeseries won’t be present.
 Returns
timeseries of log returns
 Return type

to_prices
(initial_price: float = None, suggested_initial_date: Union[datetime.datetime, int, float] = None, frequency: qf_lib.common.enums.frequency.Frequency = None) → PricesSeries[source]¶ Converts a timeseries into series of prices. The timeseries of prices returned will have an extra date at the beginning (in comparison to the returns’ timeseries). The difference between the extra date and the rest of the dates can be inferred from the returns’ timeseries or can be calculated using the frequency passed as the optional argument. Additional date at the beginning (so called “initial date”) is caused by the fact, that return for the first date of prices timeseries cannot be calculated, so it’s missing. Thus, during the opposite conversion, extra date at the beginning will be added.
 Parameters
initial_price – initial price of the timeseries. If no price will be specified, then it will be assumed to be 1.
suggested_initial_date – the first date or initial value for the prices series. It won’t be necessarily the first date of the price series (e.g. if the method is run on the PricesSeries then it won’t be used).
frequency – the frequency of the returns’ timeseries. It is used to infer the initial date for the prices series.
 Returns
series of prices
 Return type
