@d3fc/d3fc-technical-indicator
Advanced tools
Comparing version 7.0.24 to 7.0.25
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3-array')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'd3-array'], factory) : | ||
(factory((global.fc = global.fc || {}),global.d3)); | ||
}(this, (function (exports,d3Array) { 'use strict'; | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3-array')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'd3-array'], factory) : | ||
(global = global || self, factory(global.fc = global.fc || {}, global.d3)); | ||
}(this, function (exports, d3Array) { 'use strict'; | ||
var createReboundMethod = (function (target, source, name) { | ||
var method = source[name]; | ||
if (typeof method !== 'function') { | ||
throw new Error('Attempt to rebind ' + name + ' which isn\'t a function on the source object'); | ||
} | ||
return function () { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
var createReboundMethod = (function (target, source, name) { | ||
var method = source[name]; | ||
if (typeof method !== 'function') { | ||
throw new Error('Attempt to rebind ' + name + ' which isn\'t a function on the source object'); | ||
} | ||
return function () { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
var value = method.apply(source, args); | ||
return value === source ? target : value; | ||
}; | ||
}); | ||
var value = method.apply(source, args); | ||
return value === source ? target : value; | ||
}; | ||
}); | ||
var rebind = (function (target, source) { | ||
for (var _len = arguments.length, names = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { | ||
names[_key - 2] = arguments[_key]; | ||
} | ||
var rebind = (function (target, source) { | ||
for (var _len = arguments.length, names = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { | ||
names[_key - 2] = arguments[_key]; | ||
} | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
try { | ||
for (var _iterator = names[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var name = _step.value; | ||
try { | ||
for (var _iterator = names[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var name = _step.value; | ||
target[name] = createReboundMethod(target, source, name); | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return) { | ||
_iterator.return(); | ||
target[name] = createReboundMethod(target, source, name); | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
} | ||
return target; | ||
}); | ||
return target; | ||
}); | ||
var createTransform = function createTransform(transforms) { | ||
return function (name) { | ||
return transforms.reduce(function (name, fn) { | ||
return name && fn(name); | ||
}, name); | ||
var createTransform = function createTransform(transforms) { | ||
return function (name) { | ||
return transforms.reduce(function (name, fn) { | ||
return name && fn(name); | ||
}, name); | ||
}; | ||
}; | ||
}; | ||
var rebindAll = (function (target, source) { | ||
for (var _len = arguments.length, transforms = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { | ||
transforms[_key - 2] = arguments[_key]; | ||
} | ||
var rebindAll = (function (target, source) { | ||
for (var _len = arguments.length, transforms = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { | ||
transforms[_key - 2] = arguments[_key]; | ||
} | ||
var transform = createTransform(transforms); | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
var transform = createTransform(transforms); | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
try { | ||
for (var _iterator = Object.keys(source)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var name = _step.value; | ||
try { | ||
for (var _iterator = Object.keys(source)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var name = _step.value; | ||
var result = transform(name); | ||
if (result) { | ||
target[result] = createReboundMethod(target, source, name); | ||
var result = transform(name); | ||
if (result) { | ||
target[result] = createReboundMethod(target, source, name); | ||
} | ||
} | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return) { | ||
_iterator.return(); | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
} | ||
return target; | ||
}); | ||
return target; | ||
}); | ||
var includeMap = (function (mappings) { | ||
return function (name) { | ||
return mappings[name]; | ||
}; | ||
}); | ||
var includeMap = (function (mappings) { | ||
return function (name) { | ||
return mappings[name]; | ||
}; | ||
}); | ||
function identity(d) { | ||
return d; | ||
} | ||
function noop(d) {} | ||
function identity(d) { | ||
return d; | ||
} | ||
function noop(d) {} | ||
function functor(v) { | ||
return typeof v === 'function' ? v : function () { | ||
return v; | ||
}; | ||
} | ||
function convertNaN(value) { | ||
return typeof value === 'number' && isNaN(value) ? undefined : value; | ||
} | ||
function functor(v) { | ||
return typeof v === 'function' ? v : function () { | ||
return v; | ||
}; | ||
} | ||
function convertNaN(value) { | ||
return typeof value === 'number' && isNaN(value) ? undefined : value; | ||
} | ||
var _slidingWindow = function () { | ||
function _slidingWindow () { | ||
var period = function period() { | ||
return 10; | ||
}; | ||
var accumulator = noop; | ||
var value = identity; | ||
var defined = function defined(d) { | ||
return d != null; | ||
}; | ||
var period = function period() { | ||
return 10; | ||
}; | ||
var accumulator = noop; | ||
var value = identity; | ||
var defined = function defined(d) { | ||
return d != null; | ||
}; | ||
var slidingWindow = function slidingWindow(data) { | ||
var size = period.apply(this, arguments); | ||
var windowData = data.slice(0, size).map(value); | ||
return data.map(function (d, i) { | ||
if (i >= size) { | ||
// Treat windowData as FIFO rolling buffer | ||
windowData.shift(); | ||
windowData.push(value(d, i)); | ||
var slidingWindow = function slidingWindow(data) { | ||
var size = period.apply(this, arguments); | ||
var windowData = data.slice(0, size).map(value); | ||
return data.map(function (d, i) { | ||
if (i >= size) { | ||
// Treat windowData as FIFO rolling buffer | ||
windowData.shift(); | ||
windowData.push(value(d, i)); | ||
} | ||
if (i < size - 1 || windowData.some(function (d) { | ||
return !defined(d); | ||
})) { | ||
return accumulator(undefined, i); | ||
} | ||
return accumulator(windowData, i); | ||
}); | ||
}; | ||
slidingWindow.period = function () { | ||
if (!arguments.length) { | ||
return period; | ||
} | ||
if (i < size - 1 || windowData.some(function (d) { | ||
return !defined(d); | ||
})) { | ||
return accumulator(undefined, i); | ||
period = functor(arguments.length <= 0 ? undefined : arguments[0]); | ||
return slidingWindow; | ||
}; | ||
slidingWindow.accumulator = function () { | ||
if (!arguments.length) { | ||
return accumulator; | ||
} | ||
return accumulator(windowData, i); | ||
}); | ||
}; | ||
accumulator = arguments.length <= 0 ? undefined : arguments[0]; | ||
return slidingWindow; | ||
}; | ||
slidingWindow.defined = function () { | ||
if (!arguments.length) { | ||
return defined; | ||
} | ||
defined = arguments.length <= 0 ? undefined : arguments[0]; | ||
return slidingWindow; | ||
}; | ||
slidingWindow.value = function () { | ||
if (!arguments.length) { | ||
return value; | ||
} | ||
value = arguments.length <= 0 ? undefined : arguments[0]; | ||
return slidingWindow; | ||
}; | ||
slidingWindow.period = function () { | ||
if (!arguments.length) { | ||
return period; | ||
} | ||
period = functor(arguments.length <= 0 ? undefined : arguments[0]); | ||
return slidingWindow; | ||
}; | ||
slidingWindow.accumulator = function () { | ||
if (!arguments.length) { | ||
return accumulator; | ||
} | ||
accumulator = arguments.length <= 0 ? undefined : arguments[0]; | ||
return slidingWindow; | ||
}; | ||
slidingWindow.defined = function () { | ||
if (!arguments.length) { | ||
return defined; | ||
} | ||
defined = arguments.length <= 0 ? undefined : arguments[0]; | ||
return slidingWindow; | ||
}; | ||
slidingWindow.value = function () { | ||
if (!arguments.length) { | ||
return value; | ||
} | ||
value = arguments.length <= 0 ? undefined : arguments[0]; | ||
return slidingWindow; | ||
}; | ||
} | ||
return slidingWindow; | ||
}; | ||
function bollingerBands () { | ||
var bollingerBands = function () { | ||
var multiplier = 2; | ||
var multiplier = 2; | ||
var slidingWindow = _slidingWindow().accumulator(function (values) { | ||
var stdDev = values && d3Array.deviation(values); | ||
var average = values && d3Array.mean(values); | ||
return { | ||
average: average, | ||
upper: convertNaN(average + multiplier * stdDev), | ||
lower: convertNaN(average - multiplier * stdDev) | ||
}; | ||
}); | ||
var slidingWindow = _slidingWindow().accumulator(function (values) { | ||
var stdDev = values && d3Array.deviation(values); | ||
var average = values && d3Array.mean(values); | ||
return { | ||
average: average, | ||
upper: convertNaN(average + multiplier * stdDev), | ||
lower: convertNaN(average - multiplier * stdDev) | ||
var bollingerBands = function bollingerBands(data) { | ||
return slidingWindow(data); | ||
}; | ||
}); | ||
var bollingerBands = function bollingerBands(data) { | ||
return slidingWindow(data); | ||
}; | ||
bollingerBands.multiplier = function () { | ||
if (!arguments.length) { | ||
return multiplier; | ||
} | ||
multiplier = arguments.length <= 0 ? undefined : arguments[0]; | ||
return bollingerBands; | ||
}; | ||
bollingerBands.multiplier = function () { | ||
if (!arguments.length) { | ||
return multiplier; | ||
} | ||
multiplier = arguments.length <= 0 ? undefined : arguments[0]; | ||
rebind(bollingerBands, slidingWindow, 'period', 'value'); | ||
return bollingerBands; | ||
}; | ||
} | ||
rebind(bollingerBands, slidingWindow, 'period', 'value'); | ||
function exponentialMovingAverage () { | ||
return bollingerBands; | ||
}; | ||
var value = identity; | ||
var period = function period() { | ||
return 9; | ||
}; | ||
var exponentialMovingAverage = function () { | ||
var value = identity; | ||
var period = function period() { | ||
return 9; | ||
}; | ||
var initialMovingAverageAccumulator = function initialMovingAverageAccumulator(period) { | ||
var values = []; | ||
return function (value) { | ||
var movingAverage = void 0; | ||
if (values.length < period) { | ||
if (value != null) { | ||
values.push(value); | ||
var initialMovingAverageAccumulator = function initialMovingAverageAccumulator(period) { | ||
var values = []; | ||
return function (value) { | ||
var movingAverage = void 0; | ||
if (values.length < period) { | ||
if (value != null) { | ||
values.push(value); | ||
} else { | ||
values = []; | ||
} | ||
} | ||
if (values.length >= period) { | ||
movingAverage = d3Array.mean(values); | ||
} | ||
return movingAverage; | ||
}; | ||
}; | ||
var exponentialMovingAverage = function exponentialMovingAverage(data) { | ||
var size = period.apply(this, arguments); | ||
var alpha = 2 / (size + 1); | ||
var initialAccumulator = initialMovingAverageAccumulator(size); | ||
var ema = void 0; | ||
return data.map(function (d, i) { | ||
var v = value(d, i); | ||
if (ema === undefined) { | ||
ema = initialAccumulator(v); | ||
} else { | ||
values = []; | ||
ema = v * alpha + (1 - alpha) * ema; | ||
} | ||
return convertNaN(ema); | ||
}); | ||
}; | ||
exponentialMovingAverage.period = function () { | ||
if (!arguments.length) { | ||
return period; | ||
} | ||
if (values.length >= period) { | ||
movingAverage = d3Array.mean(values); | ||
period = functor(arguments.length <= 0 ? undefined : arguments[0]); | ||
return exponentialMovingAverage; | ||
}; | ||
exponentialMovingAverage.value = function () { | ||
if (!arguments.length) { | ||
return value; | ||
} | ||
return movingAverage; | ||
value = arguments.length <= 0 ? undefined : arguments[0]; | ||
return exponentialMovingAverage; | ||
}; | ||
}; | ||
var exponentialMovingAverage = function exponentialMovingAverage(data) { | ||
var size = period.apply(this, arguments); | ||
var alpha = 2 / (size + 1); | ||
var initialAccumulator = initialMovingAverageAccumulator(size); | ||
var ema = void 0; | ||
return data.map(function (d, i) { | ||
var v = value(d, i); | ||
if (ema === undefined) { | ||
ema = initialAccumulator(v); | ||
} else { | ||
ema = v * alpha + (1 - alpha) * ema; | ||
} | ||
return convertNaN(ema); | ||
}); | ||
}; | ||
exponentialMovingAverage.period = function () { | ||
if (!arguments.length) { | ||
return period; | ||
} | ||
period = functor(arguments.length <= 0 ? undefined : arguments[0]); | ||
return exponentialMovingAverage; | ||
}; | ||
} | ||
exponentialMovingAverage.value = function () { | ||
if (!arguments.length) { | ||
return value; | ||
} | ||
value = arguments.length <= 0 ? undefined : arguments[0]; | ||
return exponentialMovingAverage; | ||
}; | ||
function macd () { | ||
return exponentialMovingAverage; | ||
}; | ||
var value = identity; | ||
var macd = function () { | ||
var fastEMA = exponentialMovingAverage().period(12); | ||
var slowEMA = exponentialMovingAverage().period(26); | ||
var signalEMA = exponentialMovingAverage().period(9); | ||
var value = identity; | ||
var macd = function macd(data) { | ||
var fastEMA = exponentialMovingAverage().period(12); | ||
var slowEMA = exponentialMovingAverage().period(26); | ||
var signalEMA = exponentialMovingAverage().period(9); | ||
fastEMA.value(value); | ||
slowEMA.value(value); | ||
var macd = function macd(data) { | ||
var diff = d3Array.zip(fastEMA(data), slowEMA(data)).map(function (d) { | ||
return d[0] !== undefined && d[1] !== undefined ? d[0] - d[1] : undefined; | ||
}); | ||
fastEMA.value(value); | ||
slowEMA.value(value); | ||
var averageDiff = signalEMA(diff); | ||
var diff = d3Array.zip(fastEMA(data), slowEMA(data)).map(function (d) { | ||
return d[0] !== undefined && d[1] !== undefined ? d[0] - d[1] : undefined; | ||
}); | ||
return d3Array.zip(diff, averageDiff).map(function (d) { | ||
return { | ||
macd: d[0], | ||
signal: d[1], | ||
divergence: d[0] !== undefined && d[1] !== undefined ? d[0] - d[1] : undefined | ||
}; | ||
}); | ||
}; | ||
var averageDiff = signalEMA(diff); | ||
macd.value = function () { | ||
if (!arguments.length) { | ||
return value; | ||
} | ||
value = arguments.length <= 0 ? undefined : arguments[0]; | ||
return macd; | ||
}; | ||
return d3Array.zip(diff, averageDiff).map(function (d) { | ||
return { | ||
macd: d[0], | ||
signal: d[1], | ||
divergence: d[0] !== undefined && d[1] !== undefined ? d[0] - d[1] : undefined | ||
}; | ||
}); | ||
}; | ||
rebindAll(macd, fastEMA, includeMap({ 'period': 'fastPeriod' })); | ||
rebindAll(macd, slowEMA, includeMap({ 'period': 'slowPeriod' })); | ||
rebindAll(macd, signalEMA, includeMap({ 'period': 'signalPeriod' })); | ||
macd.value = function () { | ||
if (!arguments.length) { | ||
return value; | ||
} | ||
value = arguments.length <= 0 ? undefined : arguments[0]; | ||
return macd; | ||
}; | ||
} | ||
rebindAll(macd, fastEMA, includeMap({ 'period': 'fastPeriod' })); | ||
rebindAll(macd, slowEMA, includeMap({ 'period': 'slowPeriod' })); | ||
rebindAll(macd, signalEMA, includeMap({ 'period': 'signalPeriod' })); | ||
var slicedToArray = function () { | ||
function sliceIterator(arr, i) { | ||
var _arr = []; | ||
var _n = true; | ||
var _d = false; | ||
var _e = undefined; | ||
return macd; | ||
}; | ||
try { | ||
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { | ||
_arr.push(_s.value); | ||
var slicedToArray = function () { | ||
function sliceIterator(arr, i) { | ||
var _arr = []; | ||
var _n = true; | ||
var _d = false; | ||
var _e = undefined; | ||
if (i && _arr.length === i) break; | ||
} | ||
} catch (err) { | ||
_d = true; | ||
_e = err; | ||
} finally { | ||
try { | ||
if (!_n && _i["return"]) _i["return"](); | ||
} finally { | ||
if (_d) throw _e; | ||
} | ||
} | ||
try { | ||
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { | ||
_arr.push(_s.value); | ||
if (i && _arr.length === i) break; | ||
return _arr; | ||
} | ||
} catch (err) { | ||
_d = true; | ||
_e = err; | ||
} finally { | ||
try { | ||
if (!_n && _i["return"]) _i["return"](); | ||
} finally { | ||
if (_d) throw _e; | ||
} | ||
} | ||
return _arr; | ||
} | ||
return function (arr, i) { | ||
if (Array.isArray(arr)) { | ||
return arr; | ||
} else if (Symbol.iterator in Object(arr)) { | ||
return sliceIterator(arr, i); | ||
} else { | ||
throw new TypeError("Invalid attempt to destructure non-iterable instance"); | ||
} | ||
}; | ||
}(); | ||
return function (arr, i) { | ||
if (Array.isArray(arr)) { | ||
return arr; | ||
} else if (Symbol.iterator in Object(arr)) { | ||
return sliceIterator(arr, i); | ||
} else { | ||
throw new TypeError("Invalid attempt to destructure non-iterable instance"); | ||
} | ||
}; | ||
}(); | ||
var toConsumableArray = function (arr) { | ||
if (Array.isArray(arr)) { | ||
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} else { | ||
return Array.from(arr); | ||
} | ||
}; | ||
function relativeStrengthIndex () { | ||
var slidingWindow = _slidingWindow().period(14); | ||
var wildersSmoothing = function wildersSmoothing(values, prevAvg) { | ||
return prevAvg + (values[values.length - 1] - prevAvg) / values.length; | ||
}; | ||
var downChange = function downChange(_ref) { | ||
var _ref2 = slicedToArray(_ref, 2), | ||
prevClose = _ref2[0], | ||
close = _ref2[1]; | ||
return prevClose < close ? 0 : prevClose - close; | ||
}; | ||
var upChange = function upChange(_ref3) { | ||
var _ref4 = slicedToArray(_ref3, 2), | ||
prevClose = _ref4[0], | ||
close = _ref4[1]; | ||
return prevClose > close ? 0 : close - prevClose; | ||
}; | ||
var updateAverage = function updateAverage(changes, prevAverage) { | ||
return prevAverage !== undefined ? wildersSmoothing(changes, prevAverage) : d3Array.mean(changes); | ||
}; | ||
var makeAccumulator = function makeAccumulator() { | ||
var prevClose = void 0; | ||
var downChangesAvg = void 0; | ||
var upChangesAvg = void 0; | ||
return function (closes) { | ||
if (!closes) { | ||
if (prevClose !== undefined) { | ||
prevClose = NaN; | ||
} | ||
return undefined; | ||
} | ||
if (prevClose === undefined) { | ||
prevClose = closes[0]; | ||
return undefined; | ||
} | ||
var closePairs = d3Array.pairs([prevClose].concat(toConsumableArray(closes))); | ||
downChangesAvg = updateAverage(closePairs.map(downChange), downChangesAvg); | ||
upChangesAvg = updateAverage(closePairs.map(upChange), upChangesAvg); | ||
var rs = !isNaN(prevClose) ? upChangesAvg / downChangesAvg : NaN; | ||
return convertNaN(100 - 100 / (1 + rs)); | ||
}; | ||
}; | ||
var rsi = function rsi(data) { | ||
var rsiAccumulator = makeAccumulator(); | ||
slidingWindow.accumulator(rsiAccumulator); | ||
return slidingWindow(data); | ||
}; | ||
rebind(rsi, slidingWindow, 'period', 'value'); | ||
return rsi; | ||
} | ||
function movingAverage () { | ||
var slidingWindow = _slidingWindow().accumulator(function (values) { | ||
return values && d3Array.mean(values); | ||
}); | ||
var toConsumableArray = function (arr) { | ||
if (Array.isArray(arr)) { | ||
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; | ||
var movingAverage = function movingAverage(data) { | ||
return slidingWindow(data); | ||
}; | ||
return arr2; | ||
} else { | ||
return Array.from(arr); | ||
} | ||
}; | ||
rebind(movingAverage, slidingWindow, 'period', 'value'); | ||
var relativeStrengthIndex = function () { | ||
return movingAverage; | ||
} | ||
var slidingWindow = _slidingWindow().period(14); | ||
var wildersSmoothing = function wildersSmoothing(values, prevAvg) { | ||
return prevAvg + (values[values.length - 1] - prevAvg) / values.length; | ||
}; | ||
var downChange = function downChange(_ref) { | ||
var _ref2 = slicedToArray(_ref, 2), | ||
prevClose = _ref2[0], | ||
close = _ref2[1]; | ||
function stochasticOscillator () { | ||
return prevClose < close ? 0 : prevClose - close; | ||
}; | ||
var upChange = function upChange(_ref3) { | ||
var _ref4 = slicedToArray(_ref3, 2), | ||
prevClose = _ref4[0], | ||
close = _ref4[1]; | ||
var closeValue = function closeValue(d, i) { | ||
return d.close; | ||
}; | ||
var highValue = function highValue(d, i) { | ||
return d.high; | ||
}; | ||
var lowValue = function lowValue(d, i) { | ||
return d.low; | ||
}; | ||
return prevClose > close ? 0 : close - prevClose; | ||
}; | ||
var kWindow = _slidingWindow().period(5).defined(function (d) { | ||
return closeValue(d) != null && highValue(d) != null && lowValue(d) != null; | ||
}).accumulator(function (values) { | ||
var maxHigh = values && d3Array.max(values, highValue); | ||
var minLow = values && d3Array.min(values, lowValue); | ||
var kValue = values && 100 * (closeValue(values[values.length - 1]) - minLow) / (maxHigh - minLow); | ||
return convertNaN(kValue); | ||
}); | ||
var updateAverage = function updateAverage(changes, prevAverage) { | ||
return prevAverage !== undefined ? wildersSmoothing(changes, prevAverage) : d3Array.mean(changes); | ||
}; | ||
var dWindow = movingAverage().period(3); | ||
var makeAccumulator = function makeAccumulator() { | ||
var prevClose = void 0; | ||
var downChangesAvg = void 0; | ||
var upChangesAvg = void 0; | ||
return function (closes) { | ||
if (!closes) { | ||
if (prevClose !== undefined) { | ||
prevClose = NaN; | ||
} | ||
return undefined; | ||
var stochastic = function stochastic(data) { | ||
var kValues = kWindow(data); | ||
var dValues = dWindow(kValues); | ||
return kValues.map(function (k, i) { | ||
return { k: k, d: dValues[i] }; | ||
}); | ||
}; | ||
stochastic.closeValue = function () { | ||
if (!arguments.length) { | ||
return closeValue; | ||
} | ||
if (prevClose === undefined) { | ||
prevClose = closes[0]; | ||
return undefined; | ||
closeValue = arguments.length <= 0 ? undefined : arguments[0]; | ||
return stochastic; | ||
}; | ||
stochastic.highValue = function () { | ||
if (!arguments.length) { | ||
return highValue; | ||
} | ||
var closePairs = d3Array.pairs([prevClose].concat(toConsumableArray(closes))); | ||
downChangesAvg = updateAverage(closePairs.map(downChange), downChangesAvg); | ||
upChangesAvg = updateAverage(closePairs.map(upChange), upChangesAvg); | ||
var rs = !isNaN(prevClose) ? upChangesAvg / downChangesAvg : NaN; | ||
return convertNaN(100 - 100 / (1 + rs)); | ||
highValue = arguments.length <= 0 ? undefined : arguments[0]; | ||
return stochastic; | ||
}; | ||
}; | ||
stochastic.lowValue = function () { | ||
if (!arguments.length) { | ||
return lowValue; | ||
} | ||
lowValue = arguments.length <= 0 ? undefined : arguments[0]; | ||
return stochastic; | ||
}; | ||
var rsi = function rsi(data) { | ||
var rsiAccumulator = makeAccumulator(); | ||
slidingWindow.accumulator(rsiAccumulator); | ||
return slidingWindow(data); | ||
}; | ||
rebindAll(stochastic, kWindow, includeMap({ 'period': 'kPeriod' })); | ||
rebindAll(stochastic, dWindow, includeMap({ 'period': 'dPeriod' })); | ||
rebind(rsi, slidingWindow, 'period', 'value'); | ||
return rsi; | ||
}; | ||
return stochastic; | ||
} | ||
var movingAverage = function () { | ||
function forceIndex () { | ||
var slidingWindow = _slidingWindow().accumulator(function (values) { | ||
return values && d3Array.mean(values); | ||
}); | ||
var volumeValue = function volumeValue(d, i) { | ||
return d.volume; | ||
}; | ||
var closeValue = function closeValue(d, i) { | ||
return d.close; | ||
}; | ||
var movingAverage = function movingAverage(data) { | ||
return slidingWindow(data); | ||
}; | ||
var emaComputer = exponentialMovingAverage().period(13); | ||
rebind(movingAverage, slidingWindow, 'period', 'value'); | ||
return movingAverage; | ||
}; | ||
var stochasticOscillator = function () { | ||
var closeValue = function closeValue(d, i) { | ||
return d.close; | ||
}; | ||
var highValue = function highValue(d, i) { | ||
return d.high; | ||
}; | ||
var lowValue = function lowValue(d, i) { | ||
return d.low; | ||
}; | ||
var kWindow = _slidingWindow().period(5).defined(function (d) { | ||
return closeValue(d) != null && highValue(d) != null && lowValue(d) != null; | ||
}).accumulator(function (values) { | ||
var maxHigh = values && d3Array.max(values, highValue); | ||
var minLow = values && d3Array.min(values, lowValue); | ||
var kValue = values && 100 * (closeValue(values[values.length - 1]) - minLow) / (maxHigh - minLow); | ||
return convertNaN(kValue); | ||
}); | ||
var dWindow = movingAverage().period(3); | ||
var stochastic = function stochastic(data) { | ||
var kValues = kWindow(data); | ||
var dValues = dWindow(kValues); | ||
return kValues.map(function (k, i) { | ||
return { k: k, d: dValues[i] }; | ||
var slidingWindow = _slidingWindow().period(2).defined(function (d) { | ||
return closeValue(d) != null && volumeValue(d) != null; | ||
}).accumulator(function (values) { | ||
return values && convertNaN((closeValue(values[1]) - closeValue(values[0])) * volumeValue(values[1])); | ||
}); | ||
}; | ||
stochastic.closeValue = function () { | ||
if (!arguments.length) { | ||
return closeValue; | ||
} | ||
closeValue = arguments.length <= 0 ? undefined : arguments[0]; | ||
return stochastic; | ||
}; | ||
stochastic.highValue = function () { | ||
if (!arguments.length) { | ||
return highValue; | ||
} | ||
highValue = arguments.length <= 0 ? undefined : arguments[0]; | ||
return stochastic; | ||
}; | ||
stochastic.lowValue = function () { | ||
if (!arguments.length) { | ||
return lowValue; | ||
} | ||
lowValue = arguments.length <= 0 ? undefined : arguments[0]; | ||
return stochastic; | ||
}; | ||
var force = function force(data) { | ||
var forceIndex = slidingWindow(data); | ||
return emaComputer(forceIndex); | ||
}; | ||
rebindAll(stochastic, kWindow, includeMap({ 'period': 'kPeriod' })); | ||
rebindAll(stochastic, dWindow, includeMap({ 'period': 'dPeriod' })); | ||
force.volumeValue = function () { | ||
if (!arguments.length) { | ||
return volumeValue; | ||
} | ||
volumeValue = arguments.length <= 0 ? undefined : arguments[0]; | ||
return force; | ||
}; | ||
force.closeValue = function () { | ||
if (!arguments.length) { | ||
return closeValue; | ||
} | ||
closeValue = arguments.length <= 0 ? undefined : arguments[0]; | ||
return force; | ||
}; | ||
return stochastic; | ||
}; | ||
rebind(force, emaComputer, 'period'); | ||
var forceIndex = function () { | ||
var volumeValue = function volumeValue(d, i) { | ||
return d.volume; | ||
}; | ||
var closeValue = function closeValue(d, i) { | ||
return d.close; | ||
}; | ||
var emaComputer = exponentialMovingAverage().period(13); | ||
var slidingWindow = _slidingWindow().period(2).defined(function (d) { | ||
return closeValue(d) != null && volumeValue(d) != null; | ||
}).accumulator(function (values) { | ||
return values && convertNaN((closeValue(values[1]) - closeValue(values[0])) * volumeValue(values[1])); | ||
}); | ||
var force = function force(data) { | ||
var forceIndex = slidingWindow(data); | ||
return emaComputer(forceIndex); | ||
}; | ||
force.volumeValue = function () { | ||
if (!arguments.length) { | ||
return volumeValue; | ||
} | ||
volumeValue = arguments.length <= 0 ? undefined : arguments[0]; | ||
return force; | ||
}; | ||
force.closeValue = function () { | ||
if (!arguments.length) { | ||
return closeValue; | ||
} | ||
closeValue = arguments.length <= 0 ? undefined : arguments[0]; | ||
return force; | ||
}; | ||
} | ||
rebind(force, emaComputer, 'period'); | ||
function envelope () { | ||
return force; | ||
}; | ||
var factor = 0.1; | ||
var value = identity; | ||
var envelope = function () { | ||
var envelope = function envelope(data) { | ||
return data.map(function (d) { | ||
var lower = convertNaN(value(d) * (1.0 - factor)); | ||
var upper = convertNaN(value(d) * (1.0 + factor)); | ||
return { lower: lower, upper: upper }; | ||
}); | ||
}; | ||
var factor = 0.1; | ||
var value = identity; | ||
envelope.factor = function () { | ||
if (!arguments.length) { | ||
return factor; | ||
} | ||
factor = arguments.length <= 0 ? undefined : arguments[0]; | ||
return envelope; | ||
}; | ||
var envelope = function envelope(data) { | ||
return data.map(function (d) { | ||
var lower = convertNaN(value(d) * (1.0 - factor)); | ||
var upper = convertNaN(value(d) * (1.0 + factor)); | ||
return { lower: lower, upper: upper }; | ||
}); | ||
}; | ||
envelope.value = function () { | ||
if (!arguments.length) { | ||
return value; | ||
} | ||
value = arguments.length <= 0 ? undefined : arguments[0]; | ||
return envelope; | ||
}; | ||
envelope.factor = function () { | ||
if (!arguments.length) { | ||
return factor; | ||
} | ||
factor = arguments.length <= 0 ? undefined : arguments[0]; | ||
return envelope; | ||
}; | ||
} | ||
envelope.value = function () { | ||
if (!arguments.length) { | ||
return value; | ||
} | ||
value = arguments.length <= 0 ? undefined : arguments[0]; | ||
return envelope; | ||
}; | ||
function elderRay () { | ||
return envelope; | ||
}; | ||
var closeValue = function closeValue(d, i) { | ||
return d.close; | ||
}; | ||
var highValue = function highValue(d, i) { | ||
return d.high; | ||
}; | ||
var lowValue = function lowValue(d, i) { | ||
return d.low; | ||
}; | ||
var elderRay = function () { | ||
var emaComputer = exponentialMovingAverage().period(13); | ||
var closeValue = function closeValue(d, i) { | ||
return d.close; | ||
}; | ||
var highValue = function highValue(d, i) { | ||
return d.high; | ||
}; | ||
var lowValue = function lowValue(d, i) { | ||
return d.low; | ||
}; | ||
var elderRay = function elderRay(data) { | ||
emaComputer.value(closeValue); | ||
return d3Array.zip(data, emaComputer(data)).map(function (d) { | ||
var bullPower = convertNaN(highValue(d[0]) - d[1]); | ||
var bearPower = convertNaN(lowValue(d[0]) - d[1]); | ||
return { bullPower: bullPower, bearPower: bearPower }; | ||
}); | ||
}; | ||
var emaComputer = exponentialMovingAverage().period(13); | ||
elderRay.closeValue = function () { | ||
if (!arguments.length) { | ||
return closeValue; | ||
} | ||
closeValue = arguments.length <= 0 ? undefined : arguments[0]; | ||
return elderRay; | ||
}; | ||
var elderRay = function elderRay(data) { | ||
emaComputer.value(closeValue); | ||
return d3Array.zip(data, emaComputer(data)).map(function (d) { | ||
var bullPower = convertNaN(highValue(d[0]) - d[1]); | ||
var bearPower = convertNaN(lowValue(d[0]) - d[1]); | ||
return { bullPower: bullPower, bearPower: bearPower }; | ||
}); | ||
}; | ||
elderRay.highValue = function () { | ||
if (!arguments.length) { | ||
return highValue; | ||
} | ||
highValue = arguments.length <= 0 ? undefined : arguments[0]; | ||
return elderRay; | ||
}; | ||
elderRay.lowValue = function () { | ||
if (!arguments.length) { | ||
return lowValue; | ||
} | ||
lowValue = arguments.length <= 0 ? undefined : arguments[0]; | ||
return elderRay; | ||
}; | ||
elderRay.closeValue = function () { | ||
if (!arguments.length) { | ||
return closeValue; | ||
} | ||
closeValue = arguments.length <= 0 ? undefined : arguments[0]; | ||
return elderRay; | ||
}; | ||
rebind(elderRay, emaComputer, 'period'); | ||
elderRay.highValue = function () { | ||
if (!arguments.length) { | ||
return highValue; | ||
} | ||
highValue = arguments.length <= 0 ? undefined : arguments[0]; | ||
return elderRay; | ||
}; | ||
elderRay.lowValue = function () { | ||
if (!arguments.length) { | ||
return lowValue; | ||
} | ||
lowValue = arguments.length <= 0 ? undefined : arguments[0]; | ||
return elderRay; | ||
}; | ||
} | ||
rebind(elderRay, emaComputer, 'period'); | ||
exports.indicatorBollingerBands = bollingerBands; | ||
exports.indicatorElderRay = elderRay; | ||
exports.indicatorEnvelope = envelope; | ||
exports.indicatorExponentialMovingAverage = exponentialMovingAverage; | ||
exports.indicatorForceIndex = forceIndex; | ||
exports.indicatorMacd = macd; | ||
exports.indicatorMovingAverage = movingAverage; | ||
exports.indicatorRelativeStrengthIndex = relativeStrengthIndex; | ||
exports.indicatorStochasticOscillator = stochasticOscillator; | ||
return elderRay; | ||
}; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
exports.indicatorBollingerBands = bollingerBands; | ||
exports.indicatorExponentialMovingAverage = exponentialMovingAverage; | ||
exports.indicatorMacd = macd; | ||
exports.indicatorRelativeStrengthIndex = relativeStrengthIndex; | ||
exports.indicatorStochasticOscillator = stochasticOscillator; | ||
exports.indicatorForceIndex = forceIndex; | ||
exports.indicatorEnvelope = envelope; | ||
exports.indicatorElderRay = elderRay; | ||
exports.indicatorMovingAverage = movingAverage; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
}))); | ||
})); |
@@ -6,2 +6,10 @@ # Change Log | ||
<a name="7.0.25"></a> | ||
## [7.0.25](https://github.com/d3fc/d3fc/compare/@d3fc/d3fc-technical-indicator@7.0.24...@d3fc/d3fc-technical-indicator@7.0.25) (2019-08-12) | ||
**Note:** Version bump only for package @d3fc/d3fc-technical-indicator | ||
<a name="7.0.24"></a> | ||
@@ -8,0 +16,0 @@ ## [7.0.24](https://github.com/d3fc/d3fc/compare/@d3fc/d3fc-technical-indicator@7.0.23...@d3fc/d3fc-technical-indicator@7.0.24) (2019-05-28) |
{ | ||
"name": "@d3fc/d3fc-technical-indicator", | ||
"version": "7.0.24", | ||
"version": "7.0.25", | ||
"description": "Components for calculating technical indicators on data series", | ||
@@ -36,13 +36,13 @@ "license": "MIT", | ||
"scripts": { | ||
"bundle": "d3fc-scripts bundle", | ||
"test": "d3fc-scripts test", | ||
"screenshot": "d3fc-scripts screenshot" | ||
"bundle": "npx rollup -c ../../scripts/rollup.config.js", | ||
"test": "npx jasmine --config=../../scripts/jasmine.json", | ||
"lint": "npx eslint src/**/*.js", | ||
"screenshots": "node ../../scripts/screenshot.js" | ||
}, | ||
"devDependencies": { | ||
"@d3fc/d3fc-annotation": "^2.4.1", | ||
"@d3fc/d3fc-extent": "^3.1.4", | ||
"@d3fc/d3fc-random-data": "^3.0.8", | ||
"@d3fc/d3fc-rebind": "^5.0.7", | ||
"@d3fc/d3fc-scripts": "^2.0.5", | ||
"@d3fc/d3fc-series": "^4.0.18", | ||
"@d3fc/d3fc-annotation": "^2.4.2", | ||
"@d3fc/d3fc-extent": "^3.1.5", | ||
"@d3fc/d3fc-random-data": "^3.0.9", | ||
"@d3fc/d3fc-rebind": "^5.0.8", | ||
"@d3fc/d3fc-series": "^4.0.19", | ||
"babel-polyfill": "^6.13.0", | ||
@@ -53,3 +53,3 @@ "d3": "^4.2.5", | ||
"dependencies": { | ||
"@d3fc/d3fc-rebind": "^5.0.7", | ||
"@d3fc/d3fc-rebind": "^5.0.8", | ||
"d3-array": "^1.0.0" | ||
@@ -56,0 +56,0 @@ }, |
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
8
0
593906
81
2846
Updated@d3fc/d3fc-rebind@^5.0.8