Skip to content

validate-strategy

Validates strategy configuration before deployment, checking required fields, valid formats, and MLflow model existence.

Overview

Property Value
Trigger Step Functions / Direct
Runtime Python 3.11
Timeout 60 seconds
Memory 256 MB

Input Schema

Step Functions sends a simplified payload:

{
    "strategy_name": "PascalStrategy",      # Required
    "strategy_version": "1.0.0",            # Optional
    "timeframe": "1h",                      # Optional, validated if provided
    "symbols": ["BTC/USDT:USDT"],           # Optional, validated if provided
    "start_date": "20240101",               # Optional, YYYYMMDD format
    "end_date": "20240131",                 # Optional, YYYYMMDD format
    "run_id": "uuid-123",                   # Optional
    "experiment_name": "backtest-pascal",   # Optional
    "freqai_enabled": false,                # Optional
    "freqai_model_name": "pascal-model"     # Required if freqai_enabled=true
}

Output Schema

{
    "statusCode": 200,
    "body": {
        "success": true,
        "data": {
            "valid": true,
            "strategy_name": "PascalStrategy",
            "errors": [],
            "warnings": []
        }
    }
}

Failure Response:

{
    "statusCode": 200,
    "body": {
        "success": true,
        "data": {
            "valid": false,
            "strategy_name": "PascalStrategy",
            "errors": [
                "Invalid timeframe '1x'. Valid options: ['1d', '1h', '1m', '1w', '15m', '30m', '4h', '5m']",
                "Invalid quote currency 'EUR' in BTC/EUR. Valid: ['BTC', 'BUSD', 'ETH', 'USD', 'USDT']"
            ],
            "warnings": []
        }
    }
}

Environment Variables

Variable Required Default Description
MLFLOW_TRACKING_URI No - MLflow server URL
MLFLOW_TRACKING_USERNAME No - MLflow username
MLFLOW_TRACKING_PASSWORD No - MLflow password
MODEL_REGISTRY_NAME No "tradai-models" MLflow registry name
REQUIRE_MLFLOW_MODEL No false Require model existence for FreqAI

Validation Rules

Required Fields

  • strategy_name must be non-empty string

Timeframe Validation

Valid timeframes: 1m, 5m, 15m, 30m, 1h, 4h, 1d, 1w

Symbol Validation

  • Must contain / separator (e.g., BTC/USDT)
  • Quote currency must be: USDT, BUSD, USD, BTC, ETH
  • For futures: settlement currency after : (e.g., BTC/USDT:USDT)

Date Validation

  • Format: YYYYMMDD (8 characters)
  • start_date must be before end_date

FreqAI Validation

  • If freqai_enabled=true, freqai_model_name is required
  • If REQUIRE_MLFLOW_MODEL=true, model must exist in MLflow registry

Validation Flow

flowchart TD
    A[Receive Request] --> B[Parse Schema]
    B -->|Invalid| C[Return schema errors]
    B -->|Valid| D{Timeframe provided?}
    D -->|Yes| E[Validate timeframe]
    D -->|No| F{Symbols provided?}
    E --> F
    F -->|Yes| G[Validate each symbol]
    F -->|No| H{FreqAI enabled?}
    G --> H
    H -->|Yes| I{Model name provided?}
    H -->|No| J{Dates provided?}
    I -->|No| K[Add error: model required]
    I -->|Yes| L{Check MLflow?}
    L -->|Yes| M[Query MLflow registry]
    L -->|No| J
    M -->|Not found| N[Add error: model not found]
    M -->|Found| J
    K --> J
    N --> J
    J -->|Yes| O[Validate date range]
    J -->|No| P[Build result]
    O --> P
    C --> Q[Return response]
    P --> Q

Step Functions Integration

{
  "ValidateStrategy": {
    "Type": "Task",
    "Resource": "arn:aws:lambda:...:validate-strategy",
    "Parameters": {
      "strategy_name.$": "$.strategy_name",
      "timeframe.$": "$.timeframe",
      "symbols.$": "$.symbols",
      "start_date.$": "$.start_date",
      "end_date.$": "$.end_date"
    },
    "ResultPath": "$.validation",
    "Next": "CheckValidation"
  },
  "CheckValidation": {
    "Type": "Choice",
    "Choices": [{
      "Variable": "$.validation.body.data.valid",
      "BooleanEquals": true,
      "Next": "LaunchBacktest"
    }],
    "Default": "ValidationFailed"
  }
}

Risk Parameter Validation (Full Config)

When full strategy config is provided:

Parameter Warning Condition
stoploss < -50% (very wide) or > -1% (very tight)
trailing_stop_positive <= 0 when trailing_stop enabled
stake_amount > 1000 (verify intentional)
max_open_trades > 20 (ensure sufficient capital)

MLflow Model Check

For FreqAI strategies, validates model exists:

client = MlflowClient()
model_versions = client.search_model_versions(f"name='{model_name}'")
# Returns True if any versions found