@arction/lcjs-analysis
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -1,1 +0,1 @@ | ||
export { simpleMovingAverage } from './trading'; | ||
export { simpleMovingAverage, exponentialMovingAverage, bollingerBands, relativeStrengthIndex } from './trading'; |
@@ -20,4 +20,99 @@ var simpleMovingAverage = function (xohlcValues, averagingFrameLength) { | ||
}; | ||
var exponentialMovingAverage = function (xohlcValues, averagingFrameLength) { | ||
var len = xohlcValues.length; | ||
var result = []; | ||
var weighingMultiplier = 2 / (averagingFrameLength + 1); | ||
var i; | ||
var previousEMASum = 0; | ||
for (i = 0; i < averagingFrameLength; i++) { | ||
var xohlc = xohlcValues[i]; | ||
var value = xohlc[4]; | ||
previousEMASum += value; | ||
} | ||
var previousEMA = previousEMASum / averagingFrameLength; | ||
for (; i < len; i++) { | ||
var xohlc = xohlcValues[i]; | ||
var value = xohlc[4]; | ||
var ema = value * weighingMultiplier + (previousEMA !== undefined ? previousEMA * (1 - weighingMultiplier) : 0); | ||
if (i >= averagingFrameLength - 1) { | ||
result.push({ x: xohlc[0], y: ema }); | ||
} | ||
previousEMA = ema; | ||
} | ||
return result; | ||
}; | ||
var standardDeviation = function (values) { | ||
var len = values.length; | ||
var sum = 0; | ||
for (var i = 0; i < len; i++) { | ||
sum += values[i]; | ||
} | ||
var avg = sum / len; | ||
var sumSqDiff = 0; | ||
for (var i = 0; i < len; i++) { | ||
var value = values[i]; | ||
sumSqDiff += (value - avg) * (value - avg); | ||
} | ||
return Math.sqrt(sumSqDiff / len); | ||
}; | ||
var bollingerBands = function (xohlcValues, averagingFrameLength) { | ||
var len = xohlcValues.length; | ||
var smaValues = simpleMovingAverage(xohlcValues, averagingFrameLength); | ||
var typicalPrices = []; | ||
for (var i = 0; i < len; i++) { | ||
var xohlc = xohlcValues[i]; | ||
typicalPrices[i] = (xohlc[4] + xohlc[3] + xohlc[2]) / 3; | ||
} | ||
var bollingerBands = []; | ||
for (var i = averagingFrameLength - 1; i < len; i++) { | ||
var valuesForSD = typicalPrices.slice(i - (averagingFrameLength - 1), i + 1); | ||
var standardDeviation2 = 2 * standardDeviation(valuesForSD); | ||
var sma = smaValues[i - (averagingFrameLength - 1)]; | ||
bollingerBands.push({ | ||
position: sma.x, | ||
high: sma.y + standardDeviation2, | ||
low: sma.y - standardDeviation2 | ||
}); | ||
} | ||
return bollingerBands; | ||
}; | ||
var relativeStrengthIndex = function (xohlcValues, averagingFrameLength) { | ||
var len = xohlcValues.length; | ||
var result = []; | ||
var upValues = []; | ||
var downValues = []; | ||
var prevValue; | ||
for (var i = 0; i < len; i++) { | ||
var value = xohlcValues[i][4]; | ||
if (prevValue !== undefined) { | ||
var diff = value - prevValue; | ||
if (diff > 0) { | ||
upValues[i] = diff; | ||
downValues[i] = 0; | ||
} | ||
else { | ||
downValues[i] = -diff; | ||
upValues[i] = 0; | ||
} | ||
} | ||
prevValue = value; | ||
} | ||
for (var i = averagingFrameLength - 1; i < len; i++) { | ||
var avgUpSum = 0; | ||
var avgDownSum = 0; | ||
var count = 0; | ||
for (var j = i; j > Math.max(i - averagingFrameLength, 0); j--) { | ||
avgUpSum += upValues[j]; | ||
avgDownSum += downValues[j]; | ||
count++; | ||
} | ||
var avgUp = avgUpSum / count; | ||
var avgDown = avgDownSum / count; | ||
var rsi = 100 - (100 / (1 + avgUp / avgDown)); | ||
result.push({ x: xohlcValues[i][0], y: rsi }); | ||
} | ||
return result; | ||
}; | ||
export { simpleMovingAverage }; | ||
export { bollingerBands, exponentialMovingAverage, relativeStrengthIndex, simpleMovingAverage }; | ||
//# sourceMappingURL=lcjs-analysis.es.js.map |
@@ -1,1 +0,1 @@ | ||
var lcjsa=function(r){"use strict";return r.simpleMovingAverage=function(r,n){for(var t=r.length,u=[],a=[],f=0,i=0;i<t;i++){var v=r[i],c=v[4];if(f+=c,i>=n-1){var e=f/n;u.push({x:v[0],y:e}),f-=a.shift()}a.push(c)}return u},r}({}); | ||
var lcjsa=function(r){"use strict";var a=function(r,a){for(var v=r.length,o=[],n=[],f=0,t=0;t<v;t++){var i=r[t],u=i[4];if(f+=u,t>=a-1){var c=f/a;o.push({x:i[0],y:c}),f-=n.shift()}n.push(u)}return o},v=function(r){for(var a=r.length,v=0,o=0;o<a;o++)v+=r[o];var n=v/a,f=0;for(o=0;o<a;o++){var t=r[o];f+=(t-n)*(t-n)}return Math.sqrt(f/a)};return r.bollingerBands=function(r,o){for(var n=r.length,f=a(r,o),t=[],i=0;i<n;i++){var u=r[i];t[i]=(u[4]+u[3]+u[2])/3}var c=[];for(i=o-1;i<n;i++){var e=t.slice(i-(o-1),i+1),h=2*v(e),s=f[i-(o-1)];c.push({position:s.x,high:s.y+h,low:s.y-h})}return c},r.exponentialMovingAverage=function(r,a){var v,o=r.length,n=[],f=2/(a+1),t=0;for(v=0;v<a;v++){t+=(u=r[v])[4]}for(var i=t/a;v<o;v++){var u,c=(u=r[v])[4]*f+(void 0!==i?i*(1-f):0);v>=a-1&&n.push({x:u[0],y:c}),i=c}return n},r.relativeStrengthIndex=function(r,a){for(var v,o=r.length,n=[],f=[],t=[],i=0;i<o;i++){var u=r[i][4];if(void 0!==v){var c=u-v;c>0?(f[i]=c,t[i]=0):(t[i]=-c,f[i]=0)}v=u}for(i=a-1;i<o;i++){for(var e=0,h=0,s=0,x=i;x>Math.max(i-a,0);x--)e+=f[x],h+=t[x],s++;var y=100-100/(1+e/s/(h/s));n.push({x:r[i][0],y:y})}return n},r.simpleMovingAverage=a,r}({}); |
@@ -24,4 +24,102 @@ 'use strict'; | ||
}; | ||
var exponentialMovingAverage = function (xohlcValues, averagingFrameLength) { | ||
var len = xohlcValues.length; | ||
var result = []; | ||
var weighingMultiplier = 2 / (averagingFrameLength + 1); | ||
var i; | ||
var previousEMASum = 0; | ||
for (i = 0; i < averagingFrameLength; i++) { | ||
var xohlc = xohlcValues[i]; | ||
var value = xohlc[4]; | ||
previousEMASum += value; | ||
} | ||
var previousEMA = previousEMASum / averagingFrameLength; | ||
for (; i < len; i++) { | ||
var xohlc = xohlcValues[i]; | ||
var value = xohlc[4]; | ||
var ema = value * weighingMultiplier + (previousEMA !== undefined ? previousEMA * (1 - weighingMultiplier) : 0); | ||
if (i >= averagingFrameLength - 1) { | ||
result.push({ x: xohlc[0], y: ema }); | ||
} | ||
previousEMA = ema; | ||
} | ||
return result; | ||
}; | ||
var standardDeviation = function (values) { | ||
var len = values.length; | ||
var sum = 0; | ||
for (var i = 0; i < len; i++) { | ||
sum += values[i]; | ||
} | ||
var avg = sum / len; | ||
var sumSqDiff = 0; | ||
for (var i = 0; i < len; i++) { | ||
var value = values[i]; | ||
sumSqDiff += (value - avg) * (value - avg); | ||
} | ||
return Math.sqrt(sumSqDiff / len); | ||
}; | ||
var bollingerBands = function (xohlcValues, averagingFrameLength) { | ||
var len = xohlcValues.length; | ||
var smaValues = simpleMovingAverage(xohlcValues, averagingFrameLength); | ||
var typicalPrices = []; | ||
for (var i = 0; i < len; i++) { | ||
var xohlc = xohlcValues[i]; | ||
typicalPrices[i] = (xohlc[4] + xohlc[3] + xohlc[2]) / 3; | ||
} | ||
var bollingerBands = []; | ||
for (var i = averagingFrameLength - 1; i < len; i++) { | ||
var valuesForSD = typicalPrices.slice(i - (averagingFrameLength - 1), i + 1); | ||
var standardDeviation2 = 2 * standardDeviation(valuesForSD); | ||
var sma = smaValues[i - (averagingFrameLength - 1)]; | ||
bollingerBands.push({ | ||
position: sma.x, | ||
high: sma.y + standardDeviation2, | ||
low: sma.y - standardDeviation2 | ||
}); | ||
} | ||
return bollingerBands; | ||
}; | ||
var relativeStrengthIndex = function (xohlcValues, averagingFrameLength) { | ||
var len = xohlcValues.length; | ||
var result = []; | ||
var upValues = []; | ||
var downValues = []; | ||
var prevValue; | ||
for (var i = 0; i < len; i++) { | ||
var value = xohlcValues[i][4]; | ||
if (prevValue !== undefined) { | ||
var diff = value - prevValue; | ||
if (diff > 0) { | ||
upValues[i] = diff; | ||
downValues[i] = 0; | ||
} | ||
else { | ||
downValues[i] = -diff; | ||
upValues[i] = 0; | ||
} | ||
} | ||
prevValue = value; | ||
} | ||
for (var i = averagingFrameLength - 1; i < len; i++) { | ||
var avgUpSum = 0; | ||
var avgDownSum = 0; | ||
var count = 0; | ||
for (var j = i; j > Math.max(i - averagingFrameLength, 0); j--) { | ||
avgUpSum += upValues[j]; | ||
avgDownSum += downValues[j]; | ||
count++; | ||
} | ||
var avgUp = avgUpSum / count; | ||
var avgDown = avgDownSum / count; | ||
var rsi = 100 - (100 / (1 + avgUp / avgDown)); | ||
result.push({ x: xohlcValues[i][0], y: rsi }); | ||
} | ||
return result; | ||
}; | ||
exports.bollingerBands = bollingerBands; | ||
exports.exponentialMovingAverage = exponentialMovingAverage; | ||
exports.relativeStrengthIndex = relativeStrengthIndex; | ||
exports.simpleMovingAverage = simpleMovingAverage; | ||
//# sourceMappingURL=lcjs-analysis.js.map |
{ | ||
"name": "@arction/lcjs-analysis", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "A data analysis library.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
50395
254
1