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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@debut/plugin-neuro-vision

v1.4.4

Published

Neural network trend forecasting

Downloads

14

Readme

@debut/plugin-neuro-vision

Debut plugin, allows you to train a neural network on historical data. Use it to filter trades as well as to directly predict price direction. Forecasting is based on the algorithm of price change clustering, in which each price change for a time period is proportional to the price for the previous time period. Such changes are clustered in a Gaussian distribution, creating a uniform pattern for the neural network to work and train. In other words, each candlestick falls into a finite number of groups (from 5 to 11) and then the next candlestick, or rather the group it will be adjacent to, is predicted.

Install

npm install @debut/plugin-neuro-vision --save

Settings

| Name | Type | Description | |-----------|----------|------------| | inputSize | number | window size (input) for training and using the neural network (input size) | | outputSize | number | forecast candles count | | segmentsCount | boolean | number of segments into which the Gaussian distribution will be divided | | precision | number | number of decimal places when rounding (Affects the distribution) | | hiddenLayers? | number | optionally, number of hidden layers, default [32, 16] | | debug? | boolean | Optional, enables output of Gaussian segments, for equal division debug* |

  • Segments must contain equal number of elements (count should be about the same)

Plugin API

| Method | Description | |-----------|------------| | addInput | Add input for activation. Use after model has been trained, before forcast() call | | momentForecast | Forecast for current non closed candle | | forecast | Forecast for fully closed candle | | addTrainValue | Add a candle to the training sample (use only with --neuroTrain) | | restore | Number of decimal places, when rounding (Affects the distribution) | | isTraining | Returns the training flag, when --neuroTrain is true, otherwise false |

Initialize plugin

import { neuroVisionPlugin, NeuroVisionPluginAPI } from '@debut/plugin-neuro-vision';

// ...
export interface MyStrategyOptions extends DebutOptions, NeuroVisionPluginOptions;

export class MyStrategy extends Debut {
    declare plugins: NeuroVisionPluginAPI;
    private neuroTraining = false;

    constructor(transport: BaseTransport, opts: MyStrategyOptions) {
        super(transport, opts);

        this.registerPlugins([
            // ...
            neuroVisionPlugin({ windowSize: 25, segmentsCount: 11, precision: 6 }),
            // or
            // neuroVisionPlugin(opts),
            // ...
        ]);

        this.neuroTraining = this.plugins.neuroVision.isTraining();

        if (!this.neuroTraining) {
            this.plugins.neuroVision.restore();
        }
    }
//...
 async onCandle(candle: Candle) {
     // training
    if (this.neuroTraining) {
        This.plugins.neuroVision.addTrainValue(candle);
        return;
    }

    // usage
    this.plugins.neuroVision.addInput(candle);
    this.neuroVision = this.plugins.neuroVision.forecast(candle);
    console.log(this.neuroVision);
    /// output: [{ low: predicted low price, high: predicted high price, avg: average predicted price }]
    /// example: [{ low: 22564.3, high: 22693.7, avg:  22620.15 }]
 }

Neural network training

For training, use the standard Debut testing mechanism. Add the --neuroTrain flag to train the neural network. Don't forget to set gap so that you can test on untrained data. The training data will be automatically saved at the end of the process. In the trading strategy directory in rc. When you use and call the restore method, the network will be recreated from the saved data.

npm run compile && npm run testing -- --bot=Name --ticker=ETHUSDT --days=600 --gap=60 --neuroTrain

Algorithm

Really significant for the predictions are the changes of quotes. Therefore, the input of the neural network after preprocessing will be a series of percentage increments of quotes, calculated by the formula X[t] / X[t-1], where X[t] and X[t-1] are closing prices of periods.

Initially, the percentage increments have a Gaussian distribution, and of all statistical distribution functions defined on the finite interval, the uniform distribution has maximum entropy, so we recode the input variables to ensure that all examples in the training sample carry approximately the same information load.

In order to create different groups, which candlesticks will have equal probability to get into, the segment from the minimal percentage increment to the maximal one is divided into N segments, so each segment contains the equal amount of percentage increments of quotes in its value range. Each segment will be a group, the leftmost group - the falling price, the center - the neutral zone, the end - the zone of active price growth.

The task of reception of input images for forming the training set in tasks of forecasting of time series assumes using of "window" method. This method implies the use of a "window" with a fixed size, capable of moving through the time sequence of historical data, starting from the first element, and designed to access the data of time series, and the "window" of size N, after receiving such data, sends the elements from 1 to N-1 to the input of the neural network, and the N-th element is used as the output. The window method is used not only for training, but also for prediction. The number of elements in the window is the same as the number of input nodes in the neural network.

The higher the quality of the training sample, the less inconsistent and more repeatable it is. For the forecasting tasks of financial time series, the high discrepancy of a training sample is the sign of unsuccessful choice of the description method