Optimizer
Optimizer#
-
class sigtech.framework.analytics.optimization.optimizer.Optimizer
A class implementing an optimisation task.
To run an optimisation problem, a
OptimizationProblem
object needs to be provided.If fit requires Factors then the
FactorExposures
containing the data must also be passed and the weights are found withOptimizer.calculate_optimized_weights
. Otherwise, if the optimization does not require knowledge of factors,FactorExposures=None
is valid butcalculate_optimized_weights_with_fit
must be used.See also
sigtech.framework.analytics.optimization.optimization_problem.OptimizationProblem
An example of running a mean-variance optimisation is provided below. Here,
RETURNS_DATA_DICTIONARY
is a dictionary of return series for each instrument.from sigtech.framework.analytics.optimization.optimization_problem import TermTypes, MetricTypes # Setup data factor_exposure = sig.FactorExposures() factor_exposure.fit(RETURNS_DATA_DICTIONARY); # Create a problem problem = sig.OptimizationProblem() problem.set_optimizer_objective(TermTypes.WEIGHT, element='SUM_', weights='AVG_RET.', value=1) problem.set_optimizer_objective(TermTypes.VARIANCE, element='FULL', metric=MetricTypes.VARIANCE, value=-10) # Want to minimize the return so require a negative weight problem.set_optimizer_bounds(TermTypes.WEIGHT, element='ALL', min_value=0) problem.set_optimizer_bounds(TermTypes.WEIGHT, element='SUM_', min_value=1, max_value=1) # Run optimisation optimizer = sig.Optimizer(factor_exposure, problem) result = optimizer.calculate_optimized_weights()
-
covariance_df(covariance_array)
Convert an array to DataFrame.
- Parameters
covariance_array – Input array.
- Returns
pandas DataFrame.
-
calculate_matrices()
Evaluate the standard matrices for use in the optimisation.
-
calculate_optimized_weights_with_fit(initial_guess: Optional[Union[pandas.core.series.Series, numpy.ndarray]] = None, *fit_args, **fit_kwargs)
Fit an empty
FactorExposures
object to allow us to use theOptimizer
functionality without any factors.Usually a
pd.DataFrame
of instrument returns is expected infit_args
.- Parameters
fit_args – Args to pass to
FactorExposures.fit
.fit_kwargs – Kwargs to pass to
FactorExposures.fit
.
-
calculate_optimized_weights(initial_guess: Optional[Union[pandas.core.series.Series, numpy.ndarray]] = None)
Construct and try to solve the optimisation objectives with constraints.
The solvers stored in the list
self.solvers
will be used in order to attempt to solve the problem. If no solver is successful, anOptimizationError
will be raised.