Install
openclaw skills install openclaw-quant-skillProfessional quantitative trading system for cryptocurrency - backtesting, paper trading, live trading, and strategy optimization
openclaw skills install openclaw-quant-skillProfessional quantitative trading system designed for cryptocurrency markets, featuring backtesting, paper trading, live trading, and advanced strategy optimization.
clawhub install openclaw-quant
# Clone repository
git clone https://github.com/ZhenRobotics/openclaw-quant.git ~/openclaw-quant
cd ~/openclaw-quant
# Install dependencies
pip install -r requirements.txt
# Set API keys (optional for backtesting)
export BINANCE_API_KEY="your-key"
export BINANCE_API_SECRET="your-secret"
cd ~/openclaw-quant
python -m openclaw_quant --help
AUTO-TRIGGER when user's message contains:
backtest, trading strategy, quant, cryptocurrency trading, optimize strategyTRIGGER EXAMPLES:
DO NOT USE when:
from openclaw_quant import Strategy, Backtest
class MAStrategy(Strategy):
# Parameters (can be optimized)
fast_period = 10
slow_period = 30
def init(self):
# Vectorized indicator calculation
self.fast_ma = self.I(SMA, self.data.Close, self.fast_period)
self.slow_ma = self.I(SMA, self.data.Close, self.slow_period)
def next(self):
# Event-driven logic
if self.fast_ma[-1] > self.slow_ma[-1]:
if not self.position:
self.buy()
else:
if self.position:
self.sell()
# Backtest
bt = Backtest(MAStrategy, data, cash=10000, commission=0.001)
result = bt.run()
print(result)
result.plot()
class RSIStrategy(Strategy):
rsi_period = 14
oversold = 30
overbought = 70
def init(self):
self.rsi = self.I(RSI, self.data.Close, self.rsi_period)
def next(self):
if self.rsi[-1] < self.oversold:
if not self.position:
self.buy()
elif self.rsi[-1] > self.overbought:
if self.position:
self.sell()
bt = Backtest(RSIStrategy, data, cash=10000)
result = bt.run()
# Optimize parameters automatically
result = bt.optimize(
fast_period=range(5, 20, 2),
slow_period=range(20, 60, 5),
maximize='sharpe_ratio' # or 'total_return', 'profit_factor'
)
print(f"Best parameters: {result.best_params}")
print(f"Sharpe Ratio: {result.sharpe_ratio:.2f}")
from openclaw_quant import LiveTrading
# Paper trading with real-time data
live = LiveTrading(
strategy=MAStrategy,
exchange='binance',
symbol='BTC/USDT',
paper=True # Simulation mode
)
live.run()
# Real trading (use with caution!)
live = LiveTrading(
strategy=MAStrategy,
exchange='binance',
symbol='BTC/USDT',
paper=False, # Real mode
api_key=os.getenv('BINANCE_API_KEY'),
api_secret=os.getenv('BINANCE_API_SECRET')
)
live.run()
# Backtest a strategy
openclaw-quant backtest --strategy ma_cross --symbol BTCUSDT --days 365
# Optimize parameters
openclaw-quant optimize --strategy rsi --symbol ETHUSDT --metric sharpe_ratio
# Paper trading
openclaw-quant paper --strategy ma_cross --symbol BTCUSDT
# Live trading
openclaw-quant live --strategy ma_cross --symbol BTCUSDT --confirm
# View results
openclaw-quant results --backtest-id abc123
Agent can understand requests like:
The system calculates comprehensive performance metrics:
| Metric | Description |
|---|---|
| Total Return | Overall profit/loss percentage |
| Annualized Return | Return extrapolated to one year |
| Sharpe Ratio | Risk-adjusted return (higher is better) |
| Sortino Ratio | Downside risk-adjusted return |
| Max Drawdown | Largest peak-to-trough decline |
| Win Rate | Percentage of profitable trades |
| Profit Factor | Gross profit / Gross loss |
| Calmar Ratio | Return / Max drawdown |
| Average Win/Loss | Mean profit/loss per trade |
| Expectancy | Expected value per trade |
The system includes several ready-to-use strategies:
50+ indicators available via self.I() method:
Trend Indicators:
Momentum Indicators:
Volatility Indicators:
Volume Indicators:
Built-in risk management features:
class MyStrategy(Strategy):
def init(self):
# Set risk parameters
self.risk_per_trade = 0.02 # 2% of capital
self.stop_loss = 0.05 # 5% stop loss
self.take_profit = 0.10 # 10% take profit
self.ma = self.I(SMA, self.data.Close, 20)
def next(self):
if self.ma[-1] > self.data.Close[-1]:
if not self.position:
# Calculate position size based on risk
size = self.calculate_position_size(
risk=self.risk_per_trade,
stop_loss=self.stop_loss
)
self.buy(size=size)
self.set_stop_loss(self.stop_loss)
self.set_take_profit(self.take_profit)
Supports multiple data sources:
# Example: Load data from Binance
from openclaw_quant import DataFetcher
fetcher = DataFetcher('binance')
data = fetcher.fetch_candles(
symbol='BTC/USDT',
timeframe='1h',
since='2023-01-01',
limit=1000
)
Example configuration file (config.yaml):
backtest:
initial_capital: 10000
commission: 0.001 # 0.1%
slippage: 0.0005 # 0.05%
strategy:
name: ma_cross
parameters:
fast_period: 10
slow_period: 30
exchange:
name: binance
testnet: false
risk:
max_position_size: 0.1 # 10% of capital
max_drawdown: 0.2 # Stop if 20% drawdown
daily_loss_limit: 0.05 # Stop if 5% daily loss
notification:
telegram:
enabled: true
bot_token: "your-token"
chat_id: "your-chat-id"
openclaw-quant/
├── src/
│ ├── openclaw_quant/
│ │ ├── __init__.py
│ │ ├── strategy.py # Strategy base class
│ │ ├── backtest.py # Backtest engine
│ │ ├── live.py # Live trading engine
│ │ ├── broker.py # Order execution
│ │ ├── data.py # Data fetching
│ │ ├── indicators.py # Technical indicators
│ │ ├── optimizer.py # Parameter optimization
│ │ ├── metrics.py # Performance metrics
│ │ └── risk.py # Risk management
│ └── strategies/
│ ├── ma_cross.py
│ ├── rsi.py
│ └── ...
├── examples/
│ ├── backtest_example.py
│ ├── optimization_example.py
│ └── paper_trading_example.py
├── tests/
├── docs/
├── requirements.txt
└── README.md
Python >= 3.9
pandas >= 2.0.0
numpy >= 1.24.0
ccxt >= 4.0.0
optuna >= 3.0.0
matplotlib >= 3.7.0
pydantic >= 2.0.0
Error: ccxt.NetworkError or connection timeout
Solution:
# Check internet connection
# Verify API keys are correct
# Use testnet for testing:
exchange = ccxt.binance({'enableRateLimit': True, 'options': {'defaultType': 'future', 'testnet': True}})
Error: Not enough candles for strategy
Solution:
# Increase warmup period
bt = Backtest(strategy, data, warmup=100) # Skip first 100 candles
# Or fetch more historical data
data = fetcher.fetch_candles(symbol='BTC/USDT', limit=5000)
Solution:
# Reduce search space
result = bt.optimize(
fast_period=range(5, 20, 5), # Larger step
slow_period=range(20, 60, 10),
max_tries=50 # Limit iterations
)
self.I() for indicators (computed once)~/openclaw-quant/QUICKSTART.md~/openclaw-quant/docs/API.md~/openclaw-quant/docs/STRATEGIES.md~/openclaw-quant/README.mdMIT License - Free for personal and commercial use
When using this skill, agents should:
DO:
DON'T:
Status: Under Development (Alpha)
Author: @ZhenStaff
Last Updated: 2026-03-05