Skill flagged — suspicious patterns detected

ClawHub Security flagged this skill as suspicious. Review the scan results before using.

OpenClaw Backtester

v1.0.0

Professional backtesting framework for trading strategies. Tests SMA crossover, RSI, MACD, Bollinger Bands, and custom strategies on historical data. Generat...

0· 73·0 current·0 all-time

Install

OpenClaw Prompt Flow

Install with OpenClaw

Best for remote or guided setup. Copy the exact prompt, then paste it into OpenClaw for cry779/openclaw-backtester.

Previewing Install & Setup.
Prompt PreviewInstall & Setup
Install the skill "OpenClaw Backtester" (cry779/openclaw-backtester) from ClawHub.
Skill page: https://clawhub.ai/cry779/openclaw-backtester
Keep the work scoped to this skill only.
After install, inspect the skill metadata and help me finish setup.
Required binaries: python3
Use only the metadata you can verify from ClawHub; do not invent missing requirements.
Ask before making any broader environment changes.

Command Line

CLI Commands

Use the direct CLI path if you want to install manually and keep every step visible.

OpenClaw CLI

Bare skill slug

openclaw skills install openclaw-backtester

ClawHub CLI

Package manager switcher

npx clawhub@latest install openclaw-backtester
Security Scan
VirusTotalVirusTotal
Benign
View report →
OpenClawOpenClaw
Suspicious
medium confidence
Purpose & Capability
Name/description match a Python backtester and required binary (python3) is appropriate. However, SKILL.md advertises multiple data sources (Yahoo Finance, Tiger API, CSV upload) and auto-install of pandas/numpy/matplotlib, while the included backtest.py only reads a local SQLite DB and uses pandas/numpy (no network or plotting). The advertised capabilities exceed the actual code.
!
Instruction Scope
SKILL.md instructs the user that the tool can use remote APIs and CSV upload and implies plotting output, but the runtime file only loads data from a specific local DB path (~/.openclaw/workspace/trading/a_stock_complete.db) and prints results. The prose gives the agent broad expectations (external APIs, fallback sources) that are not implemented in backtest.py, which is an inconsistency an operator should be aware of.
Install Mechanism
There is no install spec (instruction-only), which is low risk. SKILL.md claims pandas/numpy/matplotlib will be auto-installed but no install step is provided; the skill relies on runtime environment having these Python packages. This is a usability/consistency issue rather than an active install risk.
Credentials
The code accesses a single, clearly documented file path in the user's home directory for a local SQLite DB. No environment variables or network credentials are requested. File access is consistent with the stated local-database use, though users should confirm the DB path before running.
Persistence & Privilege
The skill does not request persistent privileges; always:false and no special system-wide modifications are present. The script only reads a local DB and prints output.
Scan Findings in Context
[pre_scan_injection_signals_none] expected: Static pre-scan reported no injection or suspicious regex findings. That aligns with the code being a small, local backtester (no network calls or obfuscated code). Absence of findings does not negate the documentation/code mismatches noted above.
What to consider before installing
This package is a small Python backtester that reads a local SQLite database at ~/.openclaw/workspace/trading/a_stock_complete.db and prints results. Before installing/using it: (1) Verify you have Python and required packages (pandas, numpy) in the environment — the skill has no install step. (2) Confirm the referenced DB path and contents; running the script will access that file path and will print errors if missing. (3) Don’t assume remote data sources or auto-install behavior described in SKILL.md — the included code does not call Yahoo Finance, Tiger API, or perform downloads. (4) If you need the advertised features (API or CSV ingestion), request the author/source code for those implementations or run the script in a sandbox until you confirm behavior. If you will run this on sensitive systems, inspect or run the backtest.py in an isolated environment first and ensure no unexpected network or file access occurs.

Like a lobster shell, security has layers — review code before you run it.

Runtime requirements

📈 Clawdis
Binspython3
latestvk97ex8n6djjk7r9d5213htp07d845jbz
73downloads
0stars
1versions
Updated 3w ago
v1.0.0
MIT-0

Beta Backtester

Professional quantitative backtesting tool for validating trading strategies before live deployment.

Design Patterns Applied

1. 迭代式优化模式 (Iterative Optimization Pattern)

回测框架采用参数优化迭代流程,逐步优化策略参数:

  • 参数扫描: 自动遍历参数空间(如SMA的fast/slow、RSI的超买/超卖阈值)
  • 网格搜索: 测试不同参数组合,找到最优风险收益比
  • 验证集: 使用walk-forward分析避免过拟合

2. 情境感知工具选择 (Context-Aware Tool Selection)

根据数据类型和市场特性自动选择合适的数据源:

  • 数据源适配: A股使用本地SQLite数据库,美股/加密货币使用Yahoo Finance
  • 时间框架感知: 15分钟K线用于短线策略,日线用于中长线策略
  • 资产类别识别: 自动处理股票代码格式转换(如000001 → 000001.SZ)

3. 特定领域智能 (Domain-Specific Intelligence)

内置专业金融指标计算和风险评估:

  • 性能指标: Sharpe、Sortino、最大回撤、胜率、期望收益
  • 风险调整: 考虑手续费和滑点的实盘模拟
  • 权益曲线: 可视化回测结果,支持多策略对比

What It Does

  • Tests strategies on historical OHLCV data (stocks, crypto, forex)
  • Calculates performance metrics (Sharpe, Sortino, Max Drawdown, Win Rate)
  • Generates equity curves and drawdown charts
  • Compares multiple strategies side-by-side
  • Optimizes parameters for best risk-adjusted returns
  • Error handling with fallback data sources
  • A/B testing support for strategy comparison

Strategies Supported

StrategyDescriptionKey ParametersBest For
SMA CrossoverFast/slow moving average crossoverfast (8-14), slow (21-65)Trend following
RSIRSI overbought/oversold reversalsperiod (14), upper (70), lower (30)Mean reversion
MACDMACD signal line crossoversfast (12), slow (26), signal (9)Momentum trading
Bollinger BandsMean reversion at bandsperiod (20), std (2)Volatility trading
CustomUser-defined entry/exit logicCustomSpecialized strategies

Usage Examples

Basic Backtest

python3 backtest.py --strategy sma_crossover --ticker 600036 --start 2025-01-01 --end 2025-03-31

Parameter Optimization

python3 backtest.py --strategy rsi --ticker 000001 --start 2025-01-01 --end 2025-03-31 --upper 65 --lower 35

Multi-Strategy Comparison

# Run multiple strategies and compare
python3 backtest.py --strategy sma_crossover --ticker 600519 --start 2025-01-01 --end 2025-03-31
python3 backtest.py --strategy macd --ticker 600519 --start 2025-01-01 --end 2025-03-31
python3 backtest.py --strategy rsi --ticker 600519 --start 2025-01-01 --end 2025-03-31

Output Example

BACKTEST RESULTS: SMA_CROSSOVER | 600036 | 2025-01-01 to 2025-03-31
============================================================
📊 Performance Metrics
Total Return:        +18.2%
Annual Return:        +9.8%
Sharpe Ratio:         1.45 (Good)
Max Drawdown:        -8.7% (Acceptable)
Win Rate:             62% (Above average)
Total Trades:         32
Best Trade:          +6.8%
Worst Trade:         -3.2%
Avg Hold Time:        10 days

📈 Equity Curve
2025-01-15: $10,000 → $10,350 (Entry: SMA cross up)
2025-01-28: $10,350 → $10,520 (Exit: SMA cross down)
2025-02-10: $10,520 → $10,890 (Entry: SMA cross up)
2025-03-05: $10,890 → $11,820 (Exit: SMA cross down)
2025-03-20: $11,820 → $11,820 (Current position)

⚙️ Strategy Parameters
Fast SMA: 8
Slow SMA: 21
Commission: 0.05%
Slippage: 0.1%
Initial Capital: $100,000

Iterative Optimization Example

Step 1: Baseline with default parameters

python3 backtest.py --strategy sma_crossover --ticker 600036 --start 2025-01-01 --end 2025-03-31
# Result: Sharpe 1.25, Return +12.3%

Step 2: Test parameter variations

# Test fast=8, slow=21
python3 backtest.py --strategy sma_crossover --ticker 600036 --fast 8 --slow 21
# Result: Sharpe 1.45, Return +18.2%

# Test fast=10, slow=30
python3 backtest.py --strategy sma_crossover --ticker 600036 --fast 10 --slow 30
# Result: Sharpe 1.18, Return +14.5%

Step 3: Select optimal parameters (fast=8, slow=21) Step 4: Validate on out-of-sample data (2025-04-01 to 2025-06-30)

Error Handling & Validation

Data Validation

  • ✅ Checks database existence before query
  • ✅ Validates date range is valid
  • ✅ Handles empty result sets gracefully
  • ✅ Converts stock codes (e.g., 000001 → 000001.SZ)

Error Recovery

  • ❌ Database not found → Shows error with path
  • ❌ No data in date range → Warns user
  • ❌ Invalid stock code → Tries format conversion
  • ❌ Query error → Returns None and logs exception

Input Validation Checklist

  • Start date < End date
  • Stock code has valid format (6 digits)
  • Strategy name is supported
  • Initial capital > 0
  • Commission rate is reasonable (0.0001-0.005)

Metrics Explained

  • Sharpe Ratio: Risk-adjusted return (>1 is good, >2 is excellent) Formula: (Return - RiskFree) / StdDev
  • Max Drawdown: Largest peak-to-trough loss (-10% is acceptable) Shows worst-case loss scenario
  • Win Rate: % of profitable trades (>50% with good R:R is profitable)
  • Sortino Ratio: Like Sharpe but only penalizes downside volatility Better for asymmetric return distributions
  • R-Multiple: Return normalized by risk (1R = max loss per trade) Allows comparing trades of different sizes

Requirements

  • Python 3.8+
  • pandas, numpy, matplotlib (auto-installed)
  • SQLite database with OHLCV data (a_stock_complete.db)
  • Stock symbols in format: XXXXXX.SH (Shanghai) or XXXXXX.SZ (Shenzhen)

Data Sources

  • Default: Local SQLite (a_stock_complete.db) Location: ~/.openclaw/workspace/trading/a_stock_complete.db
  • CSV upload: Provide your own OHLCV data
  • API: Tiger API for professional data

A/B Testing Support

Compare multiple strategies on same dataset:

# Strategy A: SMA Crossover
python3 backtest.py --strategy sma_crossover --ticker 600036 --start 2025-01-01 --end 2025-03-31 > sma_results.txt

# Strategy B: RSI
python3 backtest.py --strategy rsi --ticker 600036 --start 2025-01-01 --end 2025-03-31 > rsi_results.txt

# Compare
cat sma_results.txt rsi_results.txt | grep "Sharpe\|Return\|Drawdown"

Best Practices

1. Avoid Overfitting

  • Use walk-forward analysis (train on past, validate on future)
  • Keep parameter search space reasonable (don't optimize too many parameters)
  • Use multiple instruments to validate strategy robustness

2. Include Transaction Costs

  • Always include commission (0.05%) and slippage (0.1%)
  • Real trading will have these costs - backtest should reflect reality
  • Test sensitivity: run with 0.02%, 0.05%, 0.1% commission

3. Check for Look-Ahead Bias

  • Ensure indicators only use past data
  • No peeking at future prices
  • Use .shift(1) when necessary for signal lag

4. Validate Data Quality

  • Check for missing bars or gaps
  • Verify OHLC consistency (high ≥ open/close ≥ low)
  • Remove outliers (>10% daily moves usually errors)

5. Test Edge Cases

  • Market crashes (e.g., 2020 COVID crash)
  • Low volatility periods (e.g., 2017)
  • Choppy sideways markets (e.g., 2023)

Workflow Example: Full Strategy Development

  1. Data Preparation

    • Load historical data from database
    • Clean and validate data quality
    • Check for missing bars
  2. Strategy Definition

    • Choose entry/exit criteria
    • Define position sizing
    • Set stop-loss/take-profit rules
  3. Initial Backtest

    • Run with default parameters
    • Analyze basic metrics (Sharpe, drawdown)
  4. Parameter Optimization (Iterative)

    • Grid search parameter space
    • Find optimal risk-adjusted return
    • Avoid overfitting
  5. Out-of-Sample Validation

    • Test on unseen data
    • Compare in-sample vs out-of-sample performance
    • Check for degradation
  6. Robustness Testing

    • Test on different instruments
    • Test in different market regimes
    • Add noise to parameters (±10%)
  7. Risk Analysis

    • Calculate VaR and CVaR
    • Stress test extreme scenarios
    • Check correlation with market
  8. Production Deployment

    • Paper trade for 1-2 weeks
    • Start with small position size
    • Monitor and adjust

Common Pitfalls

Look-ahead bias: Using future data in indicators ❌ Survivorship bias: Only testing current stocks (excluding delisted) ❌ Overfitting: Too many parameters, curve-fitting noise ❌ Ignoring costs: Forgetting commission and slippage ❌ Small sample: <50 trades is statistically insignificant ❌ Data snooping: Testing too many strategies until one works

Advanced Features

Custom Strategy Template

def calculate_custom_strategy(df: pd.DataFrame, param1: int, param2: float) -> pd.DataFrame:
    """User-defined strategy"""
    df = df.copy()
    
    # Your logic here
    df['signal'] = 0
    df.loc[entry_condition, 'signal'] = 1  # Buy
    df.loc[exit_condition, 'signal'] = -1  # Sell
    
    df['position'] = df['signal'].diff()
    return df

Monte Carlo Simulation

Add noise to price data to test strategy robustness:

def add_noise(df: pd.DataFrame, noise_pct: float = 0.01) -> pd.DataFrame:
    """Add random noise to prices"""
    df = df.copy()
    noise = np.random.normal(0, noise_pct, len(df))
    df['close'] = df['close'] * (1 + noise)
    return df

Troubleshooting

Problem: "Database not found" → Check: ls ~/.openclaw/workspace/trading/a_stock_complete.db → Fix: Import data using data ingestion pipeline

Problem: "No data in date range" → Check: Verify stock code format (e.g., 600036 → 600036.SH) → Check: Verify date format (YYYY-MM-DD) → Check: Database has data for that period

Problem: "Low Sharpe ratio (<0.5)" → Check: Strategy might be overfit → Check: Transaction costs too high → Check: Wrong time frame (try different bars)

Problem: "Too few trades (<20)" → Check: Parameter too restrictive → Check: Date range too short → Fix: Extend backtest period or relax entry criteria

Disclaimer

Backtested results do NOT guarantee future performance. Past performance is not indicative of future results. Always paper trade before going live. Test strategies in multiple market conditions before risking real capital.


Built by Beta — AI Trading Research Agent

Comments

Loading comments...