1.4.4 • Published 6 months ago

@debut/plugin-neuro-vision v1.4.4

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
6 months ago

@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

NameTypeDescription
inputSizenumberwindow size (input) for training and using the neural network (input size)
outputSizenumberforecast candles count
segmentsCountbooleannumber of segments into which the Gaussian distribution will be divided
precisionnumbernumber of decimal places when rounding (Affects the distribution)
hiddenLayers?numberoptionally, number of hidden layers, default 32, 16
debug?booleanOptional, enables output of Gaussian segments, for equal division debug*
  • Segments must contain equal number of elements (count should be about the same)

Plugin API

MethodDescription
addInputAdd input for activation. Use after model has been trained, before forcast() call
momentForecastForecast for current non closed candle
forecastForecast for fully closed candle
addTrainValueAdd a candle to the training sample (use only with --neuroTrain)
restoreNumber of decimal places, when rounding (Affects the distribution)
isTrainingReturns 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 Xt / Xt-1, where Xt and Xt-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

1.4.4

6 months ago

1.4.3

1 year ago

1.3.7

2 years ago

1.3.6

2 years ago

1.3.5

2 years ago

1.3.4

2 years ago

1.4.2

2 years ago

1.3.3

2 years ago

1.4.1

2 years ago

1.3.2

2 years ago

1.4.0

2 years ago

1.3.1

2 years ago

1.3.9

2 years ago

1.3.0

2 years ago

1.3.0-beta.1

2 years ago

1.2.0

2 years ago

1.3.0-beta.2

2 years ago

1.2.5

2 years ago

1.2.4

2 years ago

1.2.3

2 years ago

1.3.0-beta.0

2 years ago

1.2.1

2 years ago

1.1.1-esm.0

2 years ago

1.1.0

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago