Replace OHLCValueEvent

This commit is contained in:
2018-11-14 20:53:09 -08:00
parent 92c3636d8f
commit 8cf12a27fb
3 changed files with 14 additions and 57 deletions

View File

@ -108,18 +108,21 @@ insert into TBHKStream
-- Simple moving average streams -- Simple moving average streams
-- --
-- SMACloseStream contains OHLCValueEvents. These are like -- SMACloseStream bundles a simple moving average of the close values
-- OHLCEvents, but add an extra field for an arbitrary value. In this -- with the values of the OHLCStream.
-- stream, that extra value will contain the average of OHLC close create schema SMACloseStream as (time DateTime,
-- values. open double,
create schema SMACloseStream as ats.plugin.OHLCValueEvent high double,
low double,
close double,
averageClose double)
-- Average the most recent OHLC close values from OHLCStream and -- Average the most recent OHLC close values from OHLCStream and
-- post an event that contains open, high, low, close, and -- post an event that contains open, high, low, close, and
-- SMA(close). The number of OHLC events used in the SMA calc is set -- SMA(close). The number of OHLC events used in the SMA calc is set
-- by the SMASize variable. -- by the SMASize variable.
insert into SMACloseStream insert into SMACloseStream
select new ats.plugin.OHLCValueEvent(time, open, high, low, close, Avg(close)) select time, open, high, low, close, Avg(close) as averageClose
from OHLCStream#length(SMASize) from OHLCStream#length(SMASize)
@ -134,13 +137,11 @@ create schema BStream as (low double, time DateTime)
-- Listen to the last "RefSize" number of SMACloseStream events. Look -- Listen to the last "RefSize" number of SMACloseStream events. Look
-- for an OHLC bar with a lower average close than its neighbors. Add -- for an OHLC bar with a lower average close than its neighbors. Add
-- that bar's low value and its timestamp to the stream. As described -- that bar's low value and its timestamp to the stream.
-- in SMACloseStream, "value" in the query below represents
-- SMA(close).
insert into BStream insert into BStream
select prev(1, low) as low, prev(1, time) as time from SMACloseStream#length(RefSize) select prev(1, low) as low, prev(1, time) as time from SMACloseStream#length(RefSize)
where prev(0, value) > prev(1, value) where prev(0, averageClose) > prev(1, averageClose)
and prev(1, value) < prev(2, value) and prev(1, averageClose) < prev(2, averageClose)
-- Define B1 to contain the same fields as BStream -- Define B1 to contain the same fields as BStream
@ -168,8 +169,8 @@ create schema PStream as (low double, time DateTime)
-- Add that low value and its timestamp to the stream. -- Add that low value and its timestamp to the stream.
insert into PStream insert into PStream
select prev(1, low) as low, prev(1, time) as time from SMACloseStream#length(RefSize) select prev(1, low) as low, prev(1, time) as time from SMACloseStream#length(RefSize)
where prev(0, value) < prev(1, value) where prev(0, averageClose) < prev(1, averageClose)
and prev(1, value) > prev(2, value) and prev(1, averageClose) > prev(2, averageClose)
-- P1 contains the most recent low value and time from PStream. -- P1 contains the most recent low value and time from PStream.
-- This is the last time an average close was higher -- This is the last time an average close was higher

View File

@ -16,7 +16,6 @@ import org.slf4j.LoggerFactory;
import ats.orders.MarketOrderRequest; import ats.orders.MarketOrderRequest;
import ats.plugin.OHLCEvent; import ats.plugin.OHLCEvent;
import ats.plugin.OHLCPlugInViewFactory; import ats.plugin.OHLCPlugInViewFactory;
import ats.plugin.OHLCValueEvent;
public class EsperProcessor implements TickProcessor { public class EsperProcessor implements TickProcessor {
@ -36,7 +35,6 @@ public class EsperProcessor implements TickProcessor {
// register event types defined in java classes // register event types defined in java classes
config.addEventType(TickEvent.class); config.addEventType(TickEvent.class);
config.addEventType(OHLCEvent.class); config.addEventType(OHLCEvent.class);
config.addEventType(OHLCValueEvent.class);
config.addEventType(DateTime.class); config.addEventType(DateTime.class);
// add OHLC plugin // add OHLC plugin

View File

@ -1,42 +0,0 @@
package ats.plugin;
import org.joda.time.DateTime;
/**
* OHLCValueEvent stores one bar of OHLC info.
*/
public class OHLCValueEvent extends OHLCEvent {
private double value;
public OHLCValueEvent() {
this(null, 0, 0, 0, 0, 0);
}
public OHLCValueEvent(DateTime time,
double open, double high,
double low, double close,
double value)
{
super(time, open, high, low, close);
this.value = value;
}
public static OHLCValueEvent make(DateTime time,
double open, double high,
double low, double close,
double value)
{
return new OHLCValueEvent(time, open, high, low, close, value);
}
public Double getValue() { return value; }
/**
* Return a human readable representation of this event.
*/
public String toString() {
return String.format("OHLCValueEvent[%s, open=%.3f, high=%.3f, low=%.3f, close=%.3f, value=%.3f]",
getTime(), getOpen(), getHigh(), getLow(), getClose(), value);
}
}