Backtest.Net 4.1.14

dotnet add package Backtest.Net --version 4.1.14
                    
NuGet\Install-Package Backtest.Net -Version 4.1.14
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Backtest.Net" Version="4.1.14" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Backtest.Net" Version="4.1.14" />
                    
Directory.Packages.props
<PackageReference Include="Backtest.Net" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Backtest.Net --version 4.1.14
                    
#r "nuget: Backtest.Net, 4.1.14"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Backtest.Net@4.1.14
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Backtest.Net&version=4.1.14
                    
Install as a Cake Addin
#tool nuget:?package=Backtest.Net&version=4.1.14
                    
Install as a Cake Tool

High-Performance Backtest.Net

NuGet NuGet Downloads Build Status .NET

A high-performance backtesting engine for algorithmic trading strategies in .NET.


Introduction

High-Performance Backtest.Net is a specialized backtesting library designed for quantitative trading applications. It processes multi-timeframe candlestick data across multiple symbols, simulating tick-by-tick strategy execution with proper warmup periods and OHLC handling.

Key Characteristics

  • Multi-Symbol Support: Process multiple trading symbols in parallel
  • Multi-Timeframe: Handle multiple timeframes per symbol with automatic synchronization
  • Performance Optimized: 10 iteratively optimized engine versions with zero-allocation patterns
  • Data Splitting: Intelligent data partitioning for memory-efficient large-scale backtests
  • Cancellation Support: Graceful async cancellation with progress tracking

Features

Feature Description
EngineV10 Latest engine with Span-based iteration, binary search, and parallel processing
SymbolDataSplitter Partitions large datasets into memory-efficient chunks
Warmup Handling Configurable warmup candle counts per timeframe
OHLC Simulation Accurate current-candle OHLC handling during backtest
Progress Tracking Real-time progress from 0-100%
SIMD Acceleration Leverages SimdLinq for vectorized operations

Performance Optimizations

The library implements sophisticated performance techniques:

  • Zero-Allocation Hot Paths: Uses Span<T> and CollectionsMarshal.AsSpan
  • Parallel Processing: Parallel.ForEach for symbol-level parallelism
  • Binary Search: O(log n) candlestick lookups
  • Aggressive Inlining: [MethodImpl(MethodImplOptions.AggressiveInlining)]
  • Sealed Classes: JIT optimization hints

Installation

Package Manager

dotnet add package Backtest.Net

PackageReference

<PackageReference Include="Backtest.Net" Version="4.1.11" />

Requires .NET 9.0 or later.


Quickstart

Basic Engine Usage

using Backtest.Net.Engines;
using Backtest.Net.SymbolsData;
using Backtest.Net.SymbolDataSplitters;
using Backtest.Net.Timeframes;
using Models.Net.Enums;

// 1. Prepare your symbol data (candlesticks per timeframe)
var symbolsData = new List<SymbolDataV2>
{
    new SymbolDataV2
    {
        Symbol = "BTCUSDT",
        Timeframes = new List<TimeframeV2>
        {
            new TimeframeV2
            {
                Timeframe = CandlestickInterval.OneMinute,
                Candlesticks = yourOneMinuteCandles
            },
            new TimeframeV2
            {
                Timeframe = CandlestickInterval.OneHour,
                Candlesticks = yourOneHourCandles
            }
        }
    }
};

// 2. Split data for efficient processing
var splitter = new SymbolDataSplitterV2(
    daysPerSplit: 30,
    warmupCandlesCount: 100,
    backtestingStartDateTime: new DateTime(2024, 1, 1)
);

var splitData = await splitter.SplitAsyncV2(symbolsData);

// 3. Create and configure the engine
var engine = new EngineV10(
    warmupCandlesCount: 100,
    sortCandlesInDescOrder: false,
    useFullCandleForCurrent: false
);

// 4. Set up your strategy callback
engine.OnTick = async (symbolData) =>
{
    foreach (var symbol in symbolData)
    {
        var latestCandle = symbol.Timeframes[0].Candlesticks[^1];
        // Your strategy logic here
        Console.WriteLine($"{symbol.Symbol}: Close = {latestCandle.Close}");
    }
};

// 5. Run the backtest
await engine.RunAsync(splitData);

Console.WriteLine($"Progress: {engine.GetProgress()}%");

With Cancellation Support

using var cts = new CancellationTokenSource();

engine.OnCancellationFinishedDelegate = () =>
{
    Console.WriteLine("Backtest cancelled gracefully");
};

// Cancel after 30 seconds
cts.CancelAfter(TimeSpan.FromSeconds(30));

await engine.RunAsync(splitData, cts.Token);

Engine Versions

Engine Description Use Case
EngineV1-V7 Legacy engines Backward compatibility
EngineV8 SymbolDataV2 support Standard workloads
EngineV9 Optimized OHLC handling Memory-sensitive scenarios
EngineV10 Full optimization suite Production recommended

Use EngineV10 for new projects. It provides the best performance through zero-allocation patterns and parallel processing.


Development

Prerequisites

Build

git clone https://github.com/islero/High-Performance-Backtest.Net.git
cd High-Performance-Backtest.Net
dotnet build

Test

dotnet test

Benchmark

cd benchmarks/Backtest.Net.Benchmarks
dotnet run -c Release

Format

dotnet format

Versioning & Releases

This project follows Semantic Versioning.

Branch Version Format NuGet Feed
master X.Y.Z (stable) nuget.org
beta X.Y.Z-beta.N (prerelease) nuget.org

Release Process

  1. Update version in src/Backtest.Net/Backtest.Net.csproj
  2. Create GitHub Release with tag vX.Y.Z
  3. CI automatically publishes to NuGet

Contributing

Contributions are welcome! Please read CONTRIBUTING.md for guidelines.


License

See the LICENSE file for details.


Acknowledgments


<p align="center"> Built for the algorithmic trading community </p>

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.1.14 69 12/22/2025
4.1.12 69 12/22/2025

Added volume to candlesticks. Upgraded to EngineV10 with performance optimizations.