Skip to main content

Numba accelerated minimalist trading simulator

Project description

Intro

  • Numba accelerated minimalist trading 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("futures_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],
    "position_hist": trades[:, 2],
    "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, 482, 3) (time, symbols, fields)
482 symbols: ['BTCUSDT', 'ETHUSDT', 'BCHUSDT']...
3 fields: ['open_time', 'close', 'position']

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

fast_trading_simulator-0.0.2.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fast_trading_simulator-0.0.2-py3-none-any.whl (3.3 kB view details)

Uploaded Python 3

File details

Details for the file fast_trading_simulator-0.0.2.tar.gz.

File metadata

  • Download URL: fast_trading_simulator-0.0.2.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

Hashes for fast_trading_simulator-0.0.2.tar.gz
Algorithm Hash digest
SHA256 6a24a5e6ed60b9b05d51bc6deab12ee9ab092c594ae8a161a0ee450102fcc341
MD5 366b85ecba9e2e928454124704100109
BLAKE2b-256 58c3b6097e36e9aa819d1f7c18bb4cf9d88439ced11b59aae6a26cb7154d1b50

See more details on using hashes here.

File details

Details for the file fast_trading_simulator-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for fast_trading_simulator-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9534f7c34b14a767f77e658550d7ab0a23e36a5e68627557cce8cef981f195a7
MD5 d12a38ee4f8235ccac1ea58d83eea2ba
BLAKE2b-256 c3fb4db4f6b5ca568d55edaa05dcee2e5ea250935b139d86521e51b069e251ca

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page