Quick overview

Ibex cheat sheet

Practical syntax-first reference for day-to-day Ibex usage. Use this as a quick lookup; see the full docs for deeper semantics.

Quick terms: DataFrame means table, TimeFrame means table + time column, and [ ... ] contains query steps like filter, update, and select.

Program skeleton

// Load file/stream library functions (optional)
import "csv";

// Read data
let df = read_csv("data.csv");

// Transform
let out = df[
    filter price > 0,
    update { value = price * qty }
][
    select { total = sum(value) }, by symbol
];

// Save
write_csv(out, "out.csv");

Most-used query patterns

Filter, select, update

df[filter x > 10];
df[select { a, b, c }];
df[update { z = x + y }];
df[rename new_x = x];
df[order ts, symbol];
df[distinct];

Grouped aggregate / update

// one row per group
df[select { m = mean(x), n = count() },
   by symbol];

// broadcast group metric to rows
df[update { gmean = mean(x) }, by symbol];

Write joins in Ibex syntax

df1 join df2 on key;
df1 left join df2 on key;
df1 right join df2 on key;
df1 outer join df2 on key;
df1 semi join df2 on key;
df1 anti join df2 on key;
df1 cross join df2;

// multi-key
df1 join df2 on { k1, k2 };

Time-indexed tables, windows, and resample

let tf = as_timeframe(ticks, "ts");

tf[window 1m, update {
    rsum = rolling_sum(price),
    rmean = rolling_mean(price),
    prev = lag(price, 1)
}];
// bucketed aggregates
tf[resample 1m, select {
    open  = first(price),
    high  = max(price),
    low   = min(price),
    close = last(price)
}, by symbol];

Quick lookup

Aggregates

sum mean min max count first last median std ewma quantile skew kurtosis

Null handling

fill_null fill_forward fill_backward

Cumulative

cumsum cumprod

Scalar/date/casts

abs log sqrt year month day hour minute second round

Int64 Int32 Int Float64 Float32

RNG

rand_uniform rand_normal rand_student_t rand_gamma rand_exponential rand_bernoulli rand_poisson rand_int

R-style regression in one bracket

Formula syntax

// OLS with intercept
df[model { y ~ x1 + x2 }];

// No intercept
df[model { y ~ x - 1 }];

// Dot = all other columns
df[model { y ~ . }];

// Interaction and crossing
df[model { y ~ x1:x2 }];
df[model { y ~ x1 * x2 }];

Methods & accessors

// Ridge / WLS
df[model { y ~ x, method = ridge,
               lambda = 0.1 }];
df[model { y ~ x, method = wls,
               weights = w }];

// Extract results
model_coef(m);
model_summary(m);
model_fitted(m);
model_residuals(m);
model_r_squared(m);

Plugin and Stream basics

import "csv";
import "json";
import "parquet";

let df = read_csv("in.csv");
write_parquet(df, "out.parquet");
import "udp";

let s = Stream {
    source    = udp_recv(9001),
    transform = [filter price > 0],
    sink      = udp_send("127.0.0.1", 9002)
};

Run and compile

# REPL
./build-release/tools/ibex --plugin-path ./build-release/libraries

# Run a script (build + execute)
scripts/ibex-run.sh examples/quant.ibex

# Transpile only
scripts/ibex-build.sh examples/quant.ibex -o quant