REALBT is a realistic backtesting engine for evaluating trading strategies on historical market data.
REALBT helps you test trading strategies against past data, organize projects, fetch historical prices, run backtests, and inspect results through a simple Python-first workflow.
A backtest is useful only if it reflects enough of the real-world conditions that make trading hard. REALBT exists to make strategy evaluation more practical, structured, and repeatable before real money is involved.
Active Python backtesting project focused on straightforward workflows and realistic evaluation.
- Clone the Repository: First, clone the repository to your local machine using Git.
git clone https://github.com/username/realbt.git && cd realbt- Set Up the Environment
REALBT has dependencies that need to be installed. It is recommended to use a virtual environment to avoid conflicts with other Python packages.
2.1 Create a Virtual Environment:
python -m venv venv2.2 Activate the Virtual Environment:
- On Windows:
venv\Scripts\activate- On macos/Linux
source venv/bin/activate2.3 Install Dependencies
pip install -r requirements.txt- Verify Installation Run the CLI help command to ensure the package is installed and working correctly:
python realbt/cli.py --helpYou should see a list of available commands, such as new, fetch-data, and run.
- Create a New Project: Use the
newcommand to create a new backtesting project:
python realbt/cli.py new my_project -d /path/to/directoryThis will generate the following folder structure:
my_project/
├── data/
├── results/
├── strategies/
│ └── sample_strategy.py
└── config.yaml
- Fetch Historical Data
Fetch historical stock data using the fetch-data command. For example, to fetch Apple stock data for 2024:
python realbt/cli.py fetch-data AAPL 2024-01-01 2024-12-31 my_project/data/apple.csv- Define a Strategy
Edit the sample_strategy.py file in the strategies folder to define your trading strategy. For example:
from realbt.src.engine import BacktestEngine
def my_strategy(data):
# Example: Moving Average Crossover Strategy
data['SMA_50'] = data['Close'].rolling(window=50).mean()
data['SMA_200'] = data['Close'].rolling(window=200).mean()
signals = data['SMA_50'] > data['SMA_200']
return signals
engine = BacktestEngine()
engine.run(data_path="data/apple.csv", strategy=my_strategy)- Run the Backtest
Run the Backtest using the run command:
python realbt/cli.py run my_project/config.yamlThe results will be saved in the results folder, and you can visualize them using the built-in visualization tools.
- Extend the Framework
REALBT is modular and extensible. You can:
- Add custom cost models in the
costsdirectory. - Create new strategies in the
strategiesfolder. - Modify the backtesting engine to suit specific requirements.
For example, to add a custom transaction cost model:
def custom_transaction_cost(volume, price):
return 0.001 * volume * price # Example: 0.1% transaction costIntegrate it into your strategy:
from realbt.costs.custom_transaction_cost import custom_transaction_cost
def my_strategy_with_costs(data):
# Define strategy logic
...
# Apply custom transaction costs
costs = custom_transaction_cost(volume, price)
...-
What I'm thinking with REALBT strategy is to provide a lot of boilerplate Strategies that everyone can use and extend. The other advantage is the running from YAML, which can branch the process into multiple runs(multithreaded).
-
Another thing in this that I have figure out is how to interface this library to the users. Do they clone it and add strategies - how are they going to build the config.YAML? How do we provide it as a package?