Wickra.Backtest
0.1.9
dotnet add package Wickra.Backtest --version 0.1.9
NuGet\Install-Package Wickra.Backtest -Version 0.1.9
<PackageReference Include="Wickra.Backtest" Version="0.1.9" />
<PackageVersion Include="Wickra.Backtest" Version="0.1.9" />
<PackageReference Include="Wickra.Backtest" />
paket add Wickra.Backtest --version 0.1.9
#r "nuget: Wickra.Backtest, 0.1.9"
#:package Wickra.Backtest@0.1.9
#addin nuget:?package=Wickra.Backtest&version=0.1.9
#tool nuget:?package=Wickra.Backtest&version=0.1.9
<p align="center"> <a href="https://wickra.org"><img src="https://raw.githubusercontent.com/wickra-lib/.github/main/profile/wickra-banner.svg?v=514-8" alt="Wickra Backtest — backtest and live are byte-identical" width="100%"></a> </p>
Wickra Backtest — C#
▶ Live demo: run a strategy in your browser and watch the equity curve build bar by bar — backtest-live.wickra.org · zero backend, the same engine this repository ships, compiled to WebAssembly.
Backtest and live — for C#. dotnet add package Wickra.Backtest — prebuilt native library, no system dependencies.
C# binding for the wickra-backtest engine. It calls the stable C ABI through P/Invoke, so the results are byte-identical to the Rust, Python, Node.js, WASM, Java, Go, C/C++ and R bindings: one engine kernel behind every language.
Install
dotnet add package Wickra.Backtest
The native library ships prebuilt per platform under runtimes/<rid>/native/,
selected automatically. There is nothing to compile. Targets .NET 8 and later.
Requirements
- .NET 8 SDK
- The native library
wickra_backtest(built from the C-ABI crate)
Building from this repository (contributors)
Build the native library.
cargo build -p wickra-backtest-c # debug -> target/debug
cargo build -p wickra-backtest-c --release # release -> target/release
The test project copies the native library next to the test assembly; for your
own app, ensure wickra_backtest.dll / .so / .dylib is on the load path.
Test.
dotnet test Wickra.Backtest.Tests/Wickra.Backtest.Tests.csproj
Quick start
using Wickra.Backtest;
double[] open = { 100.0, 102.0, 104.0, 98.0 };
double[] high = { 101.0, 103.0, 104.0, 98.0 };
double[] low = { 100.0, 102.0, 99.0, 97.0 };
double[] close = { 101.0, 103.0, 99.0, 97.0 };
string spec =
"{\"symbol\":\"x\",\"timeframe\":\"1h\",\"indicators\":{}," +
"\"entry\":{\"gt\":[{\"price\":\"close\"},100]}," +
"\"exit\":{\"lt\":[{\"price\":\"close\"},100]}," +
"\"sizing\":{\"type\":\"fixed_qty\",\"qty\":1}}";
string reportJson = Backtester.Run(open, high, low, close, spec: spec, capital: 10_000.0);
Console.WriteLine(reportJson);
Backtester.Run(open, high, low, close, volume?, time?, spec, capital) returns
the BacktestReport JSON string. volume/time default to zeros / 0..n. An
invalid spec throws InvalidOperationException; no panic crosses the boundary.
The same strategy also runs one bar at a time, which is what makes a backtest and a live loop the same code path -- swap the array for a socket and nothing else changes:
using var bt = new StreamingBacktest(spec, capital: 10_000.0);
foreach (var bar in feed)
{
bt.Step(bar.Open, bar.High, bar.Low, bar.Close, bar.Volume, bar.Time);
Console.WriteLine($"{bt.NumTrades} {bt.LatestEquityJson()}");
}
string reportJson = bt.FinishJson();
StreamingBacktest owns a native handle, so dispose it -- using, Dispose(),
or FinishJson(), which ends the run and releases it. volume defaults to 0 and
time to the number of bars fed so far. Strategies reading a side feed drive the
run with StepJson, passing { "candle": ..., "feeds": ... } per bar. Using a
finished run throws ObjectDisposedException.
Benchmark
benchmarks/ reports this binding's throughput over the shared core. It measures
the call overhead of [LibraryImport] P/Invoke over the C ABI, not a cross-library ratio (the same Rust core runs
under every binding) — see the repository
BENCHMARKS.md for the
numbers, the machine and how each harness is run.
Documentation
The full guide, the spec reference and the API documentation live in the main repository and the documentation site:
Repository: https://github.com/wickra-lib/wickra-backtest
Docs (guides, spec reference, cookbook): https://backtest.wickra.org
Runnable example:
examples/csharp/Repository: https://github.com/wickra-lib/wickra-backtest
Strategy spec reference: STRATEGY_SPEC.md
Cookbook: COOKBOOK.md
Built on Wickra: https://github.com/wickra-lib/wickra · https://docs.wickra.org
The same StrategySpec runs identically across Rust, Python, Node.js, WASM, C,
C++, C#, Go, Java and R — one engine kernel, byte-identical reports.
Wickra Backtest ships native bindings for Python, Node.js, WASM and Rust, plus a C ABI hub that any
C-capable language (C, C++, C#, Go, Java, R) links against — all forwarding to the
same data-driven, unsafe-forbidden Rust core.
Security
Found a security issue? Please don't open a public issue. Report it privately
via the repository's Security tab ("Report a vulnerability") or email
support@wickra.org with a subject line starting [wickra security]. Full
policy: https://github.com/wickra-lib/wickra-backtest/blob/main/SECURITY.md.
Disclaimer
Not a trading system. Backtest results are deterministic transforms of the input data — they are not financial advice and are not indicative of future performance. Any use in a live trading context is at your own risk. The software is provided as is, without warranty of any kind; see the license files for the full terms.
License
Licensed under either of Apache-2.0 or MIT at your option.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. 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. |
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.