Skip to content

Commit 463b8c8

Browse files
committed
add workflows, improve README and pyproject.toml
1 parent b0bd9c4 commit 463b8c8

File tree

4 files changed

+182
-21
lines changed

4 files changed

+182
-21
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Python package
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
jobs:
10+
build:
11+
12+
runs-on: ubuntu-latest
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
python-version: ["3.10", "3.11", "3.12", "3.13"]
17+
18+
steps:
19+
- uses: actions/checkout@v4
20+
- name: Set up Python ${{ matrix.python-version }}
21+
uses: actions/setup-python@v3
22+
with:
23+
python-version: ${{ matrix.python-version }}
24+
- name: Install dependencies
25+
run: |
26+
python -m pip install --upgrade pip
27+
python -m pip install flake8 pytest black isort
28+
if [ -f pyproject.toml ]; then
29+
pip install .[dev]
30+
fi
31+
- name: Lint with flake8
32+
run: |
33+
# Run flake8 and fail the build if there are any issues
34+
flake8 . --count --max-complexity=10 --max-line-length=88 --statistics
35+
- name: Lint with black
36+
run: |
37+
black --check .
38+
- name: Lint with isort
39+
run: |
40+
isort . --check-only
41+
- name: Test with pytest
42+
run: |
43+
pytest
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: Upload Python Package
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
permissions:
8+
contents: read
9+
10+
jobs:
11+
release-build:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
- uses: actions/setup-python@v5
18+
with:
19+
python-version: "3.x"
20+
21+
- name: Build release distributions
22+
run: |
23+
python -m pip install build
24+
python -m build
25+
26+
- name: Upload distributions
27+
uses: actions/upload-artifact@v4
28+
with:
29+
name: release-dists
30+
path: dist/
31+
32+
pypi-publish:
33+
runs-on: ubuntu-latest
34+
needs:
35+
- release-build
36+
permissions:
37+
id-token: write
38+
39+
environment:
40+
name: pypi
41+
42+
steps:
43+
- name: Retrieve release distributions
44+
uses: actions/download-artifact@v4
45+
with:
46+
name: release-dists
47+
path: dist/
48+
49+
- name: Publish release distributions to PyPI
50+
uses: pypa/gh-action-pypi-publish@release/v1
51+
with:
52+
packages-dir: dist/
53+
env:
54+
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
55+
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
56+
57+
conda-publish:
58+
runs-on: ubuntu-latest
59+
needs:
60+
- release-build
61+
62+
steps:
63+
- name: Install conda-build
64+
run: |
65+
sudo apt-get update
66+
sudo apt-get install -y conda
67+
conda install conda-build anaconda-client
68+
69+
- name: Retrieve release distributions
70+
uses: actions/download-artifact@v4
71+
with:
72+
name: release-dists
73+
path: dist/
74+
75+
- name: Build Conda package
76+
run: |
77+
conda-build .
78+
79+
- name: Upload Conda package
80+
run: |
81+
anaconda login --username ${{ secrets.ANACONDA_USERNAME }} --password ${{ secrets.ANACONDA_PASSWORD }}
82+
anaconda upload /path/to/your/conda/package.tar.bz2

README.md

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,42 @@
11
# kissbt
22

3-
`kissbt` (Keep It Simple Stupid Backtesting) is a Python library designed for backtesting trading strategies with simplicity and ease of use in mind. The library provides essential components for creating, running, and analyzing trading strategies.
3+
**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.
4+
5+
## Why kissbt?
6+
7+
- **🚀 Lightweight** – Minimal dependencies ensure fast installation and execution.
8+
- **📖 Simple API** – Lowers the barrier for traders new to backtesting.
9+
- **🔌 Extensible** – Modular architecture enables easy customization.
10+
- **📊 Essential Features** – Includes tools for data handling, strategy implementation, and performance evaluation.
411

512
## Features
613

7-
- **Modular Design**: The library is composed of several modules, each handling a specific aspect of the backtesting process.
8-
- **Strategy Implementation**: Easily implement custom trading strategies by extending the `Strategy` class.
9-
- **Broker Simulation**: Simulate trading with the `Broker` class, which manages orders, positions, and cash.
10-
- **Performance Analysis**: Analyze trading performance with the `Analyzer` class, which calculates key metrics like total return, Sharpe ratio, and drawdown.
11-
- **Data Handling**: Efficiently handle and preprocess market data using `pandas`.
12-
- **Visualization**: Plot equity curves and drawdowns to visualize strategy performance.
14+
✔️ Object-oriented design for intuitive strategy development
15+
✔️ Fast execution, even for large universes
16+
✔️ Supports long and short positions
17+
✔️ Built-in trade execution, position tracking, and P&L calculation
18+
✔️ Performance analysis with key trading metrics
19+
✔️ Backtesting with historical market data
20+
✔️ Modular components (Strategy, Broker, Engine, Analyzer)
1321

1422
## Installation
1523

16-
To install `kissbt`, clone the repository and install the dependencies:
24+
You can install `kissbt` using either `pip` or `conda`.
25+
26+
### Using pip
27+
28+
To install `kissbt` via `pip`, run the following command:
29+
30+
```sh
31+
pip install kissbt
32+
```
33+
34+
### Using conda
35+
36+
To install `kissbt` via `conda`, run the following command:
1737

18-
```bash
19-
git clone https://github.com/FinBlobs/kissbt.git
20-
cd kissbt
21-
pip install -r requirements.txt
38+
```sh
39+
conda install kissbt
2240
```
2341

2442
## Usage
@@ -32,14 +50,14 @@ from kissbt.strategy import Strategy
3250
from kissbt.entities import Order, OrderType
3351

3452
class MyStrategy(Strategy):
35-
def generate_orders(self, current_data, current_datetime, previous_data=None, previous_datetime=None):
53+
def generate_orders(self, current_data, current_datetime):
3654
# Example: Buy if the close price is above the 128-day SMA
37-
for ticker in current_data.index.get_level_values('ticker').unique():
38-
close_price = current_data.loc[(current_datetime, ticker), 'close']
39-
sma_128 = current_data.loc[(current_datetime, ticker), 'sma_128']
55+
for ticker in current_data.index:
56+
close_price = current_data.loc[ticker, "close"]
57+
sma_128 = current_data.loc[ticker, "sma_128"]
4058
if close_price > sma_128:
4159
order = Order(ticker=ticker, size=10, order_type=OrderType.OPEN)
42-
self.broker.open_orders.append(order)
60+
self._broker.place_order(order)
4361
```
4462

4563
### 2. Set Up the Broker
@@ -49,7 +67,7 @@ Initialize the `Broker` with starting capital, fees, and other parameters:
4967
```python
5068
from kissbt.broker import Broker
5169

52-
broker = Broker(start_capital=100000, fees=0.001, tax_rate=0.2)
70+
broker = Broker(start_capital=100000, fees=0.001)
5371
```
5472

5573
### 3. Run the Backtest
@@ -93,7 +111,7 @@ This project is licensed under the Apache License 2.0. See the [LICENSE](LICENSE
93111

94112
## Contributing
95113

96-
Contributions are welcome! Please feel free to submit a Pull Request.
114+
We welcome contributions! If you have ideas, bug fixes, or feature requests, feel free to open an issue or submit a pull request.
97115

98116
## Contact
99117

pyproject.toml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,38 @@ build-backend = "setuptools.build_meta"
55
[project]
66
name = "kissbt"
77
version = "0.1.0"
8-
description = "A brief description of the project."
8+
description = "The keep it simple backtesting framework for Python."
99
readme = "README.md"
1010
authors = [
1111
{ name = "Adrian Hasse", email = "adrian.hasse@finblobs.com" }
1212
]
13+
maintainers = [
14+
{ name = "Adrian Hasse", email = "adrian.hasse@finblobs.com" }
15+
]
1316
license = { file = "LICENSE" }
1417
classifiers = [
1518
"Programming Language :: Python :: 3",
1619
"License :: OSI Approved :: Apache Software License",
1720
"Operating System :: OS Independent"
1821
]
19-
dependencies = ["pandas"]
22+
dependencies = [
23+
"numpy",
24+
"pandas",
25+
"matplotlib"
26+
]
2027
requires-python = ">=3.10"
2128

29+
[project.optional-dependencies]
30+
dev = [
31+
"pytest",
32+
"pytest-mock",
33+
"flake8",
34+
"black",
35+
"isort",
36+
"yfinance",
37+
"pyarrow",
38+
]
39+
2240
[project.urls]
2341
homepage = "https://github.com/FinBlobs/kissbt"
2442
bug-tracker = "https://github.com/FinBlobs/kissbt/issues"

0 commit comments

Comments
 (0)