public class TimeCappedMovingAverageIntervalEstimator extends MovingAverageIntervalEstimator
A time capped interval estimator is useful for conservatively estimating time intervals in environments where rates can change dramatically and semi-statically. For example, the rate of market rate updates seen just before market close can be very high, dropping dramatically at market close and staying low thereafter. A non-time-capped moving average estimator will project short estimated time interval long after market close, while a time capped interval estimator will avoid carrying the small time interval beyond the time cap.
TimeCappedMovingAverageIntervalEstimator estimates time intervals by averaging the time interval values recorded in a moving window, but if any of the results in the moving window occur outside of the capped time span requested, only the results that fall within the time cap will be considered.
TimeCappedMovingAverageIntervalEstimator can react to pauses reported by an optional PauseDetector by temporarily expanding the time cap to include each pause length, until such a time that the original time cap no longer overlaps with the pause. It will also subtract the pause length from interval times measured across a detected pause. Providing a pause detector is highly recommended, as without one the time cap can cause over-conservative interval estimation (i.e. estimated interval times that are much higher than needed) in the presence of pauses.
All times and time units are in nanoseconds
count, intervalEndTimes, windowLength, windowMagnitude, windowMask| Constructor and Description |
|---|
TimeCappedMovingAverageIntervalEstimator(int requestedWindowLength,
long timeCap) |
TimeCappedMovingAverageIntervalEstimator(int requestedWindowLength,
long timeCap,
PauseDetector pauseDetector) |
| Modifier and Type | Method and Description |
|---|---|
long |
getEstimatedInterval(long when)
Provides the estimated interval
|
void |
recordInterval(long when)
Record an interval
|
void |
stop()
Stop the tracking via the pauseDetector, and remove this estimator from the pause detector's listeners.
|
String |
toString() |
getCurrentPositionpublic TimeCappedMovingAverageIntervalEstimator(int requestedWindowLength,
long timeCap)
requestedWindowLength - The requested length of the moving window. May be rounded up to nearest
power of 2.timeCap - The cap on time span length (in nanosecond units) in which all window results must fit
in order for average estimate to be providedpublic TimeCappedMovingAverageIntervalEstimator(int requestedWindowLength,
long timeCap,
PauseDetector pauseDetector)
requestedWindowLength - The requested length of the moving window. May be rounded up to nearest
power of 2.timeCap - The cap on time span length in which all window results must fit in order for average
estimate to be providedpauseDetector - The PauseDetector to use to track pausespublic void recordInterval(long when)
IntervalEstimatorrecordInterval in class MovingAverageIntervalEstimatorwhen - the end time (in nanoTime units) at which the interval was observed.public long getEstimatedInterval(long when)
IntervalEstimatorgetEstimatedInterval in class MovingAverageIntervalEstimatorwhen - the time (preferably now) at which the estimated interval is requested.public void stop()
Copyright © 2015. All rights reserved.