crypto-backtesting

crypto-backtesting is a skill for Claude Code from khanh-vu/claude-force. It costs 0 tokens per session (761 once invoked), scanned A, original, MIT.

Patterns for testing cryptocurrency trading strategies against historical market data, a process called backtesting.

In plain words
What is it for?
Use it to model trades, calculate returns, risk and drawdowns, and account for realistic order timing.
Why use it?
It helps reveal misleading results caused by using future information or unrealistic trade prices.

Skill for Claude Code

Written for Claude Code: installed under .claude/.

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/khanh-vu/claude-force/crypto-backtesting
Any agent
npx skills add khanh-vu/claude-force --skill crypto-backtesting
Clone the repo
git clone --depth 1 https://github.com/khanh-vu/claude-force

Made for: Claude Code.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for crypto-backtesting

README.md
[![agentmods](https://agentmods.dev/badge/skills/khanh-vu/claude-force/crypto-backtesting.svg)](https://agentmods.dev/skills/khanh-vu/claude-force/crypto-backtesting)
Your own site
<a href="https://agentmods.dev/skills/khanh-vu/claude-force/crypto-backtesting"><img src="https://agentmods.dev/badge/skills/khanh-vu/claude-force/crypto-backtesting.svg" alt="Measured on agentmods" height="20"></a>
Per session 0 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 761 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00000 $0.00761
Opus 5 $0.00000 $0.00380
Sonnet 5 $0.00000 $0.00152
Haiku 4.5 $0.00000 $0.00076

Measured 5d ago against content hash 3ddf2001a422, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-05, from the pricing page.

Security

Grade A, and why

crypto-backtesting scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 5d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.claude/skills/crypto-backtesting/SKILL.md · 112 lines

How it starts

The opening of the file, as written. The whole thing — 112 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Crypto Backtesting

Comprehensive backtesting framework patterns and pitfalls to avoid.

Backtesting Engine

import pandas as pd
from dataclasses import dataclass

@dataclass
class BacktestResult:
    total_return: float
    sharpe_ratio: float
    max_drawdown: float
    win_rate: float
    num_trades: int

class Backtester:
    def __init__(self, strategy, data: pd.DataFrame, initial_capital: float = 10000):
        self.strategy = strategy
        self.data = data
        self.initial_capital = initial_capital
        self.portfolio_value = []
        self.trades = []

    def run(self) -> BacktestResult:
        """Execute backtest with proper order of operations"""
        capital = self.initial_capital
        position = 0

        for timestamp, row in self.data.iterrows():
            # Generate signal BEFORE knowing close price (avoid lookahead bias)
            signal = self.strategy.generate_signal(row, position)

            if signal == 'buy' and position == 0:
                # Use NEXT bar's open price (realistic execution)
                entry_price = self._get_next_open(timestamp)
                shares = capital / entry_price
                position = shares
                capital = 0
                self.trades.append(('buy', timestamp, entry_price, shares))

            elif signal == 'sell' and position > 0:
                exit_price = self._get_next_open(timestamp)
                capital = position * exit_price
                self.trades.append(('sell', timestamp, exit_price, position))
                position = 0

            # Track portfolio value
            current_value = capital + (position * row['close'])
            self.portfolio_value.append(current_value)

        return self._calculate_metrics()

Walk-Forward Analysis

def walk_forward_optimization(
    strategy_class,
    data: pd.DataFrame,
    train_window: int = 252,  # 1 year
    test_window: int = 63,    # 3 months
    step_size: int = 21       # 1 month
):
    """
    Walk-forward optimization to prevent overfitting
    Train on historical data, test on future data
    """
    results = []

    for i in range(0, len(data) - train_window - test_window, step_size):
        # Split data
        train_data = data.iloc[i:i+train_window]
        test_data = data.iloc[i+train_window:i+train_window+test_window]

        # Optimize on training data
        best_params = optimize_strategy(strategy_class, train_data)

        # Test on out-of-sample data
        strategy = strategy_class(**best_params)
        backtest = Backtester(strategy, test_data)
        result = backtest.run()

        results.append({
            'train_period': (train_data.index[0], train_data.index[-1]),
            'test_period': (test_data.index[0], test_data.index[-1]),
            'params': best_params,
            'result': result
        })

    return results

Read the full file on GitHub · 112 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 5d ago First seen · 112 lines · 0 tokens per session scan A 3ddf2001a422

Subscribe to this mod's changes

crypto-backtesting is a skill published in the GitHub repository khanh-vu/claude-force (5 stars, last pushed 9mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 761 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.