<a id="skfolio-preprocessing-prices-to-returns"></a>

# skfolio.preprocessing.prices_to_returns

<a id="skfolio.preprocessing.prices_to_returns"></a>

### skfolio.preprocessing.prices_to_returns(X, y=None, log_returns=False, nan_threshold=1, join='outer', drop_inceptions_nan=True, fill_nan=True)

Transform a DataFrame of prices to linear or logarithmic returns.

Linear returns (also called simple returns) are defined as:
: $$
  \frac{S_{t}}{S_{t-1}} - 1
  <br/>
  $$

Logarithmic returns (also called continuously compounded return) are defined as:
: $$
  ln\Biggl(\frac{S_{t}}{S_{t-1}}\Biggr)
  <br/>
  $$

With $S_{t}$ the asset price at time $t$.

#### WARNING
The linear returns aggregate across securities, meaning that the linear return
of the portfolio is the weighted average of the linear returns of the
securities. For this reason, **portfolio optimization should be performed
using linear returns** [[1]](#r9af81b715b17-1).

On the other hand, the logarithmic returns aggregate across time, meaning that
the total logarithmic return over K time periods is the sum of all K
single-period logarithmic returns.

#### SEE ALSO
[data preparation](https://skfolio.org/user_guide/data_preparation.html.md#data-preparation)

* **Parameters:**
  **X** *DataFrame*
  : The DataFrame of assets prices.

  **y** *DataFrame, optional*
  : The DataFrame of target or factors prices.
    If provided, it is joined with the DataFrame of prices to ensure identical
    observations.

  **log_returns** *bool, default=False*
  : If this is set to True, logarithmic returns are used instead of simple returns.

  **join** *str, default=”outer”*
  : The join method between `X` and `y` when `y` is provided.

  **nan_threshold** *float, default=1.0*
  : Drop observations (rows) that have a percentage of missing assets prices above
    this threshold. The default (`1.0`) is to keep all the observations.

  **drop_inceptions_nan** *bool, default=True*
  : If set to True, observations at the beginning are dropped if any of
    the asset values are missing, otherwise we keep the NaNs. This is useful when
    you work with a large universe of assets with different inception dates coupled
    with a pre-selection Transformer.

  **fill_nan** *bool, default=True*
  : If set to True, missing prices (NaNs) are forward filled using the previous
    price. Otherwise, NaNs are kept.
* **Returns:**
  **X** *DataFrame*
  : The DataFrame of price returns of the input `X`.

  **y** *DataFrame, optional*
  : The DataFrame of price returns of the input `y` when provided.

### References

* <a id='r9af81b715b17-1'>**[1]**</a> “Linear vs. Compounded Returns - Common Pitfalls in Portfolio Management”. GARP Risk Professional. Attilio Meucci (2010).

