class_docstr: Portfolio Optimizer
  
  The following optimization algorithms are supported:
      - `gmv`: Global Minimum Variance Portfolio
      - `mvo`: Mean Variance Optimized Portfolio
      - `rp`: Risk Parity
      - `inv`: Inverse Volatility
  
  Note:
      This optimizer always assumes full investment and no-shorting.
class_docstr_tok: ["Portfolio","Optimizer","The","following","optimization","algorithms","are","supported",":","-","`","gmv","`",":","Global","Minimum","Variance","Portfolio","-","`","mvo","`",":","Mean","Variance","Optimized","Portfolio","-","`","rp","`",":","Risk","Parity","-","`","inv","`",":","Inverse","Volatility","Note",":","This","optimizer","always","assumes","full","investment","and","no-shorting","."]
docstr: solve optimization
  
  Args:
      n (int): number of parameters
      obj (callable): optimization objective
      bounds (Bounds): bounds of parameters
      cons (list): optimization constraints
docstr_tok: ["solve","optimization","Args",":","n","(","int",")",":","number","of","parameters","obj","(","callable",")",":","optimization","objective","bounds","(","Bounds",")",":","bounds","of","parameters","cons","(","list",")",":","optimization","constraints"]
code: def _solve(
      self, n: int, obj: Callable, bounds: so.Bounds, cons: List
  ) -> np.ndarray:
      """solve optimization
  
      Args:
          n (int): number of parameters
          obj (callable): optimization objective
          bounds (Bounds): bounds of parameters
          cons (list): optimization constraints
      """
      # add l2 regularization
      wrapped_obj = obj
      if self.alpha > 0:
  
          def opt_obj(x):
              return obj(x) + self.alpha * np.sum(np.square(x))
  
          wrapped_obj = opt_obj
  
      # solve
      x0 = np.ones(n) / n  # init results
      sol = so.minimize(
          wrapped_obj, x0, bounds=bounds, constraints=cons, tol=self.tol
      )
      if not sol.success:
          warnings.warn(f"optimization not success ({sol.status})")
  
      return sol.x
  
file_path: qlib/qlib/contrib/strategy/optimizer/optimizer.py
imports: import warnings
  import numpy
  import pandas
  import scipy.optimize
  from typing import Optional, Union, Callable, List
  from .base import BaseOptimizer
label_desc: Use image node_id 12 for calling the PortfolioOptimizer obj's underlying member method code with example usage: obj._solve(n, obj, bounds, cons) and returns: sol, unknown