Skip to content

A quant-centric platform for backtesting and live trading with a unified and trader-friendly interface for developing, backtesting, and deploying dependable trading strategies.

License

Notifications You must be signed in to change notification settings

yepengding/quantstorm

Repository files navigation

Quantstorm

Quantstorm is a quant-centric platform for backtesting and live trading, providing a unified and trader-friendly interface for developing, backtesting, and deploying dependable trading strategies.

Key Features

  • Unified backtesting and live trading framework
  • Stateful strategy abstraction
  • Broker abstraction for multi-exchange compatibility
  • K-line data abstraction
  • Extensible indicator

Disclaimer

This software is provided for educational and research purposes only. It is not intended as financial advice or an invitation to trade. Any use of this software for real-money trading is ENTIRELY AT YOUR OWN RISK.

You should NEVER RISK FUNDS YOU ARE NOT PREPARED TO LOSE. The authors, contributors, and any affiliated parties * make NO guarantees regarding the accuracy, reliability, or profitability of the software* and accept NO liability for any direct or indirect loss arising from its use.

Before deploying any trading strategy in live markets, YOU MUST FIRST BACKTEST IT AND RUN IT IN A SIMULATED ENVIRONMENT to understand its behavior, limitations, and potential outcomes.

It is strongly recommended that you possess solid programming and trading knowledge. You are encouraged to review and audit the source code to fully understand the underlying mechanisms.


Getting Started

1. Install Dependencies

Install pnpm, then run:

$ pnpm install

2. Set Up Environment Variables

Copy .env.example to .env and fill in the configuration.


Strategy

All strategies in Quantstorm are implemented by extending the StrategyAbstract base class and must be explicitly registered in the StrategyRegistry.

Initialization

init(args: string) is called once at the start of strategy execution. It is responsible for setting up the strategy’s internal state and dependencies.

  • The args parameter (a JSON string) allows for dynamic configuration.
  • Typical args include:
    • Trading pair (e.g., BTC/USDT)
    • Order size
    • Selected exchange/broker
    • Any strategy-specific parameters or flags

Periodical Execution

next() contains the core trading logic and is executed at fixed intervals. It is used to react to new market data, generate trading signals, and perform trading actions (e.g., long/short).

  • The interval defines the period between two strategy executions
    • Configurable interval for backtesting (e.g., 1m, 15m)
    • Defaults to 5 seconds for live trading

Example


Backtesting

With Test Cases (Recommended)

  1. Create a mock service: BacktestService (see backtest.service.spec.ts)
  2. Write a unit test:
it("should backtest the strategy", async () => {
  const result: BacktestResult = await service.run(
    strategyInstance, // A strategy object
    strategyArgs, // Arguments to initialize the strategy
    startTimestamp, // Backtest start timestamp
    endTimstamp, // Backtest end timestamp
    executionInterval // Backtest execution interval
  );
});
  1. Run the test case and obtain backtesting result instance result: BacktestResult

Build Backtesting Data

Modify and run the test case should build Binance K-line data set in backtest.feeder.service.spec.ts

Example

Backtest Demo strategy by running the test case should backtest the demo strategy in backtest.service.spec.ts

With Web Service

Start Quantstorm

# development
$ npm run start

# watch mode
$ npm run start:dev

# production mode
$ npm run start:prod

Build Backtesting Data

Call the endpoint /backtest/build/kline with arguments:

  • base: Base currency (e.g., BTC)
  • quote: Quote currency (e.g., USDT)
  • interval: Strategy execution interval (e.g., 1m, 15m)
  • start: Start date in YYYY-MM-DD format
  • end: End date in YYYY-MM-DD format

Backtest Strategy with UI

Access the endpoint /backtest/strategy/{name} with arguments:

  • {name}: Strategy name (e.g., Demo)
  • start: Start timestamp (UNIX format)
  • end: End timestamp (UNIX format)
  • interval: Strategy execution interval (e.g., 1m, 15m)
  • base: Base currency (e.g., BTC) used for visualization
  • quote: Quote currency (e.g., USDT) used for visualization and balance calculation
  • args: Arguments to initialize the strategy

Example

  1. Locally run Quantstorm on port 8888
  2. Backtest the Demo strategy via the URL below
http://localhost:8888/backtest/strategy/Demo?start=1722427200&end=1722454200&interval=15m&base=BTC&quote=USDT&args={"base":"BTC","quote":"USDT","size":1,"interval":"30m"}
  1. Obtain the backtesting result in HTML Backtest Result

Live Trading

Deployment

  1. Install Docker Compose
  2. In the root directory:
$ docker compose up -d

This launches:

  • Quantstorm
  • MariaDB
  • Adminer

Execute Strategy

Call the endpoint /executor/execute/{name}/{id} with arguments:

  • {name}: Strategy name
  • {id}: Custom unique identifier for the strategy instance
  • args: Arguments to initialize the strategy

Stop Strategy

Access the endpoint /executor/stop/{id} with arguments:

  • {id}: Custom unique identifier for the strategy instance

About

A quant-centric platform for backtesting and live trading with a unified and trader-friendly interface for developing, backtesting, and deploying dependable trading strategies.

Resources

License

Stars

Watchers

Forks

Packages

No packages published