@arction/lcjs-analysis
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -80,5 +80,7 @@ var simpleMovingAverage = function (xohlcValues, averagingFrameLength) { | ||
var len = xohlcValues.length; | ||
if (len < averagingFrameLength) | ||
return []; | ||
var result = []; | ||
var upValues = []; | ||
var downValues = []; | ||
var gains = []; | ||
var losses = []; | ||
var prevValue; | ||
@@ -90,8 +92,8 @@ for (var i = 0; i < len; i++) { | ||
if (diff > 0) { | ||
upValues[i] = diff; | ||
downValues[i] = 0; | ||
gains[i] = diff; | ||
losses[i] = 0; | ||
} | ||
else { | ||
downValues[i] = -diff; | ||
upValues[i] = 0; | ||
losses[i] = -diff; | ||
gains[i] = 0; | ||
} | ||
@@ -101,15 +103,23 @@ } | ||
} | ||
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 }); | ||
var sum = function (prev, cur) { return prev + cur; }; | ||
var prevAvgGain = gains | ||
.slice(0, averagingFrameLength + 1) | ||
.reduce(sum, 0) | ||
/ averagingFrameLength; | ||
var prevAvgLoss = losses | ||
.slice(0, averagingFrameLength + 1) | ||
.reduce(sum, 0) | ||
/ averagingFrameLength; | ||
var firstRS = prevAvgGain / prevAvgLoss; | ||
var firstRSI = 100 - (100 / (1 + firstRS)); | ||
result.push({ x: xohlcValues[averagingFrameLength][0], y: firstRSI }); | ||
for (var i = averagingFrameLength + 1; i < len; i++) { | ||
var avgGain = (prevAvgGain * (averagingFrameLength - 1) + gains[i]) / averagingFrameLength; | ||
var avgLoss = (prevAvgLoss * (averagingFrameLength - 1) + losses[i]) / averagingFrameLength; | ||
var smoothedRS = (prevAvgGain * (averagingFrameLength - 1) + gains[i]) / | ||
(prevAvgLoss * (averagingFrameLength - 1) + losses[i]); | ||
var RSI = 100 - (100 / (1 + smoothedRS)); | ||
result.push({ x: xohlcValues[i][0], y: RSI }); | ||
prevAvgGain = avgGain; | ||
prevAvgLoss = avgLoss; | ||
} | ||
@@ -116,0 +126,0 @@ return result; |
@@ -1,1 +0,1 @@ | ||
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}({}); | ||
var lcjsa=function(r){"use strict";var n=function(r,n){for(var v=r.length,a=[],o=[],f=0,t=0;t<v;t++){var i=r[t],u=i[4];if(f+=u,t>=n-1){var e=f/n;a.push({x:i[0],y:e}),f-=o.shift()}o.push(u)}return a},v=function(r){for(var n=r.length,v=0,a=0;a<n;a++)v+=r[a];var o=v/n,f=0;for(a=0;a<n;a++){var t=r[a];f+=(t-o)*(t-o)}return Math.sqrt(f/n)};return r.bollingerBands=function(r,a){for(var o=r.length,f=n(r,a),t=[],i=0;i<o;i++){var u=r[i];t[i]=(u[4]+u[3]+u[2])/3}var e=[];for(i=a-1;i<o;i++){var c=t.slice(i-(a-1),i+1),x=2*v(c),y=f[i-(a-1)];e.push({position:y.x,high:y.y+x,low:y.y-x})}return e},r.exponentialMovingAverage=function(r,n){var v,a=r.length,o=[],f=2/(n+1),t=0;for(v=0;v<n;v++){t+=(u=r[v])[4]}for(var i=t/n;v<a;v++){var u,e=(u=r[v])[4]*f+(void 0!==i?i*(1-f):0);v>=n-1&&o.push({x:u[0],y:e}),i=e}return o},r.relativeStrengthIndex=function(r,n){var v=r.length;if(v<n)return[];for(var a,o=[],f=[],t=[],i=0;i<v;i++){var u=r[i][4];if(void 0!==a){var e=u-a;e>0?(f[i]=e,t[i]=0):(t[i]=-e,f[i]=0)}a=u}var c=function(r,n){return r+n},x=f.slice(0,n+1).reduce(c,0)/n,y=t.slice(0,n+1).reduce(c,0)/n,h=100-100/(1+x/y);o.push({x:r[n][0],y:h});for(i=n+1;i<v;i++){var s=(x*(n-1)+f[i])/n,d=(y*(n-1)+t[i])/n,g=100-100/(1+(x*(n-1)+f[i])/(y*(n-1)+t[i]));o.push({x:r[i][0],y:g}),x=s,y=d}return o},r.simpleMovingAverage=n,r}({}); |
@@ -84,5 +84,7 @@ 'use strict'; | ||
var len = xohlcValues.length; | ||
if (len < averagingFrameLength) | ||
return []; | ||
var result = []; | ||
var upValues = []; | ||
var downValues = []; | ||
var gains = []; | ||
var losses = []; | ||
var prevValue; | ||
@@ -94,8 +96,8 @@ for (var i = 0; i < len; i++) { | ||
if (diff > 0) { | ||
upValues[i] = diff; | ||
downValues[i] = 0; | ||
gains[i] = diff; | ||
losses[i] = 0; | ||
} | ||
else { | ||
downValues[i] = -diff; | ||
upValues[i] = 0; | ||
losses[i] = -diff; | ||
gains[i] = 0; | ||
} | ||
@@ -105,15 +107,23 @@ } | ||
} | ||
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 }); | ||
var sum = function (prev, cur) { return prev + cur; }; | ||
var prevAvgGain = gains | ||
.slice(0, averagingFrameLength + 1) | ||
.reduce(sum, 0) | ||
/ averagingFrameLength; | ||
var prevAvgLoss = losses | ||
.slice(0, averagingFrameLength + 1) | ||
.reduce(sum, 0) | ||
/ averagingFrameLength; | ||
var firstRS = prevAvgGain / prevAvgLoss; | ||
var firstRSI = 100 - (100 / (1 + firstRS)); | ||
result.push({ x: xohlcValues[averagingFrameLength][0], y: firstRSI }); | ||
for (var i = averagingFrameLength + 1; i < len; i++) { | ||
var avgGain = (prevAvgGain * (averagingFrameLength - 1) + gains[i]) / averagingFrameLength; | ||
var avgLoss = (prevAvgLoss * (averagingFrameLength - 1) + losses[i]) / averagingFrameLength; | ||
var smoothedRS = (prevAvgGain * (averagingFrameLength - 1) + gains[i]) / | ||
(prevAvgLoss * (averagingFrameLength - 1) + losses[i]); | ||
var RSI = 100 - (100 / (1 + smoothedRS)); | ||
result.push({ x: xohlcValues[i][0], y: RSI }); | ||
prevAvgGain = avgGain; | ||
prevAvgLoss = avgLoss; | ||
} | ||
@@ -120,0 +130,0 @@ return result; |
{ | ||
"name": "@arction/lcjs-analysis", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "A data analysis library.", | ||
@@ -58,6 +58,6 @@ "keywords": [ | ||
"rollup-plugin-typescript2": "^0.22.1", | ||
"ts-node": "^8.3.0", | ||
"ts-node": "^8.4.1", | ||
"tslint": "^5.18.0", | ||
"typedoc": "^0.15.0", | ||
"typescript": "^3.5.3" | ||
"typescript": "^3.6.3" | ||
}, | ||
@@ -64,0 +64,0 @@ "publishConfig": { |
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
56116
274
0