---
title: "Strategy Lifecycle"
description: "Programmatic deployment, monitoring, scaling, A/B testing, and retirement of strategies."
---

The Strategy Lifecycle Controller lets an LLM deploy, monitor, scale, and retire strategies without human intervention -- the core requirement for autonomous operation.

## Strategy State Machine

<CardGroup cols={3}>
  <Card title="Pending" icon="clock">
    Strategy created, thread not yet started.
  </Card>
  <Card title="Running" icon="play">
    Actively trading in a background thread.
  </Card>
  <Card title="Paused" icon="pause">
    Thread alive but not quoting. Orders canceled.
  </Card>
  <Card title="Stopping" icon="hand">
    Graceful shutdown in progress.
  </Card>
  <Card title="Stopped" icon="stop">
    Thread finished, engine idle.
  </Card>
  <Card title="Failed" icon="triangle-exclamation">
    Thread crashed with an error.
  </Card>
  <Card title="Retired" icon="box-archive">
    Permanently stopped. Can be removed.
  </Card>
</CardGroup>

**Transitions:** Pending &rarr; Running &rarr; Paused &rarr; Running. Running &rarr; Stopping &rarr; Stopped &rarr; Retired. Running/Stopping &rarr; Failed.

## Quick Start

```python
from horizon.fund import FundManager, FundConfig, StrategyConfig

fund = FundManager(FundConfig(total_capital=100_000))

# Add strategies before starting
fund.add_strategy(StrategyConfig(
    name="political_mm",
    pipeline=[signal, quote],
    markets=["will-x-win"],
    mode="paper",
))

fund.start()

# Or deploy after start
fund.add_strategy(StrategyConfig(
    name="crypto_arb",
    pipeline=[detect, execute],
    markets=["btc-100k"],
))
```

## Strategy Management

```python
# Check status of a specific strategy
status = fund.controller.status("political_mm")
print(f"State: {status.state.value}")
print(f"P&L: ${status.pnl:,.2f}")
print(f"Open orders: {status.open_orders}")
print(f"Uptime: {status.uptime_secs:.0f}s")

# List all strategies
for s in fund.controller.all_statuses():
    print(f"  {s.name}: {s.state.value} pnl={s.pnl:.2f}")

# Pause (cancels orders, keeps engine alive)
fund.pause_strategy("political_mm")

# Resume
fund.resume_strategy("political_mm")

# Scale capital allocation
fund.scale_strategy("political_mm", new_capital=25_000)

# Retire permanently
fund.remove_strategy("political_mm")
```

## Accessing Engines

Each strategy gets its own `Engine` instance running in a daemon thread.

```python
# Get all engines
engines = fund.controller.engines
# {"political_mm": <Engine>, "crypto_arb": <Engine>}

# Direct engine access for debugging
engine = engines["political_mm"]
print(engine.status())
print(engine.positions())
```

## Strategy Scaling

| Trigger | Action |
|---|---|
| Positive Sharpe after N days in staging | Promote to live with initial capital |
| Sustained profitability | Ramp up capital on schedule |
| Drawdown exceeds threshold | Auto-pause by risk monitor |
| No edge detected for N days | Retire strategy |
| LLM conviction change | Adjust capital proportionally |

## A/B Testing

Run two versions of a strategy simultaneously, each with a fraction of the allocated capital, and compare performance:

```python
# A/B test: deploy two variants
fund.add_strategy(StrategyConfig(
    name="mm_wide_spread",
    pipeline=[signal, quote_wide],
    markets=["will-x-win"],
))
fund.add_strategy(StrategyConfig(
    name="mm_tight_spread",
    pipeline=[signal, quote_tight],
    markets=["will-x-win"],
))

# Compare after running
attr = fund.pnl_attribution()
wide_pnl = attr["mm_wide_spread"]["total"]
tight_pnl = attr["mm_tight_spread"]["total"]
```

## Strategy Templates

Pre-built templates that the LLM can parameterize and deploy:

| Template | Pipeline | Key Parameters |
|---|---|---|
| **Directional** | signal -> kelly_sizer -> submit | signal_source, kelly_fraction, max_position |
| **Market Maker** | fair_value -> spread -> quote | spread_width, size, inventory_limit |
| **Arbitrage** | detect -> size -> execute | min_edge, max_position, exchanges |
| **Copy Trading** | wallet_signal -> filter -> mirror | target_wallets, min_confidence, delay |
| **Event-Driven** | catalyst -> position -> manage | catalyst_type, sizing_method, exit_rule |

## Configuration

```python
StrategyConfig(
    name="my_strategy",           # Unique name
    pipeline=[fn1, fn2, fn3],     # Pipeline functions
    markets=["market-slug"],      # Market IDs to trade
    exchange=Polymarket(...),     # Exchange (None for paper)
    feeds={"poly": PolymarketBook(...)},  # Data feeds
    risk=Risk().max_position(100),  # Risk config
    params={"custom_param": 42},  # Custom parameters
    mode="paper",                 # "paper" or "live"
    max_drawdown_pct=20.0,        # Strategy drawdown limit
)
```

## MCP Tools

| Tool | Description |
|---|---|
| `deploy_strategy` | Launch a strategy from template + parameters |
| `stop_strategy` | Gracefully stop a running strategy |
| `list_strategies` | All strategies with health and P&L |
| `promote_strategy` | Move from staging to live |
| `scale_strategy` | Adjust capital allocation |
