from clyptq.apps.trading.spec import TradingSpec
from clyptq.apps.trading import TradingDriver
spec = TradingSpec(
strategy=strategy_spec,
data=TradingDataSpec(
observations=[
OHLCVSpec(
identifier="ohlcv_1m",
venue="binance",
market_type="futures",
timeframe="1m",
fields=["close", "volume"]
)
]
),
execution=TradingExecutionSpec(
mode="backtest",
venue="binance",
market_type="futures",
latency_mode="INSTANT", # No slippage
clock_freq="1m"
),
accounts=[
AccountSpec(
type="futures",
venue="binance",
initial_balance={"USDT": 10000.0},
margin_type="CROSS",
default_leverage=3.0
)
],
symbol_source_map=SymbolSourceMap(
mappings={
"BTC/USDT:USDT": ["ohlcv_1m"],
"ETH/USDT:USDT": ["ohlcv_1m"]
}
)
)
# Run
driver = TradingDriver.from_spec(spec)
driver.load_data(
items=["BTC/USDT:USDT", "ETH/USDT:USDT"],
start=datetime(2024, 1, 1),
end=datetime(2024, 12, 31)
)
results = driver.run()
# Analyze
print(f"Total Return: {results.total_return:.2%}")
print(f"Sharpe Ratio: {results.sharpe_ratio:.2f}")
print(f"Max Drawdown: {results.max_drawdown:.2%}")
print(f"Win Rate: {results.win_rate:.2%}")