question for one and all.
based upon history of btc vs $USD (@gox) ... what is the largest swing in the following periods:
1 minute
5 minutes
15 minutes
30 minutes
60 minutes
120 minutes
180 minutes
anyone?
You can gather this info yourself by looking at the historical charts. Don't be lazy.
I think you're underestimating the problem.
EDIT: a naive sql query on the trades table runs way too long. I could do it another way though, would take roughly 2 hours. So if the info is important enough for you, Viceroy, you can try to bribe me
Just use the CSV and Ruby or Perl to parse the data.
Accessing and working with the data is not the problem: Unless he meant "timeframes" instead of "periods" you need to consider every possible pair of trades with times of execution no further than 60 seconds apart (could also be 2 seconds). You can't just use min/max (or even average or last price) values of some "minute bins" and look for the highest delta between 2 consecutive ones. The way I'd implement it would be to have a sliding window cointaining all trades from time t to time t-60s tracking min/max of the trades and then move it through the data (by moving t to the next trade and adding it to the list of the trades in the frame, then checking wether the oldest trade in the frame has time < t-60s and remove it if that's the case. keep trades in the frame in a list ordered by price so "max" can be adjusted in case the removed trade is the one with the highest price). Difference between "max" and "min" is the your swings size. Record the IDs of the 2 trades responsible for the largest swing and the solution is found.
If that sounds too complicated to you, please share your simpler solution.
For each time period N in seconds do:
create 2 priority queues, one min, one max, with the following modifications:
modify push to keep track of the last timestamp
modify peek to pop off and throw away that are more N seconds old until it finds a trade within the timeframe or empties itself
set max_spread = 0
then, for each trade:
push the trade to both queues
spread = peek(max_queue) - peek(min_queue)
max_spread = spread if spread > max_spread
Not sure if it is simpler, but at least to me it is easier to prove to myself it works as well as easy to recognize that for any number of seconds N you can calculate the max spread in worst case O(n^2*lg(n)) time, where n is the number of trades.