Hey,
Given a table of times and prices, what’s the best way to find the last time each price traded (or a higher price) before it’s corresponding time?
I can do it with a loop and I’ve gotten pretty close with an aj however the condition on the first column of an aj is = rather than >=.
An example:
/ generate some random trades
trades: flip (time
price)!(asc 10000?0D0;sums (10000?9)-4);
/ some trades generate a signal price (random offset in this example)
signals: 10?trades;
signals[original_price]: signals[
price];
signals[`offset]: 1+10?10;
signals[price] +: signals[
offset];
/ what i’m looking for
results2: signals;
j: 0;
do[count results2;
r: exec first time, first price from time xdesc trades where time<results2[j][
time], price>=results2[j][`price];
results2: update real_last_time: r[time], real_last_price: r[
price] from results2 where i=j;
j+:1;
];
/ closest i’ve gotten
results1: aj[price
time;signals;update last_time: time, last_price: price from trades];
/ comparison
results1 lj time
price xkey results2
I know there’s probably a very easy solution that I can’t see.
Thanks,
Sean