Ml4t Build Barsのロゴ

Ml4t Build Bars

組織
ml4t
ml4t-build-bars

Aggregate tick data into time, volume, and dollar bars. Use when resampling raw tick data into regular or information-driven bars.

概要

公開者ml4t
リポジトリskills
スキル名ml4t-build-bars
スター
45
フォーク
13
同梱ファイル
指示のみ
ライセンスApache-2.0
リンク
  • Markdown形式の指示

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

  • どのLLMでも利用可能

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

  • 指示だけで完結

    モデルに必要なものはすべて指示に含まれているため、別途同期するファイルはありません。

  • オープンソース

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

インストール

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

1

TypingMindにインストール

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

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

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

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

Claude Code — .claude/skills
git clone --depth 1 https://github.com/ml4t/skills.git /tmp/skills
mkdir -p .claude/skills
cp -r /tmp/skills/data/build-bars .claude/skills/ml4t-build-bars
コピー後、新しいスキルを読み込むためにClaude Codeを再起動してください。

TypingMindで使用

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

関連するリクエストがあるとすぐに、モデルが自動的にMl4t Build Barsを読み込みます。

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

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

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

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

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

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

スキルの指示

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

Build Bars

Time bars sample by the clock, producing bars with wildly different information content - a 5-minute bar during the open contains 100x more trades than one at 2pm.

The Problem

Standard time bars (1-min, 5-min, daily) sample at fixed intervals regardless of market activity. During high-volume periods, a single bar compresses thousands of trades; during quiet periods, a bar may contain just a handful. This creates heteroscedastic returns that violate the i.i.d. assumptions of most ML models. Volume and dollar bars sample by activity instead, producing bars with roughly equal information content and returns closer to normality.

The Pattern

WRONG

python
import polars as pl

# Only using time bars - uneven information per bar
trades = pl.read_parquet("trades.parquet")
bars_5min = (
    trades.group_by_dynamic("timestamp", every="5m")
    .agg(
        open=pl.col("price").first(),
        close=pl.col("price").last(),
        volume=pl.col("size").sum(),
    )
)
# Bar at 9:30 has 5000 trades, bar at 14:00 has 50 trades

CORRECT

python
import numpy as np
import polars as pl

def bar_index(dollar_vol: np.ndarray, threshold: float) -> np.ndarray:
    """Bar id per trade: accumulate, close on the crossing, then RESET.

    Bucketing by the running total (cum_dollar // threshold) never resets, so
    an overshooting bar steals from the next: four $800 trades against a
    $1,000 threshold give $1,600, $800, $800, not two $1,600 bars."""
    idx = np.empty(len(dollar_vol), dtype=np.int64)
    bar, run = 0, 0.0
    for i, value in enumerate(dollar_vol):
        idx[i] = bar
        run += value
        if run >= threshold:
            bar, run = bar + 1, 0.0
    return idx

def build_dollar_bars(trades: pl.DataFrame, threshold: float) -> pl.DataFrame:
    """Build dollar bars: each bar contains ~threshold dollars traded."""
    trades = trades.sort("timestamp").with_columns(dollar_vol=pl.col("price") * pl.col("size"))
    return (
        trades
        .with_columns(bar_idx=bar_index(trades["dollar_vol"].to_numpy(), threshold))
        .group_by("bar_idx")
        .agg(
            timestamp=pl.col("timestamp").first(),
            open=pl.col("price").first(),
            high=pl.col("price").max(),
            low=pl.col("price").min(),
            close=pl.col("price").last(),
            volume=pl.col("size").sum(),
            dollar_volume=pl.col("dollar_vol").sum(),
            n_trades=pl.len(),
        )
        .sort("bar_idx")
    )

bars = build_dollar_bars(trades, threshold=1_000_000)  # $1M per bar

Choosing the Threshold

Calibrate the threshold as total dollar volume divided by the desired bar count.

Bar Type Comparison

TypeSamples OnInformation Per BarReturns Distribution
TimeClock intervalUnevenFat-tailed, heteroscedastic
TickN tradesMore uniformCloser to normal
VolumeN sharesUniform for single stockGood for single-name
Dollar$N tradedMost uniformClosest to normal

Guardrails

  • Dollar bars require tick-level trade data (timestamp, price, size) - cannot build from OHLCV
  • Thresholds are symbol-specific: $1M/bar for AAPL vs $50K/bar for a small-cap
  • Volume and dollar bars are not directly comparable across symbols - normalize returns
  • Overnight gaps should be handled (exclude or flag the first bar of each session)

Production Implementation

ml4t-engineer provides vectorized tick, volume, dollar, imbalance, and run-bar samplers:

python
from ml4t.engineer.bars import DollarBarSampler

bars = DollarBarSampler(dollars_per_bar=1_000_000).sample(trades.rename({"size": "volume"}))

Package-level names use vectorized implementations; compatibility implementations retain the Original suffix. Volume and imbalance samplers require a signed side column. Instantiate a concrete sampler with its class-specific threshold keyword, not the abstract BarSampler.

Checklist

  • Tick data available with timestamp, price, and size columns
  • Threshold calibrated to produce reasonable bar count (~same as time bars)
  • Bars include OHLCV, dollar volume, and trade count
  • Returns closer to normal verified (Jarque-Bera test or QQ plot)

よくある質問

AIスキル「Ml4t Build Bars」では何ができますか?

Aggregate tick data into time, volume, and dollar bars. Use when resampling raw tick data into regular or information-driven bars.

TypingMindでMl4t Build Barsを使うメリットは何ですか?

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

TypingMindにMl4t Build Barsをインストールするにはどうすればよいですか?

TypingMindで「プラグイン」→「スキル」→「GitHubからインストール」を開き、https://github.com/ml4t/skills/tree/main/data/build-barsを貼り付けてください。TypingMindがSKILL.mdを読み込み、チャットごとに有効にできるスキルとしてインストールします。

Ml4t Build Barsを使えるAIモデルはどれですか?

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

Ml4t Build Barsで使えるAIモデルの数に制限はありますか?

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

AIスキル「Ml4t Build Bars」は無料ですか?

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

AIスキルとは何ですか?

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

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

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

すべて見る

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

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