Python Lab Guide

Quantitative research inside the terminal

Python Lab gives you a full research environment connected directly to Dome Terminal's data pipeline. Fetch market data, run backtests, validate strategies, and export results to Dome Script — without leaving the terminal or setting up external tools.

What Python Lab is — and what it isn't

Python Lab is a quantitative trading research environment. It is specifically designed for strategy research, indicator development, and statistical analysis using Dome Terminal's live and historical data. It is not a general-purpose Python coding environment — it won't run web scrapers or Discord bots.

What Python Lab is built for

Strategy research using real market data · Indicator calculations and statistical analysis · Backtest and walk-forward validation · Correlation and regime analysis · Exporting validated research to Dome Script for live or paper deployment

To open Python Lab: click Python Lab in the left sidebar, or press Alt+P. The lab opens in its own panel and can be floated to a second monitor. Your notebooks persist between sessions.

Your first notebook

Create a notebook from the Python Lab home screen (click + New Notebook). Each notebook is an independent research workspace. Give it a descriptive name — you'll accumulate more of these than you expect.

my_first_research.py
1# Dome Terminal Python Lab — default imports
2import dome as dt
3import pandas as pd
4import numpy as np
5
6# Verify the connection to terminal data
7status = dt.status()
8print(status)
9# → { "connected": true, "provider": "CME Live", "active_symbol": "ES" }
10

The import dome as dt line gives you access to the full data and backtest API. Run any cell with Shift+Enter. If dt.status() returns "connected": true, your notebook is live and ready.

Accessing market data

The dt.data() function is your primary data access method. It fetches OHLCV data for any symbol available through your configured data providers and returns a standard pandas DataFrame.

data_access.py
1# Fetch 500 bars of 4-hour BTC/USDT data
2df = dt.data("BTC/USDT", "4h", 500)
3
4# Preview the DataFrame
5print(df.head())
6print(df.dtypes)
7
8# Available columns: timestamp, open, high, low, close, volume
9# Data is always sorted oldest → newest (ascending timestamp)
DataFrame output — BTC/USDT 4H 500 rows × 6 cols
timestamp open high low close volume
2024-01-15 00:0042,800.0043,120.5042,640.0043,050.2518,420.3
2024-01-15 04:0043,050.2543,380.0042,980.7543,310.0021,840.7
2024-01-15 08:0043,310.0043,450.2543,100.0043,150.5014,220.1
2024-01-15 12:0043,150.5043,200.0042,880.2542,940.0024,680.9
ParameterTypeWhat it accepts
symbolstringAny symbol available in your provider: "BTC/USDT", "ES", "NQ", "AAPL", "EUR/USD"
timeframestring"1m", "5m", "15m", "1h", "4h", "1d", "1w" — must be supported by provider
barsintegerNumber of completed bars to return. Maximum: 5,000. More bars = slower fetch.
enddatetime (optional)End date for historical research. Defaults to now (current session data).
Running a backtest

The dt.backtest() function runs your strategy function against historical data and returns a full performance report. Walk-forward mode (wf=True) is strongly recommended — it's the difference between an honest and a misleading result.

backtest_example.py
1# Define your strategy function
2def my_strategy(df):
3    df['sma20'] = df['close'].rolling(20).mean()
4    df['signal'] = (df['close'] > df['sma20']).astype(int)
5    return df['signal']
6
7# Run backtest with walk-forward validation
8results = dt.backtest(
9    df,
10    strategy=my_strategy,
11    wf=True, # walk-forward — strongly recommended
12    cost_bps=5, # 5 basis points per trade (realistic)
13    slippage_bps=2 # 2 bps slippage assumption
14)
15print(results.summary())

Reading the output metrics

Sharpe Ratio
1.42
Return per unit of risk. Above 1.0 is acceptable; above 1.5 is good. Below 0.5 on walk-forward suggests edge is weak.
Max Drawdown
-14.2%
Largest peak-to-trough equity decline. You need to be able to trade through this psychologically — not just mathematically.
Win Rate
54.1%
Win rate alone is not meaningful without the reward-to-risk ratio. A 40% win rate with 3:1 R:R can outperform 70% at 0.8:1.
OOS Sharpe
1.18
Sharpe on the out-of-sample (walk-forward) portion only. This is the number that matters most — not the in-sample result.

Always use wf=True — here's why it matters

Without walk-forward, your backtest fits the strategy to data it has already seen — which almost always produces a better result than real trading. Walk-forward simulates deploying the strategy in rolling out-of-sample windows, giving you a realistic picture of what you'd have actually earned. The OOS Sharpe is the honest number. The in-sample Sharpe is the optimistic one.

Validation checklist — what makes a result trustworthy

A backtest result that passes all five of these checks is worth investigating further. A result that fails two or more is likely a false positive — do not proceed to live deployment based on it.

Walk-forward passes
The strategy performs consistently across all rolling walk-forward windows — not just a few lucky periods. If performance clusters in one time period, the edge may not be durable.
Realistic cost assumptions included
Transaction costs (spread + commission + slippage) are modelled at or above real-world levels for your instrument. Strategies that only work with zero-cost assumptions don't work in practice.
No lookahead bias in signal labels
Your signal uses only data that would have been available at bar close — not data from future bars. Use .shift(1) in pandas when referencing the prior bar's value.
OOS Sharpe ≥ in-sample Sharpe × 0.6
A rough but useful guide: if the out-of-sample Sharpe is less than 60% of the in-sample Sharpe, the strategy is heavily overfit to the training data. The ratio should be as close to 1.0 as possible. This threshold is a guide, not a guarantee.
Tested across multiple market regimes
The historical data includes trending markets, ranging markets, high-volatility periods, and low-volatility periods. A strategy that only works in one regime has a limited operational window and is not suitable for automated deployment.
Exporting to Dome Script

When your research passes the validation checklist, you can export the strategy function directly to the Script Library as a Dome Script template. From there it can be validated, refined in Dome Script syntax, and connected to a bot.

export.py
1# When research passes validation — export to Script Library
2dt.export(
3    my_strategy,
4    "Volume Breakout v1",
5    notes="Walk-forward validated Jan 2023 - Jan 2024. OOS Sharpe 1.18."
6)
7# → Creates a Dome Script template in Script Library
8# → Includes the backtest summary and notes as comments
9# → You can then refine, validate, and deploy from Script Library

Export carries your research context forward

The exported Dome Script template includes your backtest metrics and any notes you added as comments in the script header. This ensures that when you or someone else opens the strategy in Script Library months later, the research context is preserved — including why you built it and what the validation numbers were.

Common mistakes to avoid

These four mistakes account for the majority of misleading research results. Knowing what they are doesn't prevent you from making them — but checking for them systematically does.

Mistake 01

Overfitting to historical data

Running dozens of parameter combinations until you find one that looks great on the in-sample period. The strategy is memorizing the past, not discovering an edge. Walk-forward testing and a single, pre-specified parameter set are the defenses against this.

Mistake 02

Ignoring transaction costs

Setting cost_bps=0 or not thinking about it. A strategy that trades 20 times per day at 5 bps per trade loses 1% per day just to costs — before market risk. Always include realistic costs for your instrument and broker.

Mistake 03

Confusing in-sample with out-of-sample

Reporting the in-sample Sharpe as if it represents real-world performance. The in-sample number is what the strategy earned when it already knew the answers. The OOS number is what it earned when it didn't. Only the OOS number is a realistic performance estimate.

Mistake 04

Testing only in trending markets

Most momentum strategies look excellent when backtested on 2020–2021 crypto data (a strongly trending period). The question is how they perform in 2022 (downtrend) and 2023 (range). If your data doesn't include all three types of conditions, your result is incomplete.