Skip to content

Instantly share code, notes, and snippets.

@zackster
Created April 22, 2013 02:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zackster/5432075 to your computer and use it in GitHub Desktop.
Save zackster/5432075 to your computer and use it in GitHub Desktop.
csv:
time, price
read in csv; populate array:
price_data = [[time,price],[time,price]]
sort array on time
pct_aggregate = [];
pct_aggregate_summed = [];
time_limit = 48h
last_trade_time = price_data[count(price_data)]['time'] - time_limit
i = 0
while (price_data[i]['time'] < last_trade_time){
start_price = price_data[i]['price']
start_time = price_data[i]['time'] //first time
end_time = start_time + 48h
pct_temp = [];
j = i;
distribution_limit = 0;
while (price_data[j][0] < end_time){
pct_change = (price_data[j]['price']-start_price)/start_price;
//limit pct_change to only positive values
if(pct_change < 0) {
distribution_limit = 0;
}
if (pct_change > 0.0086) {
pct_temp.push([(start_price*1+pct_change), pct_change, distribution_limit]);
distribution_limit = Math.MAX(price_data[j]['price'], distribution_limit);
}
j++;
}
//pct_temp contains decimals - e.g. 0.02 = 2%
for each pct_temp as (new_price, pct_change, distribution_limit) {
interval = round(pct*1000)/10; //give 0.1% intervals
foreach interval in range(distribution_limit, new_price) {
pct_aggregate[interval]++; //add one trade to the interval
}
}
i++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment