Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

increased accuracy of stored prices

  • Loading branch information...
commit 78acad33952837890abeda7fbc9b3d02158c7486 1 parent 86378e6
@mikedanese mikedanese authored
Showing with 8 additions and 7 deletions.
  1. +8 −7 src/main/java/com/raskol/tradebot/TickerService.java
View
15 src/main/java/com/raskol/tradebot/TickerService.java
@@ -1,6 +1,7 @@
package com.raskol.tradebot;
import com.codahale.metrics.ExponentiallyDecayingReservoir;
+import com.codahale.metrics.SlidingWindowReservoir;
import com.google.common.util.concurrent.AbstractScheduledService;
import com.xeiam.xchange.ExchangeFactory;
import com.xeiam.xchange.bitstamp.BitstampExchange;
@@ -21,11 +22,11 @@
private final PollingMarketDataService marketDataService = ExchangeFactory.INSTANCE
.createExchange(BitstampExchange.class.getName()).getPollingMarketDataService();
- private final ExponentiallyDecayingHistogram oneMinute = getHistogram("one minute", SAMPLE_SIZE, getAlpha(1, TimeUnit.MINUTES));
- private final ExponentiallyDecayingHistogram oneHour = getHistogram("one hour", SAMPLE_SIZE, getAlpha(1, TimeUnit.HOURS));
- private final ExponentiallyDecayingHistogram oneDay = getHistogram("one day", SAMPLE_SIZE, getAlpha(1, TimeUnit.DAYS));
- private final ExponentiallyDecayingHistogram fiveDays = getHistogram("five days", SAMPLE_SIZE, getAlpha(5, TimeUnit.DAYS));
- private final ExponentiallyDecayingHistogram oneMonth = getHistogram("one month", SAMPLE_SIZE, getAlpha(30, TimeUnit.DAYS));
+ private final ExponentiallyDecayingHistogram oneMinute = getExponentiallyDecayingHistogram("one minute", SAMPLE_SIZE, getAlpha(1, TimeUnit.MINUTES));
+ private final ExponentiallyDecayingHistogram oneHour = getExponentiallyDecayingHistogram("one hour", SAMPLE_SIZE, getAlpha(1, TimeUnit.HOURS));
+ private final ExponentiallyDecayingHistogram oneDay = getExponentiallyDecayingHistogram("one day", SAMPLE_SIZE, getAlpha(1, TimeUnit.DAYS));
+ private final ExponentiallyDecayingHistogram fiveDays = getExponentiallyDecayingHistogram("five days", SAMPLE_SIZE, getAlpha(5, TimeUnit.DAYS));
+ private final ExponentiallyDecayingHistogram oneMonth = getExponentiallyDecayingHistogram("one month", SAMPLE_SIZE, getAlpha(30, TimeUnit.DAYS));
private final List<ExponentiallyDecayingHistogram> histograms = Arrays.asList(oneMinute, oneHour, oneDay, fiveDays, oneMonth);
@Override
@@ -34,7 +35,7 @@ protected void runOneIteration() throws Exception {
for (Trade trade : trades.getTrades()) {
final long time = trade.getTimestamp().getTime();
- final long price = trade.getPrice().getAmountMajorLong();
+ final long price = trade.getPrice().getAmountMinorLong();
for (ExponentiallyDecayingHistogram histogram : histograms) {
histogram.update(price, time);
}
@@ -50,7 +51,7 @@ private double getAlpha(Integer duration, TimeUnit timeUnit) {
return 1 - Math.exp(-INTERVAL / timeUnit.toSeconds(duration));
}
- private ExponentiallyDecayingHistogram getHistogram(String label, int sampleSize, double alpha) {
+ private ExponentiallyDecayingHistogram getExponentiallyDecayingHistogram(String label, int sampleSize, double alpha) {
return new ExponentiallyDecayingHistogram(new ExponentiallyDecayingReservoir(sampleSize, alpha), label);
}
Please sign in to comment.
Something went wrong with that request. Please try again.