Skip to content

contango.trading.execution.backtest.fill_behavior.rules.sufficient_position_rule

contango.trading.execution.backtest.fill_behavior.rules.sufficient_position_rule

SufficientPositionRule

Bases: FillRule[RuleContext]

Rule that only allows a sufficient position, disallowing selling more position than available.

validate

validate(context: RuleContext) -> bool

Returns True if the desired quantity does not result in the position becoming negative.

Source code in src\contango\trading\execution\backtest\fill_behavior\rules\sufficient_position_rule.py
15
16
17
18
19
def validate(self, context: RuleContext) -> bool:
    """
    Returns True if the desired quantity does not result in the position becoming negative.
    """
    return (context.desired_quantity + context.current_position) >= 0