quantopy.ReturnDataFrame.from_price

classmethod ReturnDataFrame.from_price(price)[source]

Generate a new ReturnDataFrame with simple returns from given prices.

Parameters
pricendarray (structured or homogeneous), Iterable, dict, or DataFrame

Dict can contain Series, arrays, constants, dataclass or list-like objects.

Returns
ReturnDataFrame

A new ReturnDataFrame object with simple returns for the given price series.

See also

ReturnSeries.from_price

Analogous function for ReturnSeries.

Examples

>>> qp.ReturnDataFrame.from_price([10, 15, 20])
          0
1  0.500000
2  0.333333
>>> qp.ReturnDataFrame.from_price(
        {
            "stock_1": [10, 15, 20],
            "stock_2": [30, 20, 35]
        }
    )
    stock_1   stock_2
1  0.500000 -0.333333
2  0.333333  0.750000
>>> qp.ReturnDataFrame.from_price(
        pd.DataFrame(
            {
                "stock_1": [10, 15, 20],
                "stock_2": [30, 20, 35]
            }
        )
    )
    stock_1   stock_2
1  0.500000 -0.333333
2  0.333333  0.750000