Backtest Outlier And Bad Tick Filteringのロゴ

Backtest Outlier And Bad Tick Filtering

コミュニティ
HimanshuJ16
backtest-outlier-and-bad-tick-filtering

異常な誤発注価格、テストメッセージ、ゼロ価格、時系列順でないティックを含む生のティックまたはバーのファイルを取り込む際に使用します。異常な約定値1件が偽のシグナルを生み出すのを防ぎます。ただし、データを除去するたびに、ストップ注文が実際に約定していた可能性のある価格も削除されます。

概要

公開者HimanshuJ16
リポジトリAlgo-Trading-Skills
スキル名backtest-outlier-and-bad-tick-filtering
スター
50
フォーク
7
同梱ファイル
5
ライセンスApache-2.0
リンク
  • Markdown形式の指示

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

  • どのLLMでも利用可能

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

  • 5個の同梱ファイル

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

  • オープンソース

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

インストール

AIスキル「Backtest Outlier And Bad Tick Filtering」を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/backtest-outlier-and-bad-tick-filtering
  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/backtest-outlier-and-bad-tick-filtering .claude/skills/backtest-outlier-and-bad-tick-filtering
コピー後、新しいスキルを読み込むためにClaude Codeを再起動してください。

TypingMindで使用

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

関連するリクエストがあるとすぐに、モデルが自動的にBacktest Outlier And Bad Tick Filteringを読み込みます。

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

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

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

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

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

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

スキルの指示

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

When to Use

Invoke this skill during data ingestion prior to backtesting. Raw exchange tick files frequently contain anomalous data points: fat-finger bad prints ($10.00$ on a $100.00$ stock), test messages, corrupt quotes during opening auction, or zero-price trades. If unfiltered, a single erroneous low print can trigger a false $+900%$ momentum signal or hit a stop loss in backtest simulation that could never occur in reality.

When NOT to Use

  • Not for stop-loss, liquidation, or margin-call realism. Every purge deletes a price the backtest will never see. If a print was genuinely executable, removing it means your simulated stop never fires — the mirror image of the bias this skill exists to prevent. Filter the signal series, keep the raw series for execution modelling.
  • Not a substitute for the venue's own erroneous-trade record. Exchanges break clearly erroneous trades and publish the list. Where that record exists it is authoritative; a statistical filter is a fallback for data you cannot reconcile.
  • Not for detecting stale or out-of-sequence ticks. Despite the description's wording, this implementation reads prices only. It has no timestamps, so it cannot detect a repeated stale quote, a sequence gap, or an out-of-order print. Use sequence-number-gap-detection-for-feeds and clock-skew-correction-for-tick-timestamps.
  • Not for low-frequency bar series. A rolling window of 21 daily bars spans a month; the median will not track a trend, and legitimate moves get flagged. This is a tick and high-frequency-bar tool.
  • Not a returns-based test. It measures deviation from a rolling level, so a fast directional move drifts away from the trailing median and produces a low but non-zero false-positive rate. Measure that rate on a known-clean segment before trusting the settings.

Prerequisites

  • Raw price time series (ticks or high-frequency bars), chronologically ordered.
  • Rolling window size $W$ (e.g., 21 ticks) and outlier threshold $Z_{\text{max}}$ (e.g., 5.0 MAD deviations).
  • The instrument's minimum price variation (tick size), for the min_deviation floor.
  • Any array parallel to the prices — timestamps, volumes, venue codes — that must be realigned after filtering using report.kept_indices.

Workflow

  1. Compute Rolling Median & Median Absolute Deviation (MAD) over a strictly trailing window of already-accepted prices, so the decision for tick $i$ never reads tick $i+1$: $$\text{MAD} = \text{median}(|P_i - \text{median}(P)|)$$

  2. Evaluate Modified Z-Score (Iglewicz–Hoaglin, per NIST §1.3.5.17): $$Z_i = \frac{0.6745 \cdot |P_i - \text{median}(P)|}{\text{MAD}}$$

  3. Filter Outliers: Purge non-positive prices, non-finite prices, single-tick jumps beyond $\Delta_{\text{max}}%$, and prices where $Z_i > Z_{\text{max}}$. The test is applied in price units with an additive floor, $|P_i - \text{median}| > Z_{\text{max}} \cdot \text{MAD}/0.6745 + \gamma$, following Brownlees & Gallo (2006). Set $\gamma$ (min_deviation) to the tick size — at $\gamma = 0$ the MAD test is skipped entirely whenever MAD is zero, which is every flat window, and report.mad_test_skipped_count tells you how often that happened.

  4. Decide Whether a Run of Outliers Is a Level Shift: After max_consecutive_drops consecutive flags, the run is reinterpreted as a genuine gap (split, news, halt reopen) rather than bad prints. The prints purged on the way in are then restored, because the evidence says they were real, and the MAD window restarts at the new level. Set restore_ticks_on_regime_change=False for a strictly causal pass matching a live streaming filter — at the cost of permanently losing the ticks at each shift.

  5. Generate Data Cleanliness Report: Report total raw ticks, bad ticks purged, and percent dataset sanitized. Realign every parallel array with report.kept_indices before using the cleaned series.

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

Common Pitfalls

  • Using Mean/StdDev Instead of Median/MAD: Outliers heavily distort mean and standard deviation, masking subsequent bad prints.
  • Over-filtering Real Volatility Spikes: Setting $Z_{\text{max}}$ too low (e.g. 2.0) and truncating genuine flash crash price moves.
  • NaN Passing Every Test: Every comparison against NaN is False, so an unguarded filter accepts it, and one NaN then corrupts every subsequent median. Non-finite values must be rejected explicitly, before any comparison.
  • Trusting a Flat Window: When more than half a window shares one value, MAD is exactly zero and the modified Z-score is undefined. Skipping the test there silently leaves quiet stretches unscreened; dividing anyway raises ZeroDivisionError. Use the $\gamma$ floor.
  • A Bad First Print Anchoring the File: A trailing filter has no history before the first tick, so an erroneous opening print is accepted and becomes the reference for the jump test. Validate the first $W$ ticks against an external reference, or discard the warm-up.
  • Deleting Real Data at Every Genuine Gap: A naive consecutive-drop rule purges the leading ticks of every split or news gap. Worse, if the rolling window is not restarted at the new level it stays contaminated for $W$ more ticks and keeps re-flagging good prints — measured at 22 real ticks lost from a single level shift before this was fixed.
  • Losing Timestamp Alignment: The function returns bare prices. Reusing the original timestamp array against the cleaned series silently shifts every observation. Use kept_indices.
  • Treating 20% as a Standard: It is this implementation's default, not a published threshold. For US OTC equity securities FINRA's clearly-erroneous guidelines run from 20% (sub-$1) down to 3% ($1,000+), and LULD bands for NMS stocks above $3.00 are 5% (Tier 1) or 10% (Tier 2). A flat 20% is far too loose for a liquid equity. See references/standards.md.

Verification

  • Inject bad tick ($P=10.0$ into $100.0$ series), verify bad tick detection and removal.
  • Inject float("nan") and float("inf") and assert neither appears in the cleaned series.
  • Feed a permanent level shift and assert no genuine tick is lost and exactly one regime change is reported.
  • Assert the hand-computed MAD boundary: window $[10,11,12,13,14]$ has median $12$ and MAD $1$, so with $Z_{\text{max}}=5$ the limit is $5/0.6745 = 7.4129$; $19.42$ must be purged and $19.41$ kept.
  • Run the filter over a segment known to be clean and confirm the purge rate is acceptably low.
  • Run python -m unittest discover -s skills/backtest-outlier-and-bad-tick-filtering/scripts and confirm 100% pass rate.

Related Skills

  • data-vendor-cross-validation-for-backtests
  • backtest-determinism-and-reproducibility
  • multi-source-price-reconciliation-tie-breaking
  • sequence-number-gap-detection-for-feeds

同梱ファイル

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

よくある質問

AIスキル「Backtest Outlier And Bad Tick Filtering」では何ができますか?

異常な誤発注価格、テストメッセージ、ゼロ価格、時系列順でないティックを含む生のティックまたはバーのファイルを取り込む際に使用します。異常な約定値1件が偽のシグナルを生み出すのを防ぎます。ただし、データを除去するたびに、ストップ注文が実際に約定していた可能性のある価格も削除されます。

TypingMindでBacktest Outlier And Bad Tick Filteringを使うメリットは何ですか?

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

TypingMindにBacktest Outlier And Bad Tick Filteringをインストールするにはどうすればよいですか?

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

Backtest Outlier And Bad Tick Filteringを使えるAIモデルはどれですか?

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

Backtest Outlier And Bad Tick Filteringで使えるAIモデルの数に制限はありますか?

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

AIスキル「Backtest Outlier And Bad Tick Filtering」は無料ですか?

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

AIスキルとは何ですか?

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

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

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

すべて見る

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

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