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 🙏

© 2025 – Pkg Stats / Ryan Hefner

trading-cycle

v1.0.2

Published

A lightweight, modular core library designed for backtesting trading strategies in financial markets.

Readme

Trading Cycle

npm version Build Status Codecov code style: prettier

bundle size bundle minzipped size dependencies

A lightweight, modular core library designed for backtesting trading strategies in financial markets.

Installation

Install the full or light version depending on your use case:

# Full version (with built-in indicators and helpers)
npm install trading-cycle

# Light version (core only)
npm install trading-cycle

Usage

Full Version

import {
  Candles,
  PositiveValues,
  NegativeValues,
  Renko,
  TimeRenko,
  TestLogic,
  PositiveTimeLength,
  NegativeTimeLength,
  FakeTrader,
  LogCandle,
  RenkoCounter
} from 'trading-cycle/full';

Light Version

import { TradingCycle } from 'trading-cycle/light';

Versions

  • Full: Includes core, built-in indicators, helpers, and utility functions.
  • Light: Contains only the core functionality — TradingCycle class and abstract handler interfaces.

Built-in Handlers

Trading Cycle ships with a set of predefined handlers you can use out of the box:

  Candles,
  PositiveValues,
  NegativeValues,
  Renko,
  TimeRenko,
  TestLogic,
  PositiveTimeLength,
  NegativeTimeLength,
  FakeTrader,
  LogCandle,
  RenkoCounter

Default Preset Configuration

A default preset is provided under trading-cycle/config, pre-wiring common handlers with sensible defaults (e.g. Renko bar size of 0.05):

import defaultPreset from 'trading-cycle/config';

This preset includes handlers such as:

  • candles
  • log-candles
  • renko-0.05
  • time-renko
  • renko-counter
  • test-logic
  • fake-trader

Customize or extend it by supplying your own HandlerConfig[] when creating TradingCycle.

Handler Example

Below is a concise description of a custom handler, illustrating how you can extend the core functionality:

  1. Class Declaration
    Create a class that extends AbstractHandler.
  2. Internal State
    Define private fields (e.g., prev) to store data between ticks.
  3. Constructor
    Call super(state, config) to initialize base properties and set up your own fields.
  4. Override doExecute()
    • Access input values via this.v and stored state via this._s.
    • Implement your logic (e.g., detect when the current close is lower than the previous close).
    • Update internal state (this.prev = this.v.input;).
    • Return a result only when the condition is met.

NegativeValues handler example (pseudocode):

Extends AbstractHandler, tracks the previous candle in prev, and returns the current candle when its close is less than the previous close.

Example: Backtest from CSV

A quick outline to run a backtest with CSV data:

import TradingCycle from 'trading-cycle';
import handlers from 'trading-cycle/full';
import defaultPreset from 'trading-cycle/config';

// Initialize the cycle
const cycle = new TradingCycle(handlers, defaultPreset);

// Load your CSV into `ticks: Array<{ o, h, l, c, v }>`
// e.g. via `csv-parse` or any CSV loader

ticks.forEach(tick => cycle.execute(tick));

// Inspect results
console.log(cycle.state);

API Overview

  • new TradingCycle(handlerClasses: Record<string, HandlerConstructor>, preset: HandlerConfig[]) — Create a cycle with provided handlers and configuration presets.
  • execute(tick: any): void — Run all handlers on a single market tick; results accumulate in cycle.state.
  • cycle.state: Record<string, any[]> — Current output arrays for each handler.

Design Philosophy

  • Modularity: Handlers are self-contained units; you can add, remove or customize them without affecting others.
  • Flexibility: Presets define the pipeline; you control data flow by composing inputs and defaults.
  • Simplicity: Core abstractions (TradingCycle, AbstractHandler) remain minimal and clear.

Continuous Integration

This project uses GitHub Actions for CI and Codecov for coverage reporting.

Setup

  1. Add Codecov action: No extra npm packages needed, simply configure the workflow.
  2. Create a secret: Add CODECOV_TOKEN in your repository's Settings > Secrets.

Workflow (.github/workflows/ci.yml)

name: CI

on:
  push:
    branches: [ main ]
  pull_request:

jobs:
  build-and-test:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3
      - name: Setup Node.js
        uses: actions/setup-node@v3
        with:
          node-version: 18

      - name: Install dependencies
        run: yarn install --frozen-lockfile

      - name: Run tests
        run: yarn test --coverage

      - name: Upload to Codecov
        uses: codecov/codecov-action@v3
        with:
          token: ${{ secrets.CODECOV_TOKEN }}

License

MIT

Author

Vladyslav Tarasenko