lumix.core.expressions.LXQuadraticExpression¶
- class lumix.core.expressions.LXQuadraticExpression(linear_terms=<factory>, quadratic_terms=<factory>, constant=0.0)[source]¶
Quadratic expression: linear_terms + quadratic_terms + constant
Represents: 0.5 * x^T Q x + c^T x + constant
Example
# Portfolio variance: sum(w[i] * w[j] * cov[i,j]) # Plus linear returns: sum(return[i] * w[i]) quad_expr = LXQuadraticExpression() quad_expr.add_quadratic(w[0], w[1], cov[0,1]) quad_expr.linear_terms.add_term(w[0], returns[0])
- Parameters:
linear_terms (LXLinearExpression)
quadratic_terms (List[LXQuadraticTerm])
constant (float)
- __init__(linear_terms=<factory>, quadratic_terms=<factory>, constant=0.0)¶
- Parameters:
linear_terms (LXLinearExpression)
quadratic_terms (List[LXQuadraticTerm])
constant (float)
- Return type:
None
Methods
__init__([linear_terms, quadratic_terms, ...])add_quadratic(var1, var2[, coeff])Add quadratic term.
add_squared(var[, coeff])Add x^2 term.
Attributes
-
linear_terms:
LXLinearExpression¶
-
quadratic_terms:
List[LXQuadraticTerm]¶
- __deepcopy__(memo)[source]¶
Custom deepcopy that handles linear and quadratic terms.
This method enables what-if analysis on quadratic expressions by: 1. Deep copying the linear expression component 2. Deep copying all quadratic terms 3. Preserving the expression structure
- Parameters:
memo – Dictionary for tracking circular references during deepcopy
- Returns:
Deep copy of this quadratic expression with all dependencies resolved
- add_quadratic(var1, var2, coeff=1.0)[source]¶
Add quadratic term.
- Parameters:
var1 (
LXVariable) – First variablevar2 (
LXVariable) – Second variablecoeff (
float) – Coefficient
- Return type:
Self- Returns:
Self for chaining
- add_squared(var, coeff=1.0)[source]¶
Add x^2 term.
- Parameters:
var (
LXVariable) – Variable to squarecoeff (
float) – Coefficient
- Return type:
Self- Returns:
Self for chaining
- __add__(other)[source]¶
Enable: quad_expr + linear_expr or quad_expr + constant.
- Parameters:
other (
LXLinearExpression|float) – Linear expression or constant- Return type:
Self- Returns:
Self for chaining
- __init__(linear_terms=<factory>, quadratic_terms=<factory>, constant=0.0)¶
- Parameters:
linear_terms (LXLinearExpression)
quadratic_terms (List[LXQuadraticTerm])
constant (float)
- Return type:
None