Numba accelerated minimalist trading simulator
Project description
Intro
Numbaacceleratedminimalisttrading simulator- In
28 lines:- Multi-symbol
- Multi-position, long & short, continuous from -1 to 1
- Timeout, take-profit, stop-loss, trading fee
- Initial cash, minimum cash, allocation ratio (risk control)
Usage
pip install fast-trading-simulator
from typing import Dict
import numpy as np
from crypto_data_downloader.utils import load_pkl
from trading_models.utils import plot_general
from fast_trading_simulator.simulate import simulate
data: Dict = load_pkl("sim_data_2025-07-01_2025-08-01.pkl", gz=True)
sim_data: Dict[str, Dict[str, np.ndarray]] = data["sim_data"]
# for sym, x in sim_data.items():
# x["position"] = custom_strategy(x["close"])
symbols = list(sim_data.keys())
fields = list(sim_data["BTCUSDT"].keys())
arr = np.array([list(x.values()) for x in sim_data.values()])
arr = arr.transpose((2, 0, 1))
print(f"data keys: {list(data.keys())}")
print(f"arr.shape: {arr.shape} (time, symbols, fields)")
print(f"{len(symbols)} symbols: {symbols[:3]}...")
print(f"{len(fields)} fields: {fields}")
"""
timeout: int, number of time steps
take_profit: float, e.g. 0.01 (1%)
stop_loss: float, e.g. -0.3 (-30%)
fee: float, buy+sell total, e.g. 7e-4 (0.07%)
"""
data["sim_data"] = arr
trades = np.array(simulate(**data, init_cash=10e3, alloc_ratio=0.005))
plots = {
f"worth ({len(trades)} trades)": trades[:, -1],
"cash_hist": trades[:, -4],
"duration_hist": trades[:, -3],
"profit_hist": trades[:, -2],
}
plot_general(plots, "simulate")
- Output
data keys: ['sim_data', 'timeout', 'take_profit', 'stop_loss', 'fee']
arr.shape: (8417, 401, 3) (time, symbols, fields)
401 symbols: ['BTCUSDT', 'ETHUSDT', 'BNBUSDT']...
3 fields: ['open_time', 'close', 'position']
Project details
Release history Release notifications | RSS feed
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 fast_trading_simulator-0.0.1.tar.gz.
File metadata
- Download URL: fast_trading_simulator-0.0.1.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
618316a3cab3f7c921db9a239cabb1a6a2ec10da3aa9688524b56c62332a2648
|
|
| MD5 |
d7d0b1aa34ba409258681b8768d05a22
|
|
| BLAKE2b-256 |
91b35e9b58035c6d8cc6776d1d3f1c1f31e98f34af1c26d1bb94d91c836cae4e
|
File details
Details for the file fast_trading_simulator-0.0.1-py3-none-any.whl.
File metadata
- Download URL: fast_trading_simulator-0.0.1-py3-none-any.whl
- Upload date:
- Size: 3.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
deccb069304b3b2a92862eb76aa8ed50b3ad271bb507959ade4254856ce04d60
|
|
| MD5 |
79aeae0bc4b77854571085b33b3fbf98
|
|
| BLAKE2b-256 |
f17b0530c86cca510e4866e703aa0438380301bb02373ab849893775bb943e1f
|