Skip to content

yash-srivastava19/REALBT

Repository files navigation

REALBT

REALBT is a realistic backtesting engine for evaluating trading strategies on historical market data.

What it is

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.

Why it matters

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.

Current status

Active Python backtesting project focused on straightforward workflows and realistic evaluation.

How to use REALBT?

  1. Clone the Repository: First, clone the repository to your local machine using Git.
git clone https://github.com/username/realbt.git && cd realbt
  1. 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 venv

2.2 Activate the Virtual Environment:

  • On Windows:
venv\Scripts\activate
  • On macos/Linux
source venv/bin/activate

2.3 Install Dependencies

pip install -r requirements.txt
  1. Verify Installation Run the CLI help command to ensure the package is installed and working correctly:
python realbt/cli.py --help

You should see a list of available commands, such as newfetch-data, and run.

  1. Create a New Project: Use the new command to create a new backtesting project:
python realbt/cli.py new my_project -d /path/to/directory

This will generate the following folder structure:

my_project/
├── data/
├── results/
├── strategies/
│   └── sample_strategy.py
└── config.yaml
  1. 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

  1. 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)

  1. Run the Backtest

Run the Backtest using the run command:

python realbt/cli.py run my_project/config.yaml

The results will be saved in the results folder, and you can visualize them using the built-in visualization tools.


  1. Extend the Framework

REALBT is modular and extensible. You can:

  • Add custom cost models in the costs directory.
  • Create new strategies in the strategies folder.
  • Modify the backtesting engine to suit specific requirements.

For example, to add a custom transaction cost model:

def custom_transaction_cost(volumeprice):
    return 0.001 * volume * price  # Example: 0.1% transaction cost

Integrate 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(volumeprice)
    ...

Future Works

  • 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?

About

REAListic BackTesting is a simple backtesting framework for your portfolio that just works.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages