PricesSeries

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

Bases: QFSeries

Series of prices (for example prices of the SPY).

Methods:

to_log_returns()

Converts timeseries to the timeseries of logarithmic returns.

to_prices([initial_price, ...])

Converts a timeseries into series of prices.

to_simple_returns()

Converts timeseries to the timeseries of simple returns.

total_cumulative_return()

Calculates the total cumulative return for the series.

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:

LogReturnsSeries

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

to_simple_returns() SimpleReturnsSeries[source]

Converts timeseries to the timeseries of simple returns. First date of prices in the returns timeseries won’t be present.

Returns:

timeseries of simple returns

Return type:

SimpleReturnsSeries

total_cumulative_return() float[source]

Calculates the total cumulative return for the series.