npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

trader-backtest

v1.0.2

Published

High-performance C++ backtesting engine for trading strategies, with a Node.js native addon interface.

Readme

quant-demo

macOS only — Windows and Linux are not supported yet.

⚠️ Demo Data Only: This project runs exclusively on static / dummy demo historical data. It does not connect to live market data feeds, live brokerages, or execute live trades.

A C++ backtesting engine for trading strategies, with a Node.js native addon so you can call it directly from JavaScript.

You give it price history as a CSV, pick a strategy, and it tells you what trades it would have made, the final P&L, and how bad the worst drawdown was.


Prerequisites

This package compiles C++ on install. You need these installed before running anything.

1. Xcode Command Line Tools (gives you the C++ compiler and make)

xcode-select --install

If it says already installed, you're good.

2. Node.js 18+

Download from nodejs.org or via Homebrew:

brew install node

3. Python 3 (required by node-gyp internally)

Comes pre-installed on macOS. Verify:

python3 --version

If missing:

brew install python

Verify everything is in order:

node --version     # should be v18+
npm --version      # should be 9+
python3 --version  # any 3.x
clang++ --version  # should print Apple clang version...

Running the CLI

make
./quant_demo

Swap the strategy, pass your own CSV data, or tune the windows without touching code:

./quant_demo --strategy ma-crossover --short 5 --long 20
./quant_demo --csv /path/to/prices.csv
./quant_demo --csv data/template.csv
./quant_demo --list    # see what strategies are registered
./quant_demo --help

Running from JavaScript

npm install   # builds the native addon
node demo.js  # run the example
const { run, listStrategies } = require('./index');

const result = run({
  strategy:     'ma-crossover',
  shortWindow:  3,
  longWindow:   5,
  slippageRate: 0.0005,
  initialCash:  10000,
  csvPath:      './data/template.csv', // optional: path to custom CSV
});

console.log(result.profitLoss);     // 14.39
console.log(result.returnPct);      // 0.144
console.log(result.maxDrawdownPct); // 0.083
console.log(result.trades);         // [{ timestamp, type, quantity, price }]
console.log(result.equityCurve);    // [{ timestamp, value }]

All options are optional — defaults are used if you omit them (bundled demo dataset is used by default).


Using Your Own Data (CSV Template)

A ready-to-use CSV template is provided at data/template.csv.

CSV Format Requirements

timestamp,price
1700000000,100.00
1700086400,101.50
1700172800,99.75
  • Header: Must start with timestamp,price.
  • timestamp: Unix timestamp (seconds).
  • price: Number / float (closing or trade price).
  • One bar per row, sorted in ascending chronological order.

How to use your own CSV file

  1. Copy the template:

    cp data/template.csv data/my-stock.csv
  2. Populate it with your own historical price data.

  3. Pass the path to your file:

    CLI:

    ./quant_demo --csv data/my-stock.csv

    JavaScript:

    const result = run({
      csvPath: '/absolute/or/relative/path/to/my-stock.csv'
    });

Adding a Strategy

Create strategy/MyStrategy.hpp:

class MyStrategy : public Strategy {
public:
  Signal generateSignal(const PricePoint &point) override {
    // return Signal::BUY, Signal::SELL, or Signal::NONE
  }
  std::string getName() const override { return "My Strategy"; }
};

Register it in strategy/StrategyFactory.hpp:

#include "MyStrategy.hpp"

// inside the constructor:
add("my-strategy", [](Params p) -> std::unique_ptr<Strategy> {
  return std::unique_ptr<Strategy>(new MyStrategy());
});

Then just use it:

./quant_demo --strategy my-strategy

Nothing else needs to change.