Backtesting Ml Models Against Transaction Costsのロゴ

Backtesting Ml Models Against Transaction Costs

コミュニティ
HimanshuJ16
backtesting-ml-models-against-transaction-costs

機械学習モデルがほぼすべてのバーで予測を反転させ、シャープレシオがその売買回転率に左右される場合に使用します。戦略を評価する前に、売買回転率に応じたコストを適用し、信頼度のしきい値を設定します。注文単位のコスト分析にはtransaction-cost-analysis-tca-integrationを使用してください。

Add to TypingMind

概要

公開者HimanshuJ16
リポジトリAlgo-Trading-Skills
スキル名backtesting-ml-models-against-transaction-costs
スター
50
フォーク
7
同梱ファイル
5
ライセンスApache-2.0
リンク
  • Markdown形式の指示

    モデルが必要に応じて読み込むSKILL.mdファイルです。関連するリクエストがあったときだけトークンを消費します。

  • どのLLMでも利用可能

    AIスキルはプロバイダー固有のコードではなく、通常のMarkdownなので、GPT、Claude、Gemini、Grok、ローカルモデルで利用できます。

  • 5個の同梱ファイル

    モデルが作業中に読み取れるスクリプト、テンプレート、参考資料です。ファイルは読み取り専用で、実行されることはありません。

  • オープンソース

    HimanshuJ16がGitHubで公開しています。インストールする前にソースを確認してください。

インストール

AIスキル「Backtesting Ml Models Against Transaction Costs」をTypingMindにインストールすれば、どのLLMでも利用できます。SKILL.mdを読み取れる別のAIエージェントに追加することもできます。

1

TypingMindにインストール

TypingMindはGitHubフォルダから直接スキルをインストールします。SKILL.mdを読み取り、リソースファイルをまとめてローカルに保存します。

  1. アプリを開き、「プラグイン」→「スキル」に移動します。
  2. 「GitHubからインストール」を選択します。
  3. 以下のスキルフォルダのURLを貼り付けて確定します。
    https://github.com/HimanshuJ16/Algo-Trading-Skills/tree/main/skills/backtesting-ml-models-against-transaction-costs
  4. スキルを利用したいチャットごとに、そのスキルを有効にしてください。
「プラグイン」→「スキル」→「スキルを追加」→「GitHubのURLから」を選択し、フォルダのURLを貼り付けて「続行」を押します。
2

別のAIエージェントにインストール

Agent Skills形式を読み取れるAIエージェントなら、このスキルを利用できます。フォルダをそのAIエージェントのスキルディレクトリにコピーしてください。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/HimanshuJ16/Algo-Trading-Skills.git /tmp/Algo-Trading-Skills
mkdir -p .claude/skills
cp -r /tmp/Algo-Trading-Skills/skills/backtesting-ml-models-against-transaction-costs .claude/skills/backtesting-ml-models-against-transaction-costs
コピー後、新しいスキルを読み込むためにClaude Codeを再起動してください。

TypingMindで使用

TypingMindのチャットでBacktesting Ml Models Against Transaction Costsを有効にするだけで、あとはモデルが対応します。名前と説明がシステムプロンプトに含まれ、関連するリクエストがあると、モデルが指示の全文を自動で読み込みます。手動で呼び出す必要はなく、実際に使用されるまでトークンを消費しません。

関連するリクエストがあるとすぐに、モデルが自動的にBacktesting Ml Models Against Transaction Costsを読み込みます。

どのAIモデルでも利用可能

AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、Backtesting Ml Models Against Transaction Costsは作成時に想定されたモデルに縛られません。TypingMindに一度インストールすれば、ご自身のAPIキーを使って、GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama、またはご自身で実行するローカルモデルで利用できます。

  • 必要なときだけ読み込み

    システムプロンプトには名前と説明だけが含まれます。関連するリクエストが初めてあったときに指示を取得するため、スキルを使わない間は指示の読み込みにトークンを消費しません。

  • チャットの途中でモデルを切り替え

    スキルはコードではなく指示なので、モデルを切り替えてもそのまま使えます。次のモデルも同じSKILL.mdを読み込みます。

スキルの指示

モデルが読み込むSKILL.mdの内容です。スキルはモデルが従う指示なので、インストールする前に確認してください。

When to Use

Machine learning models inherently generate highly active signals (e.g., changing predictions from slightly positive to slightly negative on every bar). Without strict Transaction Cost Analysis (TCA) and confidence thresholding, these models achieve massive theoretical Sharpe ratios that instantly collapse in live trading due to Turnover Drag. Invoke this skill to evaluate ML model predictions against realistic slippage and commission models, filtering out low-confidence trades that do not cover their own execution costs.

When NOT to Use

  • Order-level cost attribution. This skill models cost as a flat bps charge per unit of turnover. To decompose realised shortfall into delay, spread, and market impact, use transaction-cost-analysis-tca-integration.
  • Size-dependent impact. The flat-rate model has no ADV or participation term, so it will understate cost for orders that are large relative to available liquidity. Pair it with liquidity-adjusted-position-sizing and strategy-capacity-estimation-before-scaling-capital before scaling capital.
  • Continuous or leveraged target weights. Positions here are discrete {-1, 0, +1}. A continuous-weight portfolio needs turnover computed on the weight vector — see portfolio-construction-with-transaction-cost-awareness.

Prerequisites

  • An array of numerical ML predictions (e.g., predicted forward returns or continuous signal strength).
  • An array of actual underlying returns, already aligned so that element i is the return realised after predictions[i] was observable. The backtester cannot detect misalignment.
  • Estimated transaction costs in basis points (bps) per half-turn (e.g., 5 bps for slippage + fee), calibrated against your own execution data rather than a folklore constant.

Workflow

  1. Align predictions to forward returns: pair predictions[t] with the return earned by acting on it (t → t+1, or t+1 → t+2 if your execution lags the signal by a bar). Getting this wrong is the single most common way to produce a spectacular, meaningless backtest.
  2. Clean the inputs: drop or impute NaN/Inf predictions before the backtest. A NaN prediction silently classified as "flat" is a hidden regime change in the strategy, not a neutral default — MlTcaBacktester rejects non-finite input rather than absorbing it.
  3. Set the hurdle: the entry threshold must clear the round-trip cost. A position that is entered and later exited pays 2 units of turnover, so require signal_threshold >= 2 * bps_cost_half_turn / 10_000 in decimal-return units. Below this line, a correct prediction is still a losing trade.
  4. Generate positions: map predictions to {+1, -1, 0} against the threshold.
  5. Decide whether to apply a buy/hold spread: if the model churns around the threshold boundary, set exit_threshold < signal_threshold so an open position is held until conviction genuinely decays, rather than being closed and re-entered on noise.
  6. Calculate turnover: costs are charged on position changes only. Flat→long is 1 unit; long→short is 2 units; a position still open on the final bar owes its exit half-turn (liquidate_at_end, on by default).
  7. Apply cost drag and compute net returns: subtract turnover × bps_cost_half_turn / 10_000 from gross returns each period.
  8. Sweep the threshold out-of-sample: pick signal_threshold/exit_threshold on training folds and confirm them on held-out data. Choosing the threshold that maximises net return on the same sample you report is parameter mining, not cost control — see walk-forward-optimization-window-management.
  9. Stress the cost assumption: re-run at 2–3× your estimated bps. A strategy whose net edge disappears when costs double has no margin for a bad execution day.

Full procedure: see references/workflows.md. Standards reference: see references/standards.md. Printable pre-flight checklist: see assets/checklist.md.

Common Pitfalls

  • Ignoring State Persistence: Charging a transaction cost on every bar simply because the model predicted "Buy", even though the portfolio is already in a "Buy" state. Costs are only incurred on position changes (Turnover).
  • Zero Thresholding: Taking trades on microscopic predictions (e.g., model predicts +0.0001% return) which guarantees a net loss when the transaction cost is 0.05%. A threshold of exactly 0 is worse than useless — it makes the long and short conditions overlap, so a neutral prediction can be classified as a short.
  • Symmetric Costs: Forgetting that crossing the spread (market order) costs money on both entry and exit (half-turns).
  • The Free Exit: Ending the backtest with an open position and never charging the closing half-turn. On a low-trade-count strategy this can hide a meaningful slice of total cost.
  • Contemporaneous Returns: Multiplying predictions[t] by the return of the bar the prediction was made on. This is look-ahead bias, and the resulting equity curve survives any cost assumption you throw at it — see lookahead-bias-elimination.
  • NaN as Neutral: Letting missing predictions default to "flat". The backtest then reports a strategy nobody can trade, and a NaN in the return series silently poisons every compounded metric.
  • Threshold Mined In-Sample: Sweeping signal_threshold across the full history and reporting the best net result. The threshold is a free parameter, and cost-aware backtests overfit it as readily as any other.

Verification

  • Simulate an ML model that perfectly predicts 10% returns but flips direction every day. Apply a 6% (600 bps) per-half-turn cost. The gross return will be massive, but the net return must be decisively negative — covered by test_perfect_but_churning_model_is_net_negative.
  • Confirm a held position is charged once, not once per bar: two consecutive identical long signals must produce 1 unit of turnover, not 2.
  • Confirm a neutral (0.0) prediction maps to flat, never to short.
  • Run python -m unittest discover -s skills/backtesting-ml-models-against-transaction-costs/scripts and confirm a 100% pass rate.

Related Skills

  • transaction-cost-analysis-tca-integration
  • execution-cost-model-recalibration-cadence
  • lookahead-bias-elimination
  • execution-realistic-simulation
  • walk-forward-optimization-window-management
  • portfolio-construction-with-transaction-cost-awareness

同梱ファイル

スキルが読み込まれている間、モデルは必要に応じてこれらを読み取ります。読み取り可能なファイルとして提供され、実行されることはありません。

よくある質問

AIスキル「Backtesting Ml Models Against Transaction Costs」では何ができますか?

機械学習モデルがほぼすべてのバーで予測を反転させ、シャープレシオがその売買回転率に左右される場合に使用します。戦略を評価する前に、売買回転率に応じたコストを適用し、信頼度のしきい値を設定します。注文単位のコスト分析にはtransaction-cost-analysis-tca-integrationを使用してください。

TypingMindでBacktesting Ml Models Against Transaction Costsを使うメリットは何ですか?

一度インストールすれば、どのモデルでも使えるからです。Backtesting Ml Models Against Transaction Costsはプロバイダー固有のコードではなく、通常のMarkdownで記述されているため、同じスキルをGPT-5、Claude、Gemini、Grok、ローカルモデルで利用できます。チャットの途中でモデルを切り替えても、そのまま使い続けられます。TypingMindは自分のAPIキーで動作するため、シート単位のサブスクリプションではなく、プロバイダーに直接料金を支払います。スキルとチャットは自分のストレージに保持されます。

TypingMindにBacktesting Ml Models Against Transaction Costsをインストールするにはどうすればよいですか?

TypingMindで「プラグイン」→「スキル」→「GitHubからインストール」を開き、https://github.com/HimanshuJ16/Algo-Trading-Skills/tree/main/skills/backtesting-ml-models-against-transaction-costsを貼り付けてください。TypingMindがSKILL.mdを読み込み、関連ファイルをまとめて、チャットごとに有効にできるスキルとしてインストールします。

Backtesting Ml Models Against Transaction Costsを使えるAIモデルはどれですか?

TypingMindに接続したどのモデルでも利用できます。AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、GPT、Claude、Gemini、Grok、ローカルモデルのいずれも、リクエストの内容がこのスキルの用途に合ったときに、このスキルを読み込めます。

Backtesting Ml Models Against Transaction Costsで使えるAIモデルの数に制限はありますか?

数に制限はありません。スキルに対応したモデルであれば、GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llamaなど、どのモデルでもBacktesting Ml Models Against Transaction Costsを利用できます。すべてTypingMind上で、自分のAPIキーを使って利用できます。

AIスキル「Backtesting Ml Models Against Transaction Costs」は無料ですか?

はい。HimanshuJ16がApache-2.0ライセンスのもとでGitHubに公開しています。ご利用のAIプロバイダーに支払うのは、使用したトークンの料金だけです。

AIスキルとは何ですか?

AIスキルは、特定のタスクの実行方法をAIモデルに教える、再利用可能な指示のセットです。オープンなAgent Skills形式に従い、名前と説明を含むSKILL.mdファイルに加え、モデルが必要とするスクリプト、テンプレート、参照ファイルで構成されます。モデルはリクエストがスキルに合致したときだけ指示を読み込むため、インストール済みのスキルも、使うまでは費用がかかりません。

AIスキルは、プラグインやMCPサーバーとどう違いますか?

プラグインやMCPサーバーは、モデルが呼び出せる新しいツールを提供します。ツールとは、どこかで実行され、結果を返すコードです。一方、AIスキルは、タスクへの取り組み方、従うべき手順、望ましい出力の例といった知識や進め方をモデルに伝えます。スキルは通常のMarkdownで記述されているため、サーバー、APIキー、実行環境は不要で、どのモデルでも利用できます。

すべて見る

今すぐ自分専用のAIワークスペースを作成

ニュースレターに登録すると、新機能や今後のプレゼント企画のお知らせが届きます👇