Skip to content

contango.strategy.rule_based.conditions.predicate

contango.strategy.rule_based.conditions.predicate

Predicate

Predicate(fn: Callable[[TradingContext], bool])

Bases: Condition[TradingContext]

A lambda expression that evaluates to a boolean.

Initializes Predicate.

Parameters:

Name Type Description Default
fn Callable[[TradingContext], bool]

The callable that returns a boolean.

required
Source code in src\contango\strategy\rule_based\conditions\predicate.py
13
14
15
16
17
18
19
20
def __init__(self, fn: Callable[[TradingContext], bool]) -> None:
    """
    Initializes `Predicate`.

    Args:   
        fn: The callable that returns a boolean.
    """
    self._fn = fn

evaluate

evaluate(context: TradingContext) -> bool

Evaluates the state of the predicate.

Parameters:

Name Type Description Default
context TradingContext

The current context to feed into the lambda.

required

Returns:

Name Type Description
bool bool

The boolean value of the lambda.

Source code in src\contango\strategy\rule_based\conditions\predicate.py
22
23
24
25
26
27
28
29
30
31
32
def evaluate(self, context: TradingContext) -> bool:
    """
    Evaluates the state of the predicate.

    Args:
        context: The current context to feed into the lambda.

    Returns:
        bool: The boolean value of the lambda.
    """
    return self._fn(context)