Skip to content

Use Alpha Lab signals

Use alpha for the three supplied alphalib 2.0.4 calculations. They return signal series, not orders or position sizes. The optional package must be installed in the Python environment that runs the strategy. Without it, the namespace is empty and an attempted signal call reports that it is unavailable.

Start with a complete strategy

"""Alpha Lab v2 temporal example: fixed quantities on a supplied high-price delta."""
from math import isfinite

symbol = "TCS"


def on_tick():
    history = bars(100)
    signal = alpha.alpha_026(history)
    value = signal[0]
    if not isfinite(value):
        return
    if position.is_flat and value < 0:
        long(10)
    elif position.is_long and value >= 0:
        close()

This example reads 100 available bars for the current instrument and computes the negative eight-bar change in high. It requests ten units when that value is negative and the position is flat, then requests an exit when the value becomes nonnegative. A high rising from 100 to 108 over eight intervals produces -8; a high falling from 108 to 100 produces 8. These are price differences, not percentages. A request fills under the configured execution rules, normally at the next available opening price.

The initial missing readings cause the example to wait. This is a teaching rule, not evidence of profitable trading or a recommendation about an instrument. The example uses the strategy's bar timeframe: eight hourly bars and eight daily bars describe different horizons.

Choose a supplied calculation

Call Required fields Meaning First possible usable observation
alpha.alpha_000(bars) close, low Negative rolling product of close/low over 16 observations 16th
alpha.alpha_026(bars) high Negative change in high over eight intervals 9th
alpha.alpha_084(bars) low, close Change in low/close over 26 intervals 27th

The first two source formulas spell negation as inv(x). Here inv(x) means -x, not 1/x. For alpha_000, a constant close/low ratio of 1 produces -1 after warmup. For alpha_084, a ratio moving from 0.98 to 0.99 over 26 intervals produces 0.01, a dimensionless ratio difference.

The observation counts assume valid required values. Null or undefined values can leave later results as NaN too. Check math.isfinite; do not replace missing signals with zero unless that is an explicit part of your rule. Warmup does not establish adequate research sample size, profitability or live readiness.

Supply full bars

Python calls require an explicit input. Use alpha.alpha_000(bars) or pass a fetched bar container, such as alpha.alpha_084(bars(200)). bars uses a default window of 500 available observations; the explicit form selects your history window. A requested window cannot create observations absent from the feed.

Do not write alpha.alpha_000(close) or alpha.alpha_026(high). The ordinary field proxies used by TAP export their numeric values under a column named close; they cannot provide the required high/low bundle or be relabeled by guessing. These three alpha calls reject field proxies and ask for full bars. The existing TAP forms such as sma(high, 20) remain valid for TAP.

For explicit portfolio work, fetch a complete intended set inside the strategy:

from atom.helpers.historical import get_historical_bars

def read_scores():
    history = get_historical_bars(["TCS", "INFY"], 100, timeframe="1d")
    if history is None:
        return {}
    results = alpha.alpha_084(history)
    return {symbol: result[0] for symbol, result in results.items()}

Call this helper from your strategy's book() or another dispatched function. Portfolio input returns a dictionary of symbol to result. An explicitly declared one-symbol portfolio remains a dictionary, and an empty portfolio protocol returns an empty dictionary. A single-instrument input returns one result. All three approved formulas calculate within each symbol's own chronological history; they do not rank instruments against one another. bars as an implicit current symbol is for single/broadcast contexts; use the explicit fetch in book().

The requested history length is per symbol. The local backtest returns only instruments with observed data, retaining portfolio mode even if just one is available. If none has history, the fetch returns None, which the helper above handles. Missing observations are not filled and the histories need not share a calendar; these temporal formulas work independently on the data for each name.

Histories must have ordered, unique observation keys. Portfolio data needs nonmissing datetime timestamps and nonempty string symbols. Duplicate keys or unordered per-symbol history are errors; alpha calls do not silently sort or fill future values. Missing required columns and malformed numeric inputs raise an alphalib error. Preserve industry labels for direct upstream formulas that declare that requirement; no industry-dependent formula is approved here.

Read current and earlier results

float(result) and result[0] read the latest value. result[1] reads one observation earlier. Empty latest values and positive lookbacks beyond the supplied history return NaN. Unlike a bare Atom price proxy, this does not raise a history error. Slices and iteration are chronological, oldest first:

result = alpha.alpha_084(bars(200))
current = result[0]
previous = result[1]
chronological_values = result[:]
recent_values = result[-5:]

Use these reads inside a dispatched strategy function. Arithmetic and comparisons use the current value. The package also accepts Python-style negative integer indexing, but [0] and positive offsets express lookbacks most clearly.

Repeated identical calls during one dispatch reuse signal work. A new bar, symbol, namespace function or changed input snapshot requires fresh work. For known single-symbol bar inputs, the current value may use the formula's proven exact window; older lookbacks, slices and iteration retain full supplied-history results. The full input is validated before that optimization. Arbitrary mutable pandas/Polars frames and custom protocol objects bypass dispatch memoization. Model bars containing opaque object metadata also run without memoization when that input cannot be safely frozen. Invalid required fields still report the normal alphalib validation error.

Install the approved optional build

Ask Alpha Lab for the pinned alphalib-2.0.4-py3-none-any.whl. From Atom's checkout, using the same Python 3.12 environment as the engine:

.venv/bin/python scripts/install_alphalib.py /path/to/alphalib-2.0.4-py3-none-any.whl

The installer verifies the approved artifact and installs its [atom] dependencies, including Polars and PyArrow. The loader checks both version and installed wheel provenance and requires the imported package/adapter to come from that installation. A shadow package on the Python path reports an import-origin error. A different build with the same version, an editable alphalib install, or an older version is rejected with an installation diagnostic. Do not install an unrelated same-named package from an arbitrary index. Missing PyArrow reports the required alphalib[atom] dependency rather than substituting another result.

Update an existing Alpha environment

Atom 4.11.0 accepts the reviewed 2.0.4 wheel instead of the 2.0.3 wheel accepted by Atom 4.10.1. Existing strategy calls do not need editing: for example, alpha.alpha_026(bars) still returns -8 when high rises from 100 to 108 over eight intervals. Update the environment that actually runs the engine, not just your editor's environment. Leaving 2.0.3 or 2.0.0 installed reports version drift before the namespace becomes usable; running without the optional package still leaves the namespace empty.

The approved 2.0.4 wheel's SHA256 is 9b1cdbac765920239e20f7731809d0f2c84673d01a4d1cb94b623c48e11b3554. Use the installer above rather than accepting another wheel solely because its filename says 2.0.4. Rebuilding the same source can change the archive bytes and requires a separate reviewed fingerprint. A later release must also be explicitly adopted and tested before changing the pin.

Other names in the upstream research catalog are not enabled by installation alone. Its reported research statistics have not been reproduced by these engine integration checks. Direct alphalib.atom calls and pandas batch/latest APIs are separate upstream interfaces, with their own scope and requirements.

See indicator usage, price data and target portfolios when composing a complete strategy.