qis.to_returns

qis.to_returns(prices, is_log_returns=False, return_type=ReturnTypes.RELATIVE, freq=None, include_start_date=False, include_end_date=False, ffill_nans=True, drop_first=False, is_first_zero=False, **kwargs)[source]

Convert prices to returns with specified methodology.

Parameters:
  • prices (Series | DataFrame) – Numeric price time series. Pandas nullable floating values are supported

  • is_log_returns (bool) – If True, compute log returns (overrides return_type)

  • return_type (ReturnTypes) – Type of return calculation. LOG and RELATIVE require finite positive endpoints; DIFFERENCE, LEVEL, and LEVEL0 accept finite signed levels

  • freq (str | None) – Resampling frequency (e.g., ‘D’, ‘W’, ‘M’)

  • include_start_date (bool) – Include period start date when resampling

  • include_end_date (bool) – Include period end date when resampling

  • ffill_nans (bool) – Forward-fill NaN prices before computing returns. With freq set, the fill applies when prices are resampled onto the freq grid; input whose inferred frequency already equals freq is returned by prices_at_freq with its missing values kept, so a missing observation there leaves both adjacent returns missing

  • drop_first (bool) – Drop first return observation

  • is_first_zero (bool) – Set first non-NaN return to zero

  • **kwargs – Accepted so that callers forwarding a shared keyword dictionary do not fail. They are not used, and any keyword passed here raises a UserWarning that names it, with the closest documented argument when there is one

Returns:

Return time series matching the input’s pandas shape and labels. LOG and RELATIVE are missing unless both endpoints are finite and positive. DIFFERENCE is missing unless both signed endpoints are finite; LEVEL and LEVEL0 are missing unless their returned level is finite. Nullable floating inputs retain a nullable output dtype. Integer LOG operands use double precision; DIFFERENCE widens narrower integers and unsigned levels within signed 64-bit capacity. Other wide integer differences retain native arithmetic

Return type:

Series | DataFrame