Indicators

q.indicator contains deterministic market measurements for one instrument at a time. Indicators preserve pandas indexes, never group by symbol implicitly, and do not express investment intent. The preserved observation index is the row key, so indicator results align correctly when assigned to or joined with other objects computed from the same observations.

Use indicators directly in research, model-input frames, dashboards, alerts, and rules. Scheduling and materialization belong to the application using QRT.

q.indicator.sma(prices["close"], 20)
q.indicator.ema(prices["close"], 20)
q.indicator.relative_strength(prices["close"], benchmark, lookback=21)

Native functions are flat under q.indicator; provider-specific formulas remain explicit under q.indicator.talib and q.indicator.pandas_ta. The examples below are executed live by Quarto every time the docs are built.

Sample data

We use qrt’s bundled AAPL sample dataset — loaded offline via q.data.datasets.load, no network dependency (see the Data tutorial for more on q.data):

import pandas as pd

import qrt as q

aapl = q.data.datasets.load("aapl")
aapl.tail()
open high low close volume
datetime
2026-07-20 333.510010 333.709991 323.679993 326.589996 53468000
2026-07-21 323.130005 329.600006 322.220001 327.739990 41338900
2026-07-22 327.869995 329.000000 323.339996 325.890015 38755900
2026-07-23 321.730011 323.299988 319.350006 321.660004 40840800
2026-07-24 NaN NaN NaN NaN 47460975

Calculate reusable market measurements directly and assemble them into a model-input DataFrame when needed:

sma_20 = q.indicator.sma(aapl["close"], 20)
sma_100 = q.indicator.sma(aapl["close"], 100)

price_indicators = pd.DataFrame({"close": aapl["close"], "sma_20": sma_20, "sma_100": sma_100})
price_indicators.tail()
close sma_20 sma_100
datetime
2026-07-20 326.589996 306.946999 282.654511
2026-07-21 327.739990 308.483498 283.192135
2026-07-22 325.890015 310.062999 283.724048
2026-07-23 321.660004 311.492000 284.301279
2026-07-24 NaN NaN NaN
q.indicator.ema(aapl["close"], 20).tail()
datetime
2026-07-20    313.057453
2026-07-21    314.455790
2026-07-22    315.544764
2026-07-23    316.127168
2026-07-24    316.127168
Name: close, dtype: float64

To add a native indicator, create qrt/indicator/_<indicator>.py with one public function and re-export it from qrt/indicator/__init__.py. Keep one canonical formula per native name; provider variants remain under their provider namespace.

Visualizing indicators

q.plot.line renders any indicator DataFrame as an interactive Plotly chart with hover, zoom, and range-selector buttons. Visualization does not register the values as stored features:

fig = q.plot.line(
    price_indicators,
    title="AAPL close price with SMA overlays",
    ylabel="Price",
    height=450,
)
fig.show()
Back to top