ReturnsSeries

class qf_lib.containers.series.returns_series.ReturnsSeries(data: Optional[object] = None, index: Optional[object] = None, dtype: Optional[object] = None, name: Optional[object] = None, copy: object = False, fastpath: object = False)[source]

Bases: QFSeries

Series of returns. It is a base class for series which specify the type of the returns (e.g. LogReturnsSeries). This is an abstract class and should not be instantiated.

Methods:

to_prices([initial_price, ...])

Converts a timeseries into series of prices.

to_prices(initial_price: float = None, suggested_initial_date: Union[datetime, int, float] = None, 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:

PricesSeries