The keep it simple backtesting framework for Python.
Project description
kissbt
kissbt, the keep it simple backtesting framework, is a lightweight and user-friendly Python framework for backtesting trading strategies. It focuses on simplicity, performance, and ease of extensibility while providing essential tools for effective backtesting.
Why kissbt?
- 🚀 Lightweight – Minimal dependencies ensure fast installation and execution.
- 📖 Simple API – Lowers the barrier for traders new to backtesting.
- 🔌 Extensible – Modular architecture enables easy customization.
- 📊 Essential Features – Includes tools for data handling, strategy implementation, and performance evaluation.
Features
✔️ Object-oriented design for intuitive strategy development ✔️ Fast execution, even for large universes ✔️ Supports long and short positions ✔️ Built-in trade execution, position tracking, and P&L calculation ✔️ Performance analysis with key trading metrics ✔️ Backtesting with historical market data ✔️ Modular components (Strategy, Broker, Engine, Analyzer)
Installation
You can install kissbt using either pip or conda.
Using pip
To install kissbt via pip, run the following command:
pip install kissbt
Using conda
To install kissbt via conda, run the following command:
conda install kissbt
Usage
1. Define a Strategy
Create a custom strategy by extending the Strategy class and implementing the generate_orders method:
from kissbt.strategy import Strategy
from kissbt.entities import Order, OrderType
class MyStrategy(Strategy):
def generate_orders(self, current_data, current_datetime):
# Example: Buy if the close price is above the 128-day SMA
for ticker in current_data.index:
close_price = current_data.loc[ticker, "close"]
sma_128 = current_data.loc[ticker, "sma_128"]
if close_price > sma_128:
order = Order(ticker=ticker, size=10, order_type=OrderType.OPEN)
self._broker.place_order(order)
2. Set Up the Broker
Initialize the Broker with starting capital, fees, and other parameters:
from kissbt.broker import Broker
broker = Broker(start_capital=100000, fees=0.001)
3. Run the Backtest
Use the Engine to run the backtest with your strategy and market data:
from kissbt.engine import Engine
import pandas as pd
# Load market data
data = pd.read_csv('market_data.csv', parse_dates=['date'])
# Initialize strategy and engine
strategy = MyStrategy(broker)
engine = Engine(broker, strategy)
# Run the backtest
engine.run(data)
4. Analyze Performance
Use the Analyzer to calculate and display performance metrics:
from kissbt.analyzer import Analyzer
analyzer = Analyzer(broker)
metrics = analyzer.get_performance_metrics()
print(metrics)
Examples
Check out the examples directory for more detailed examples and use cases.
License
This project is licensed under the Apache License 2.0. See the LICENSE file for details.
Contributing
We welcome contributions! If you have ideas, bug fixes, or feature requests, feel free to open an issue or submit a pull request.
Contact
For any questions or inquiries, please contact Adrian Hasse at adrian.hasse@finblobs.com.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kissbt-0.1.3.tar.gz.
File metadata
- Download URL: kissbt-0.1.3.tar.gz
- Upload date:
- Size: 27.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ceee21a99ee787bff3b5ddd73b4ab1566ac42f5894160729b0726644db69062c
|
|
| MD5 |
e7733cedd4f9ac22bb829f27a3270150
|
|
| BLAKE2b-256 |
cd5d73b5fa6a079c3cae1cbb711b3aab3f0b28d7387c96e5446497ff2fb7f5cc
|
Provenance
The following attestation bundles were made for kissbt-0.1.3.tar.gz:
Publisher:
python-publish.yaml on FinBlobs/kissbt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kissbt-0.1.3.tar.gz -
Subject digest:
ceee21a99ee787bff3b5ddd73b4ab1566ac42f5894160729b0726644db69062c - Sigstore transparency entry: 171542001
- Sigstore integration time:
-
Permalink:
FinBlobs/kissbt@21b6217599459ee77e142afb78fa580bce574c46 -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/FinBlobs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yaml@21b6217599459ee77e142afb78fa580bce574c46 -
Trigger Event:
release
-
Statement type:
File details
Details for the file kissbt-0.1.3-py3-none-any.whl.
File metadata
- Download URL: kissbt-0.1.3-py3-none-any.whl
- Upload date:
- Size: 22.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
261ee80a1cc3bec5429ae8cf2900d59d63d757d82515fc9a3949359b06aafe48
|
|
| MD5 |
2d2452769ab692a54a9c2b80c98fabad
|
|
| BLAKE2b-256 |
471f4cd32ecc4cc28a97b9df9b105d834cf5d53a91f8cec6f5f7701790e3ddd8
|
Provenance
The following attestation bundles were made for kissbt-0.1.3-py3-none-any.whl:
Publisher:
python-publish.yaml on FinBlobs/kissbt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kissbt-0.1.3-py3-none-any.whl -
Subject digest:
261ee80a1cc3bec5429ae8cf2900d59d63d757d82515fc9a3949359b06aafe48 - Sigstore transparency entry: 171542002
- Sigstore integration time:
-
Permalink:
FinBlobs/kissbt@21b6217599459ee77e142afb78fa580bce574c46 -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/FinBlobs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yaml@21b6217599459ee77e142afb78fa580bce574c46 -
Trigger Event:
release
-
Statement type: