algorithm to finding the first price hit by the end of the day. searching algorithm.
Anonymous User
221

I have a series of prices throughout the day. I need to find whether the price at each time point will first go up by 50% or drop by 50% by the end of the day.

Currently I can only think about using brute force -- compare the current price with each of the following prices until I meet the above requirement or go through all the prices in the day.

Are there any good methods to solve the problem? Thank you very much in advance!

there are six price movements by the end of the day.
price=[1, 1.3, 0.9, 1.5, 0.65, 3]
label=[1, -1, 1, -1, 1]
Explanation:
at t0, the price is 1 and it first goes up to 1.5 rather than down to 0.5, so the label is 1.
at t1, the price is 1.3 and it first drops down to 0.65 rather than up to 1.95, so the label is -1.
at t2, the price is 0.9 and it first goes up to 1.5 (0.9*1.5=1.35) rather than down to 0.45(0.9*0.5), so the label is 1.
at t3, the price is 1.5 and it first drops down to 0.65 (1.5*0.5=0.75) rather than up to 3, so the label is -1.
at t4, the price is 0.65 and it first goes up to 3 (0.65*1.5=0.975) rather than down to 0.325 (0.65*0.5), so the label is 1.
If the price change lies within -50% - +50%, the label will be 0.
Comments (2)