Created
April 22, 2013 02:34
-
-
Save zackster/5432075 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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