paradance.optimization.MultipleObjective
- class paradance.optimization.MultipleObjective(calculator: Calculator | LogarithmPCACalculator, direction: str | None = None, formula: str | None = None, warmup_formula: str | None = None, warmup_trials: int = 200, first_order: bool | None = False, power: bool | None = True, dirichlet: bool | None = False, weights_num: int | None = None, study_name: str | None = None, study_path: str | None = None, save_study: bool | None = True, checkpoint_path: str | None = None, first_order_with_scales: bool = True, first_order_lower_bound: float = 0.001, first_order_upper_bound: float = 1000000.0, free_style_lower_bound: float | List[float] = 0.001, free_style_upper_bound: float | List[float] = 1000000.0, base_weights: List[float] | None = None, base_weights_offset_ratio: float = 0.1, max_min_scale_ratio: float | None = None, first_order_scale_upper_bound: float | List[float] = 1, first_order_scale_lower_bound: float | List[float] = 1, power_lower_bound: float | List[float] = -1, power_upper_bound: float | List[float] = 1, pca_importance_lower_bound: float = 0, pca_importance_upper_bound: float = 10, config: Dict | None = None)[source]
This class provides methods to optimize the portfolio objective.
- __init__(calculator: Calculator | LogarithmPCACalculator, direction: str | None = None, formula: str | None = None, warmup_formula: str | None = None, warmup_trials: int = 200, first_order: bool | None = False, power: bool | None = True, dirichlet: bool | None = False, weights_num: int | None = None, study_name: str | None = None, study_path: str | None = None, save_study: bool | None = True, checkpoint_path: str | None = None, first_order_with_scales: bool = True, first_order_lower_bound: float = 0.001, first_order_upper_bound: float = 1000000.0, free_style_lower_bound: float | List[float] = 0.001, free_style_upper_bound: float | List[float] = 1000000.0, base_weights: List[float] | None = None, base_weights_offset_ratio: float = 0.1, max_min_scale_ratio: float | None = None, first_order_scale_upper_bound: float | List[float] = 1, first_order_scale_lower_bound: float | List[float] = 1, power_lower_bound: float | List[float] = -1, power_upper_bound: float | List[float] = 1, pca_importance_lower_bound: float = 0, pca_importance_upper_bound: float = 10, config: Dict | None = None) None[source]
Initialize with direction, weights_num, formula, and dirichlet.
- Parameters:
first_order_with_scales (bool, optional) – Whether to use scales-control in the first-order objective. Defaults to True.
first_order_lower_bound (float, optional) – Lower bound for first order value. Defaults to 1e-3.
first_order_upper_bound (float, optional) – Upper bound for first order value. Defaults to 1e6.
power_lower_bound (Union[float, List[float]]) – Lower bound for power value. Defaults to -1.
power_upper_bound (Union[float, List[float]]) – Upper bound for power value. Defaults to 1.
pca_importance_lower_bound (float, optional) – Lower bound for pca importance value. Defaults to 0.
pca_importance_upper_bound (float, optional) – Upper bound for pca importance value. Defaults to 10.
first_order_scale_bound (Optional[float], optional) – Scale bound for first order value. Defaults to None.
Methods
__init__(calculator[, direction, formula, ...])Initialize with direction, weights_num, formula, and dirichlet.
add_evaluator(flag, target_column[, ...])Adds evaluators to the objective.
build_logger([process_id])Constructs a logger for the optimization process.
construct_weights(trial)evaluate_custom_weights(weights)Evaluate the objective function with custom weights.
evaluate_given_scores(scores)Evaluate the objective function with given scores.
export_completed_formulas([weights])Exports the completed formulas by replacing weight placeholders in the formulas with actual values from the provided or default weights.
get_weights_num()Returns the number of weights.
objective(trial)Objective function to be optimized by optuna.
optimize(n_trials)Optimizes the objective for a set number of trials.
- add_evaluator(flag: str, target_column: str, mask_column: str | None = None, hyperparameter: Dict | None = None, evaluator_property: str | None = None, groupby: str | None = None, weights_for_groups: Series | None = None) None[source]
Adds evaluators to the objective.
- Parameters:
flag (str) – Type of calculator. Expected values include [“wuauc”, “portfolio”, “logmse”, …].
target_column (str) – The target column for calculation.
hyperparameter (Optional[float], optional) – Hyperparameter for the calculator. Defaults to None.
evaluator_property (Optional[str], optional) – Property of the evaluator. Defaults to None.
groupby (Optional[str], optional) – Grouping criteria. Defaults to None.
- evaluate_custom_weights(weights: List[float]) List[float][source]
Evaluate the objective function with custom weights.
- Parameters:
weights (List[float]) – Custom weights to evaluate.
- evaluate_given_scores(scores: List[float]) List[float][source]
Evaluate the objective function with given scores.
- Parameters:
scores (List[float]) – Scores to evaluate.
- objective(trial: Trial) float[source]
Objective function to be optimized by optuna.
- Parameters:
trial (Trial) – Optuna trial instance.
- Returns:
Computed objective value based on the provided trial.
- Return type:
- export_completed_formulas(weights: ndarray | None = None) None[source]
Exports the completed formulas by replacing weight placeholders in the formulas with actual values from the provided or default weights.
If weights is not provided, it defaults to self.best_params. The method updates self.completed_formulas by replacing occurrences of weights[i] in the stored equations with corresponding values from the weight array.
- Parameters:
weights (Optional[np.ndarray]) – An optional numpy array containing weight values to substitute in the formulas. If None, self.best_params is used.
- Returns:
This method does not return a value but updates self.completed_formulas with the substituted equations.
- Return type:
None