AlgoQuant, an integrated trading strategy research and backtesting system
com.numericalmethod.algoquant.model.signal.technical.ohlc

## Class HighLows

• java.lang.Object
• com.numericalmethod.algoquant.model.signal.technical.ohlc.HighLows

• public class HighLows
extends Object
Keeps track of the highest and lowest prices in OHLCBars over multiple periods of time. It can for example be used to get the highest price in the last n days. There are three frequencies (or periods) used by this class: The bar frequency at which OHLC bars are created, the frequency at which we keep track of the highest and lowest bars and the frequency at which the output of this class is updated. In general, the update frequency (e.g., instantly) must be at least as big as the bar frequency (e.g., daily), which in turn must be at least as big as the high-low frequency (e.g., weekly). For example, we receive tick-by-tick price data, and wish to aggregate the data into one-minute bars. This class can then be used to track the daily highs and lows. In this case, we set the update and high-low frequencies to Daily, the bar frequency to Minute. The highs and lows are tracked up to but excluding the last day. In the case where the latest update is always accounted for, set the update frequency to Instantly. If you need the last update to be accounted for, you can call forceUpdate(), to notify the object that the period can be regarded as finished.
• ### Constructor Summary

Constructors
Constructor and Description
HighLows(Frequency frequency)
Constructs a new instance, tracking the highs and lows at a certain frequency.
HighLows(Frequency barFrequency, Frequency highLowFrequency)
Constructs a new instance, keeping the OHLC bar information.
HighLows(Frequency updateFrequency, Frequency barFrequency, Frequency highLowFrequency)
Constructs a new instance.
• ### Method Summary

All Methods
Modifier and Type Method and Description
OHLCBar currentBar()
Gets the bar to which the latest price update was added.
OHLCBar currentHigh()
Returns the bar with the highest price in the current period (the last period for which an update was received).
OHLCBar currentLow()
Returns the bar with the lowest price in the current period (the last period for which an update was received).
void forceUpdate()
By default, the updates that are counted are determined by update frequency.
OHLCBar high(int n)
Gets the bar with the highest price over the given number of periods.
OHLCBar low(int n)
Gets the bar with the lowest price over the given number of periods.
int size()
Gets the number of periods for which we have bars.
void update(org.joda.time.DateTime t, double px)
Updates the highs and lows with the given price data.
• ### Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
• ### Constructor Detail

• #### HighLows

public HighLows(Frequency updateFrequency,
Frequency barFrequency,
Frequency highLowFrequency)
Constructs a new instance.
Parameters:
updateFrequency - the frequency at which new updates are included
barFrequency - the frequency at which we create the bars
highLowFrequency - the frequency at which we create the highs and lows
• #### HighLows

public HighLows(Frequency barFrequency,
Frequency highLowFrequency)
Constructs a new instance, keeping the OHLC bar information.
Parameters:
barFrequency - the frequency at which we create the bars
highLowFrequency - the frequency at which we create the highs and lows
• #### HighLows

public HighLows(Frequency frequency)
Constructs a new instance, tracking the highs and lows at a certain frequency.
Parameters:
frequency - the frequency to track the highs and lows
• ### Method Detail

• #### update

public void update(org.joda.time.DateTime t,
double px)
Updates the highs and lows with the given price data. All the price data that comes in must be ordered by time. If an update with an earlier time is received, a runtime exception will be thrown.
Parameters:
t - a timestamp
px - a price
• #### forceUpdate

public void forceUpdate()
By default, the updates that are counted are determined by update frequency. This method causes the output to reflect all price updates received by the instance regardless of the update frequency.

Hence this method could be called if you are certain that the period defined in updateGranularity has ended. If this is not the case then future price updates in that period will only be reflected in the output immediately if they are in the same OHLCBar.

• #### high

public OHLCBar high(int n)
Gets the bar with the highest price over the given number of periods. For example high(2) will get the highest bar from the last two completed periods.
Parameters:
n - the number of periods over which we want the highest bar. This number counts from 1.
Returns:
the bar with the highest price. If insufficient data is available, null will be returned
• #### low

public OHLCBar low(int n)
Gets the bar with the lowest price over the given number of periods. For example low(2) will get the lowest bar from the last two completed periods.
Parameters:
n - the number of periods over which we want the lowest bar. This number counts from 1.
Returns:
the bar with the lowest price. If insufficient data is available, null will be returned
• #### size

public int size()
Gets the number of periods for which we have bars.
Returns:
the number of periods
• #### currentHigh

public OHLCBar currentHigh()
Returns the bar with the highest price in the current period (the last period for which an update was received). If forceUpdate() hasn't been called then this bar won't yet be included in the output of the high(int) and low(int) methods.
Returns:
the bar with the highest price in the current period
• #### currentLow

public OHLCBar currentLow()
Returns the bar with the lowest price in the current period (the last period for which an update was received). If forceUpdate() hasn't been called then this bar won't yet be included in the output of the high(int) and low(int) methods.
Returns:
the bar with the lowest price in the current period
• #### currentBar

public OHLCBar currentBar()
Gets the bar to which the latest price update was added.
Returns:
the most recent bar