Skip to content

contango.trading.execution.backtest.fill_behavior.rules.pyramiding_rule

contango.trading.execution.backtest.fill_behavior.rules.pyramiding_rule

PyramidingRule

Bases: FillRule[RuleContext]

Rule that does not allow two subsequent positive orders.

validate

validate(context: RuleContext) -> bool

Returns True upon correctly selling shares when the last order was a buy.

Source code in src\contango\trading\execution\backtest\fill_behavior\rules\pyramiding_rule.py
15
16
17
18
19
20
21
22
def validate(self, context: RuleContext) -> bool:
    """
    Returns True upon correctly selling shares when the last order was a buy.
    """
    return not (
        context.current_position > 0
        and context.desired_quantity > 0
    )