Rebalance

class Rebalance(period='year', abs_deviation=None, rel_deviation=None)

Bases: object

Rebalancing strategy for an investment portfolio.

Rebalancing is the process by which an investor restores their portfolio to its target allocation by selling and buying assets. After rebalancing all the assets have original (target) weights.

Attributes

period

The rebalancing period for the investment portfolio.

abs_deviation

(float, optional) The absolute deviation allowed for the assets weights in the portfolio. It is defined for an asset weight as an absolut value of: actual_weight - target_weight. It must be more than 0 (0%). Max value is 1 (100%). if None the parameter is ignored.

rel_deviation

(float, optional) The relative deviation allowed for the assets weights in the portfolio. It is defined for an asset weight as an absolut value of: actual_weight / target_weight - 1. it must be positive. if None the parameter is ignored.

Methods & Attributes

assets_weights_ts(target_weights, ror)

Calculate assets weights monthly time series for rebalanced portfolio.

period

The rebalancing period for the investment portfolio.

return_ror_ts(target_weights, ror)

Return monthly rate of return time series of rebalanced portfolio given returns time series of the assets.

return_ror_ts_ef(weights, ror)

Return monthly rate of return time series of rebalanced portfolio given returns time series of the assets.

wealth_ts(target_weights, ror[, ...])

Calculate wealth index time series of rebalanced portfolio given returns time series of the assets.

wealth_ts_ef(weights, ror)

Calculate wealth index time series of rebalanced portfolio given returns time series of the assets.

property period

The rebalancing period for the investment portfolio.

It can be: ‘none’, ‘month’, ‘quarter’, ‘half-year’, ‘year’.

wealth_ts(target_weights, ror, calculate_assets_wealth_indexes=False)

Calculate wealth index time series of rebalanced portfolio given returns time series of the assets.

Optionally calculate also ASSETS wealth indexes time series inside rebalanced portfolio.

Parameters:
target_weightslist of float

The target weights for assets in the portfolio.

rorpd.DataFrame

Assets rate of return monthly time series.

calculate_assets_wealth_indexesbool, optional

Whether or not to calculate assets wealth indexes after rebalancing. When ‘True’ works slower.

Returns:
Result

Result of rebalancing investment portfolio.

assets_weights_ts(target_weights, ror)

Calculate assets weights monthly time series for rebalanced portfolio.

Parameters:
target_weightslist of float

The target weights for assets in the portfolio.

rorpd.DataFrame

Assets rate of return monthly time series.

Returns:
pd.DataFrame

Assets weights monthly time series.

return_ror_ts(target_weights, ror)

Return monthly rate of return time series of rebalanced portfolio given returns time series of the assets.

Parameters:
target_weightslist of float

The target weights for assets in the portfolio.

rorpd.DataFrame

Assets rate of return monthly time series.

Returns:
pd.Series

The monthly rate of return time series of rebalanced portfolio.

wealth_ts_ef(weights, ror)

Calculate wealth index time series of rebalanced portfolio given returns time series of the assets.

Simple version without conditional rebalancing (abs_deviation and rel_deviation are not used). This method is used for efficient frontier optimization. Default rebalancing period is a Year (end of year). For not rebalanced portfolio set period to ‘none’.

Parameters:
weightslist of float

The target weights for assets in the portfolio.

rorpd.DataFrame

Assets rate of return monthly time series.

Returns:
pd.Series

Wealth index time series.

return_ror_ts_ef(weights, ror)

Return monthly rate of return time series of rebalanced portfolio given returns time series of the assets.

Simple version without conditional rebalancing (abs_deviation and rel_deviation are not used). This method is used for efficient frontier optimization. Default rebalancing period is a Year (end of year). For not rebalanced portfolio set period to ‘none’.

Parameters:
weightslist of float or np.ndarray

The target weights for assets in the portfolio.

rorpd.DataFrame

Assets rate of return monthly time series.

Returns:
pd.Series

The monthly rate of return time series of rebalanced portfolio.