portfolio_optimization.components.postprocess module

This module implements required post processing steps.

class portfolio_optimization.components.postprocess.Decoder(portfolio_data, k)[source]

Bases: object

Decoder class for decoding samples and samplesets.

__init__(portfolio_data, k)[source]

Init for the Decoder Class.

Parameters:
  • portfolio_data (PortfolioData) – A PortfolioData object containing the portfolio to optimize.

  • k (int) – The number of bits that are used to represent the outstanding amount for each asset. A fixed point representation is used to represent \(2^k\) different equidistant values in the range \([LB_i, UB_i]\) for asset i.

decode_sample(sample)[source]

Decodes a sample to the oustanding_future array.

Parameters:

sample (Mapping[int, int]) – Sample as returned by D-Wave.

Return type:

ndarray[Any, dtype[float64]]

Returns:

Array containing all outstanding future values.

decode_sampleset(sampleset)[source]

Efficiently decodes a sampleset create a matrix of oustanding_future values.

Each row in the matrix corresponds to a different sample in the sampleset.

Parameters:

sampleset (SampleSet) – SampleSet as returned by D-Wave.

Return type:

ndarray[Any, dtype[float64]]

Returns:

Matrix containing all outstanding future values.

portfolio_optimization.components.postprocess.pareto_front(xvals, yvals, min_points=50, upper_right_quadrant=True)[source]

Calculates the pareto front with at least min_points data points by repeatedly creating a convex hull around data points.

Parameters:
  • xvals (ArrayLike) – x-values of data points

  • yvals (ArrayLike) – y-values of data points

  • min_points (int) – minimum number of points to be selected

  • upper_right_quadrant (bool) – If True, only show the upper right quadrant of the pareto front.

Return type:

tuple[ndarray[Any, dtype[float64]], ndarray[Any, dtype[float64]]]

Returns:

x, y values of the points that are on the pareto front