Skip to content

contango.trading.execution.backtest.fill_behavior.rules.sufficient_cash_rule

contango.trading.execution.backtest.fill_behavior.rules.sufficient_cash_rule

SufficientCashRule

Bases: FillRule[RuleContext]

Rule that only allows trades with sufficient cash.

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_cash_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.total_cost <= context.current_cash