0.4.0 • Published 4 years ago

alphacate v0.4.0

Weekly downloads
5
License
MIT
Repository
github
Last release
4 years ago

Alphacate


A Node.js toolkit with various indicators and oscillators for the technical stock analysis. This package contains only the mathematical calculations.

Installation


$ npm install alphacate [--save]

Example


//retrieve indicator module via accessor or alias
const LWMA = require('alphacate').LWMA;
const BB = require('alphacate').BollingerBands;

//do computation asynchronously
let run = async () => {
    try{
        //pass optional configuration object into the constructor
        let lwma = new LWMA( {periods: 4} );
        let bb = new BB( {periods: 4} );

        let data = [25.5, 26.75, 27.0, 26.5, 27.25];

        //set data series
        lwma.setValues( data );
        bb.setValues( data );

        //invoke calculate() to compute and retrieve result collection
        //an error will be throw if passed data serie or options are invalid
        let lwmaResultCollection = await lwma.calculate();
        let bbResultCollection = await bb.calculate();
        
        for(let i=0, len=lwmaCollection.length; i<len; i++){
            console.log(`Price: ${lwmaCollection[i].price}, LWMA: ${lwmaCollection[i].lwma}, BB Upper: ${bbCollection[i].upper}`);
        }

    }
    catch( err ){
        console.log(err.message);
    }
};

run();

List of indicators


See the list below for all available indicators in the package. Retrieve the indicator module via the accessor property or with the alias.

IndicatorModule accessorAlias
Average True RangeAverageTrueRangeATR
Bollinger BandsBollingerBandsBB
Exponential Moving AverageExponentialMovingAverageEMA
Linearly Weighted Moving AverageLinearlyWeightedMovingAverageLWMA
Money Flow IndexMoneyFlowIndexMFI
Moving Average Convergence DivergenceMovingAverageConvergenceDivergenceMACD
On Balance VolumeOnBalanceVolumeOBV
Rate Of ChangeRateOfChangeROC
Relative Strength IndexRelativeStrengthIndexRSI
Simple Moving AverageSimpleMovingAverageSMA
Smoothed Moving AverageSmoothedMovingAverageSMMA
Stochastic OscillatorStochasticOscillatorSO
Weighted Moving AverageWeightedMovingAverageWMA

Data serie item


The type of the item in the data serie that will be passed into the setValues function

IndicatorTypeUsage
Average True RangeNumber
Bollinger BandsNumber
Exponential Moving AverageNumber
Linearly Weighted Moving AverageNumber
Money Flow IndexObject{high:\<Number>, low:\<Number>, close:\<Number>, volume:\<Number> };
Moving Average Convergence DivergenceNumber
On Balance VolumeObject{price:\<Number>, volume:\<Number>}
Rate Of ChangeNumber
Relative Strength IndexNumber
Simple Moving AverageNumber
Smoothed Moving AverageNumber
Stochastic OscillatorNumber
Weighted Moving AverageNumber

Result collection item


Each item in the result collection contains several object properties. See the list below which properties belongs to the particular indicator. All values are numbers except where noted.

IndicatorCollection Item properties
Average True Range{tr, atr}
Bollinger Bands{upper:\<Array>, middle:\<Array>, lower:\<Array>, price:\<Array>}
Exponential Moving Average{price, ema}
Linearly Weighted Moving Average{price, lmwa}
Moving Average Convergence Divergence{slow_ema:\<Array>, fast_ema:\<Array>, signal_ema:\<Array>, macd:\<Array>, prices:\<Array>}
On Balance Volume{price, obv}
Rate Of Change{price, roc}
Relative Strength Index{price, gain, loss, avg_gain, avg_loss, rs, rsi}
Simple Moving Average{price, sma}
Smoothed Moving Average{price, smma}
Stochastic Oscillator{k,v, price}
Weighted Moving Average{price, wma}

Indicator options


To configure the indicator with different settings, you can pass an optional configuration object into the indicator constructor.

IndicatorOption properties
Average True Rangeperiods, startIndex, endIndex, lazyEvaluation, maxTickDuration
Bollinger Bandsperiods, startIndex, endIndex, sliceOffset, lazyEvaluation, maxTickDuration
Exponential Moving Averageperiods, startIndex, endIndex, sliceOffset, lazyEvaluation, maxTickDuration, emaResultsOnly, startWithFirst
Linearly Weighted Moving Averageperiods, startIndex, endIndex, sliceOffset, lazyEvaluation, maxTickDuration
Money Flow Indexperiods, startIndex, endIndex, sliceOffset, lazyEvaluation, maxTickDuration
Moving Average Convergence DivergencefastPeriods, slowPeriods, signalPeriods, sliceOffset, lazyEvaluation, maxTickDuration
On Balance VolumestartIndex, endIndex, lazyEvaluation, maxTickDuration
Rate Of Changeperiods, startIndex, endIndex, sliceOffset, lazyEvaluation, maxTickDuration
Relative Strength Indexperiods, startIndex, endIndex, sliceOffset, lazyEvaluation, maxTickDuration
Simple Moving Averageperiods, startIndex, endIndex, sliceOffset, lazyEvaluation, maxTickDuration
Smoothed Moving Averageperiods, startIndex, endIndex, sliceOffset, lazyEvaluation, maxTickDuration
Stochastic Oscillatorperiods, startIndex, endIndex, smaPeriods, sliceOffset, lazyEvaluation, maxTickDuration
Weighted Moving Averageperiods, startIndex, endIndex, sliceOffset, lazyEvaluation, maxTickDuration

See the table below for a description of the particular option property.

Option propertyTypeDescription
periodsNumberThe time periods to calculate the indicator
startIndexNumberThe index for the passed data serie to start the calulation
endIndexNumberThe index for the passed data serie to end the calculation
sliceOffsetBooleanOmit items in result collection used for inital period calculation
fastPeriodsNumberThe time periods for the fast moving average
slowPeriodsNumberThe time periods for the slow moving average
signalPeriodsNumberThe time periods for the signal average
smaPeriodsNumberThe time periods for the simple moving average
lazyEvaluationBooleanDo the computation of passed values in an asynchronous fashion
maxTickDurationNumberThe computation tick duration in milliseconds. If the computation is not completed, it will be continued in the tick of the next event loop.

Run Tests


All tests are inside test folder

Run tests:

$ npm test

Run code coverage report:

$ npm run coverage    

License

This project is under the MIT License. See the LICENSE file for the full license text.