Skip to main content

BrintScript: Backtesting System Documentation

Welcome to the BrintScript backtesting system documentation. This guide covers how to write and execute trading strategies using our JavaScript-based strategy sandbox environment.

Overview

BrintScript is a sandboxed JavaScript environment for writing and testing trading strategies. Key features:

  • Write strategies in JavaScript
  • Access to built-in technical indicators
  • Create custom indicators
  • Compute results with analysis and metrics

Is this Event Driven or Vectorized?

Brint uses a hybrid approach that leans towards event-driven processing:

Event-Driven Processing

  • Trade execution occurs chronologically minute by minute
  • Account state (capital, positions, etc.) from previous minutes affects future trading decisions
  • Strategy logic can react to the results of previous trades

What is Vectorized Processing?

Traditional vectorized systems process the entire historical dataset at once:

  • All trades across all time periods are calculated simultaneously
  • Faster computation but less realistic since future trades can't consider previous trade outcomes
  • Position sizing doesn't account for actual capital changes from previous trades

How Brint Works

Our system uses a balanced approach where we process data minute-by-minute in chronological order, but vectorise each minute:

  1. For each minute, all available assets are analyzed simultaneously in a vectorised way
  2. Trading signals for that minute are generated in parallel
  3. Trades for that minute are executed as a batch

This means that position sizing and trade limits apply independently to each minute. For example, if your strategy limits open positions to 5 trades maximum and 10 valid signals occur within the same minute, all 10 trades will execute. However, in the next minute, no new trades will open until positions are closed.

This approach prioritizes realistic backtesting results while maintaining reasonable performance on consumer hardware. You get most of the benefits of event-driven processing (realistic capital management, trade sequencing) while still keeping computation time manageable.

Compute Limits

Your strategy is limited to 2GB memory and a one hour timeout for this initial beta test. We recommend ensuring that you do not hold large objects or run significant loops, as this may result in your backtest failing. If you require higher limits, join our discord server and open up a ticket; should there be no malicious intent, we will happily run your strategy with higher limits :)

Whilst the full access model allows you to backtest an unlimited number of days, with full access to data from May 30th to December 1st 2024, the beta test is restricted to one day backtests from May 30th to July 31st. More access will be enabled as the beta test progresses, before pushing to a freemium pricing model!

Performance Tips

To optimize your strategy's performance and stay within compute limits:

  1. Use efficient data structures:
    • Prefer Map over Array.find() for lookups (O(1) vs O(n))
    • Use Set for quick membership testing
  2. Avoid memory leaks:
    • Clear temporary collections when no longer needed
    • Don't accumulate historical data unnecessarily
  3. Optimize loops:
    • Precompute values outside of loops where possible
    • Break early from loops when conditions are met
  4. Cache calculations:
    • Store frequently accessed computed values
    • Avoid recalculating the same values repeatedly