I'm getting a stream of numbers from a random walk, and I'm successfully getting the min and max from that random walk using this code:
const rw = require('random-walk')
const num = new rw
let nums = []
num.on("result", number => {
nums.push(number.toFixed(4))
let minmax = minMax(30,30) // minMax(low-period, high-period) <-- Usage
function minMax(l, h){
let lows = nums.slice(-l) //slice a given range for highs
let highs = nums.slice(-h) //slice a given range for lows
let low = Math.min(...lows) //get the min for the range
let high = Math.max(...highs) //get the max for the range
return {low: low, high: high}
}
console.log(minmax)
let ha = angle(number, minmax.high) // high angle
let la = angle(minmax.low, number) // low angle
function angle(a, h){
return Math.acos(a/h)*180/Math.PI
}
if(la == 0 || ha == 0){
nums = nums.slice(-30)
}
})
num.get("walk", {rate: 50, base: 200, type: "positive", scale: 2000, pseudo: false})
What I'm trying to figure out, is how to further find a min and max of the maximums (A); and then find a min and a max of the minimums (B).
Please refer to this image for sections A and B in purple respectively:
I believe I need to set a new variable to the output of my minMax
function but use smaller periods, but I'm not 100% sure. When I have tried this, I find that sometimes the max of the maximum range is also the max of the minimum range and the same is true for the min of the maximum and minimum ranges. Apologies if that's confusing. I hope the image makes it clear what I'm trying to accomplish.
Any thoughts about how to solve this problem would be great!