Skip to content

Commit

Permalink
windowstats @ 1st, 99th percentile (12th~ish too)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sarah White committed Jul 16, 2014
1 parent b554b26 commit a9c8a94
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions methods/indicators/windowstats.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,32 @@ var Indicator = function(period) {
this.sorted = [];
this.enough = false;
this.age = 0;
this.p1st = 0;
this.p5th = 0;
this.p10th = 0;
this.pFancyEighth = 0;
this.p25th = 0;
this.p40th = 0;
this.p50th = 0;
this.p60th = 0;
this.p75th = 0;
this.p90th = 0;
this.p95th = 0;
this.p99th = 0;
this.p1ndx = Math.floor(this.period * (1 / 100));
this.p5ndx = Math.floor(this.period * (5 / 100));
this.p10ndx = Math.floor(this.period * (10 / 100));
var FancyEight = (0 - (1 / 3)); // one over cube root 541
FancyEight = Math.pow(541, FancyEight); // is aprox 1/8th
this.pFancyEightNdx = Math.floor(this.period * FancyEight);
this.p25ndx = Math.floor(this.period * (25 / 100));
this.p40ndx = Math.floor(this.period * (40 / 100));
this.p50ndx = Math.floor(this.period * (50 / 100));
this.p60ndx = Math.floor(this.period * (60 / 100));
this.p75ndx = Math.floor(this.period * (75 / 100));
this.p90ndx = Math.floor(this.period * (90 / 100));
this.p95ndx = Math.floor(this.period * (95 / 100));
this.p99ndx = Math.floor(this.period * (99 / 100));
this.vwap = 0;
};

Expand Down Expand Up @@ -73,15 +81,18 @@ Indicator.prototype.update = function(price) {
};

Indicator.prototype.calculate = function() {
this.p1st = this.sorted[this.p1ndx];
this.p5th = this.sorted[this.p5ndx];
this.p10th = this.sorted[this.p10ndx];
this.pFancyEighth = this.sorted[this.pFancyEightNdx];
this.p25th = this.sorted[this.p25ndx];
this.p40th = this.sorted[this.p40ndx];
this.p50th = this.sorted[this.p50ndx];
this.p60th = this.sorted[this.p60ndx];
this.p75th = this.sorted[this.p75ndx];
this.p90th = this.sorted[this.p90ndx];
this.p95th = this.sorted[this.p95ndx];
this.p99th = this.sorted[this.p99ndx];
};

module.exports = Indicator;

0 comments on commit a9c8a94

Please sign in to comment.