Skip to main content

Numba accelerated minimalist trading simulator

Project description

Intro

  • Numba accelerated minimalist trading simulator

Usage

pip install fast-trading-simulator
import numpy as np
import talib as ta
from crypto_data_downloader.utils import load_pkl
from trading_models.utils import D_TYPE

from fast_trading_simulator.sim import map_trades, simulate

path = "./futures_data_2025-08-01_2025-11-20.pkl"
data: D_TYPE = load_pkl(path, gz=True)

ref_sym = "BTCUSDT"
price_idx = 1
delta = 0.05

T = len(data[ref_sym])
data = {k: v for k, v in data.items() if len(v) == T}
all_act = []
for sym, v in data.items():
    p = v[:, price_idx]
    obs = p / ta.KAMA(p, 20) - 1
    pos = np.where(obs < -delta, 1, 0)
    pos = np.where(obs > delta, -1, pos)
    lev = np.full(T, 20)
    timeout = np.full(T, 10)
    take_profit = np.full(T, 0.01)
    stop_loss = np.full(T, -0.9)
    act = np.array([pos, lev, timeout, take_profit, stop_loss]).T
    all_act.append(act)
market = np.array(list(data.values()))
action = np.array(all_act)
tot_fee = 1e-3
liq_fee = np.full(len(data), 0.02)

trades = simulate(market, action, tot_fee, liq_fee, use_ratio=0.2, alloc_ratio=0.01)
map_trades(trades, plot=True)

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.1.1.tar.gz (4.7 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.1.1-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fast_trading_simulator-0.1.1.tar.gz
  • Upload date:
  • Size: 4.7 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.1.1.tar.gz
Algorithm Hash digest
SHA256 4860d093dc1b02fa9b8a248377e1f204f9d6168120c976c2f0458d373226e707
MD5 42981cea43181173d21e38bc937dc5e1
BLAKE2b-256 0349a09be9aff9a40b9e5bb08d03f47d0e17c3b5d10d018fccb37adfcd2dd23f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fast_trading_simulator-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f9a4ec9507ce4f5a6abfdca567b23e4f672b2d30f77cc34e55aa73716055212f
MD5 a73cd71c9a01a7f4a4132a53335fdc0d
BLAKE2b-256 7f505f6dca892bd8169593b00db39e57197a79348bed5370b5ac0508b84aa8c6

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