New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

binary-indicators

Package Overview
Dependencies
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

binary-indicators - npm Package Compare versions

Comparing version 1.2.0 to 1.3.0

0

Gulpfile.js

@@ -0,0 +0,0 @@ const gulp = require('gulp');

40

lib/exponentialMovingAverage.js

@@ -6,26 +6,40 @@ 'use strict';

});
exports.exponentialMovingAverageArray = undefined;
var _binaryUtils = require('binary-utils');
var _math = require('./math');
var _simpleMovingAverage = require('./simpleMovingAverage');
var ema = function ema(vals, periods) {
if (vals.length === 1) {
return vals[0];
}
var _simpleMovingAverage2 = _interopRequireDefault(_simpleMovingAverage);
var prev = ema(vals.slice(0, vals.length - 1), periods);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var EMA = function EMA(previousDay) {
return 1;
return (vals.slice(-1)[0] - prev) * (0, _math.weightingMultiplier)(periods) + prev;
};
exports.default = function (data, config) {
var exponentialMovingAverage = function exponentialMovingAverage(data, config) {
var periods = config.periods;
var field = config.field;
var sma = (0, _simpleMovingAverage2.default)(data, config);
var multiplier = (0, _math.weightingMultiplier)(periods);
if (data.length < periods) {
throw new Error('Periods longer than data length');
}
// const prevEMA = EMA(previousDay);
// const ema = close - prevEMA * multiplier + prevEMA;
var vals = (0, _math.takeLast)(data, periods, field);
return 0;
};
return ema(vals, periods);
};
var exponentialMovingAverageArray = exports.exponentialMovingAverageArray = function exponentialMovingAverageArray(data, config) {
var periods = config.periods;
return (0, _binaryUtils.sequence)(data.length - periods + 1).map(function (x, i) {
return exponentialMovingAverage(data.slice(i, i + periods), config);
});
};
exports.default = exponentialMovingAverage;
{
"name": "binary-indicators",
"version": "1.2.0",
"version": "1.3.0",
"description": "Binary.com Indicators",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -0,0 +0,0 @@ #Binary.com Indicators

@@ -0,0 +0,0 @@ import { expect } from 'chai';

@@ -5,3 +5,3 @@ import { expect } from 'chai';

describe('exponentialMovingAverage', () => {
it.skip('single value with periods of 1 equals the value', () => {
it('single value with periods of 1 equals the value', () => {
const result = exponentialMovingAverage([1], { periods: 1 });

@@ -11,21 +11,22 @@ expect(result).to.equal(1);

it.skip('whole data sample', () => {
it('whole data sample', () => {
const result = exponentialMovingAverage([1, 2, 3], { periods: 3 });
// const roundedResult = roundResult(result);
expect(result).to.deep.equal(1);
expect(result).to.deep.equal(2.25);
});
it.skip('wuut2', () => {
it('wuut2', () => {
const data = [1, 2, 3, 4, 5];
const result = exponentialMovingAverageArray(data, { periods: 3 });
expect(result).to.deep.equal([1, 1.5, 2.25, 3.125, 4.063]);
expect(result).to.deep.equal([2.25, 3.25, 4.25]);
});
it.skip('real world', () => {
it('real world', () => {
const data = [22.27, 22.19, 22.08, 22.17, 22.18, 22.13, 22.23, 22.43, 22.24, 22.29,
22.15, 22.39, 22.38, 22.61, 23.36, 24.05, 23.75, 23.83, 23.95, 23.63, 23.82,
23.87, 23.65, 23.19, 23.10, 23.33, 22.68, 23.10, 22.40, 22.17];
const ema10days = [22.22, 22.21, 22.24, 22.27, 22.33, 22.52, 22.80, 22.97, 23.13,
23.28, 23.34, 23.43, 23.51, 23.54, 23.47, 23.40, 23.39, 23.26, 23.23, 23.08, 22.92];
const result = exponentialMovingAverage(data, { periods: 10 });
const ema10days = [22.25, 22.22, 22.24, 22.28, 22.34, 22.52, 22.81,
23.01, 23.13, 23.29, 23.33, 23.45, 23.53, 23.58, 23.61,
23.61, 23.52, 23.38, 23.34, 23.13, 22.98];
const result = exponentialMovingAverageArray(data, { periods: 10 });
const roundedResult = result.map(x => Math.round(x * 100) / 100);

@@ -32,0 +33,0 @@ expect(roundedResult).to.deep.equal(ema10days);

@@ -0,0 +0,0 @@ import { expect } from 'chai';

@@ -0,0 +0,0 @@ import { expect } from 'chai';

@@ -0,0 +0,0 @@ import { expect } from 'chai';

@@ -0,0 +0,0 @@ import { expect } from 'chai';

@@ -0,0 +0,0 @@ import { expect } from 'chai';

@@ -0,0 +0,0 @@ import { sequence } from 'binary-utils';

@@ -1,23 +0,41 @@

import { weightingMultiplier } from './math';
import simpleMovingAverage from './simpleMovingAverage';
import { sequence } from 'binary-utils';
import { takeLast, weightingMultiplier } from './math';
type CandleKeys = 'open' | 'high' | 'low' | 'close';
type CandleField = 'open' | 'high' | 'low' | 'close';
type ExponentialMovingAverageConfig = {
periods: number,
field?: CandleKeys,
field?: CandleField,
};
const EMA = (previousDay: number): number => 1;
const ema = (vals: [], periods: number) => {
if (vals.length === 1) {
return vals[0];
}
export default (data: Candle[], config: ExponentialMovingAverageConfig) => {
const { periods } = config;
const sma = simpleMovingAverage(data, config);
const prev = ema(vals.slice(0, vals.length - 1), periods);
const multiplier = weightingMultiplier(periods);
return (vals.slice(-1)[0] - prev) * weightingMultiplier(periods) + prev;
};
// const prevEMA = EMA(previousDay);
// const ema = close - prevEMA * multiplier + prevEMA;
const exponentialMovingAverage = (data: Candle[], config: ExponentialMovingAverageConfig): number => {
const { periods, field } = config;
return 0;
if (data.length < periods) {
throw new Error('Periods longer than data length');
}
const vals = takeLast(data, periods, field);
return ema(vals, periods);
};
export const exponentialMovingAverageArray = (data: Candle[], config: ExponentialMovingAverageConfig): number[] => {
const { periods } = config;
return sequence(data.length - periods + 1)
.map((x, i) =>
exponentialMovingAverage(data.slice(i, i + periods), config)
);
};
export default exponentialMovingAverage;

@@ -0,0 +0,0 @@ const sum = (arr: number[], valFunc) =>

@@ -0,0 +0,0 @@ type MomentumConfig = {

@@ -0,0 +0,0 @@ export const takeLast = (arr: any[], n: number, field?: string): any[] =>

@@ -0,0 +0,0 @@ type RelativeStrengthIndexConfig = {

@@ -0,0 +0,0 @@ import { sequence } from 'binary-utils';

@@ -0,0 +0,0 @@ module.exports = wallaby => ({

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc