Ml4t Cost Model logo

Ml4t Cost Model

Organization
ml4t
ml4t-cost-model

Commission, slippage, and market-impact cost models for realistic strategy simulation. Use when backtesting to ensure P&L accounts for transaction costs.

Overview

Publisherml4t
Repositoryskills
Skill nameml4t-cost-model
Stars
45
Forks
13
Bundled files
Instructions only
LicenseApache-2.0
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by ml4t on GitHub. Read the source before you install it.

Installation

Install the Ml4t Cost Model AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/ml4t/skills/tree/main/backtest/cost-model
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/ml4t/skills.git /tmp/skills
mkdir -p .claude/skills
cp -r /tmp/skills/backtest/cost-model .claude/skills/ml4t-cost-model
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Ml4t Cost Model in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Ml4t Cost Model on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Ml4t Cost Model is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Backtest Cost Model

Once a strategy passes the feasibility screen, the backtest engine still needs explicit cost settings. If commission, slippage, and impact are left at optimistic defaults, the simulation is still fiction.

The Problem

Most mistakes at this stage are implementation mistakes: missing volume in the feed, flat slippage for every asset, or no participation cap on large orders. The result is a backtest that claims to include costs while still materially understating them.

The Pattern

WRONG

python
import numpy as np

# Zero-cost backtest - fiction
positions = compute_positions(signals)
gross_returns = positions * asset_returns
sharpe = gross_returns.mean() / gross_returns.std() * np.sqrt(252)  # overstated

CORRECT

python
import numpy as np

def net_returns_with_costs(
    weights: np.ndarray,     # target weight per BAR for ONE asset, not shares
    asset_returns: np.ndarray,
    prices: np.ndarray,
    adv_shares: np.ndarray,  # average daily volume in shares, per bar
    daily_vol: np.ndarray,   # daily return volatility, per bar
    nav: float,
    commission_bps: float = 1.0,
    spread_bps: float = 5.0,
    impact_coeff: float = 0.1,
) -> np.ndarray:
    """Net returns after commission, spread and impact, all fractions of NAV.

    One asset, arrays indexed by bar. For a panel, run this per asset and sum:
    np.diff over a time-by-asset array differences neighbouring assets, not bars.
    """
    gross = weights * asset_returns
    traded_w = np.abs(np.diff(weights, prepend=0.0))  # traded fraction of NAV

    # Fixed costs: commission + half-spread on the traded notional
    fixed_cost = traded_w * (commission_bps + spread_bps / 2) / 10_000

    # Impact eta*sigma*sqrt(Q/ADV) as written below: Q is in shares, so take
    # the weight change through NAV and price before comparing it to ADV.
    participation = np.where(adv_shares > 0, traded_w * nav / prices / adv_shares, 0.0)
    # No upper cap: clipping at 1.0 prices a 3x-ADV order like an ADV-sized one
    impact_pct = impact_coeff * daily_vol * np.sqrt(np.clip(participation, 0, None))
    impact = impact_pct * traded_w  # a price move costs only what you traded

    return gross - fixed_cost - impact


def estimate_capacity(gross_sharpe, turnover, cost_bps_per_turn):
    """Rough capacity: the AUM at which costs consume alpha to the threshold."""
    alpha_bps = gross_sharpe * 100 / np.sqrt(252)  # daily alpha in bps (approx)
    cost_drag = turnover * cost_bps_per_turn / 252
    return f"Gross alpha ~{alpha_bps:.1f} bps/day, cost drag ~{cost_drag:.1f} bps/day"

Cost Components

ComponentTypical RangeScales With
Commission0.5 - 10 bpsTrade count
Spread1 - 50 bpsAsset liquidity
Slippage1 - 20 bpsOrder urgency
Market impact5 - 100+ bpsOrder size / ADV
Financing25 - 300+ bps/yrShort positions, leverage

Impact model: $\text{impact} = \eta \cdot \sigma \cdot \sqrt{\frac{Q}{\text{ADV}}}$ where $Q$ is order size, $\sigma$ is daily volatility, $\eta$ is a calibration constant (typically 0.05-0.3).

Guardrails

  • Impact grows with the square root of participation rate - doubling AUM does not double cost
  • Use asset-class appropriate estimates: crypto spread is 5-50 bps, US large-cap is 1-3 bps
  • Short-side strategies must include borrow fees and financing - these can dominate total costs
  • Validate cost assumptions against actual fill data (TCA) when available

Production Implementation

ml4t-backtest provides composable cost models:

python
from ml4t.backtest import BacktestConfig, CommissionType, DataFeed, Engine
from ml4t.backtest.config import SlippageType
from ml4t.backtest.execution.impact import SquareRootImpact
from ml4t.backtest.execution.limits import VolumeParticipationLimit

config = BacktestConfig(
    commission_type=CommissionType.PERCENTAGE, commission_rate=0.001,  # 10 bps
    slippage_type=SlippageType.VOLUME_BASED, slippage_rate=0.001,
)
engine = Engine(
    DataFeed(prices_df=prices), strategy, config,
    market_impact_model=SquareRootImpact(volatility=0.02),
    execution_limits=VolumeParticipationLimit(max_participation=0.10),
)

Checklist

  • Feed includes volume so impact and participation limits are meaningful
  • Market impact modeled for order sizes > 1% ADV
  • Cost assumptions match asset class (not a single number for everything)
  • Zero-cost and cost-aware runs compared to quantify implementation drag
  • TCA or broker fill data used to calibrate rates when available

Frequently asked questions

What does the Ml4t Cost Model AI skill do?

Commission, slippage, and market-impact cost models for realistic strategy simulation. Use when backtesting to ensure P&L accounts for transaction costs.

Why use Ml4t Cost Model on TypingMind?

Because you install it once and use it with any model. Ml4t Cost Model is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Ml4t Cost Model in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/ml4t/skills/tree/main/backtest/cost-model. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Ml4t Cost Model?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Ml4t Cost Model?

As many as you like. As long as a model supports skills, you can use Ml4t Cost Model with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Ml4t Cost Model AI skill free?

Yes. It is published on GitHub by ml4t under the Apache-2.0 license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇