Matching a Sequence of Events

Place MATCHING and WHERE clauses on output streams to produce a set of sequenced data.

The example creates three schemas: StocksSchema, OptionsSchema, and OutSchema. The example then creates an input window named InTrades that references StocksSchema; an input window named InOptions that references OptionsSchema; and two output streams named TradeOptMatch and TradeOptFilter that both reference OutSchema.

TradeOptMatch uses the MATCHING clause to retrieve rows that match and have the same trade symbol, over a one-second period. TradeOptFilter uses a SELECT statement to pull data from TradeOptMatch; a WHERE clause tells TradeOptFilter to output data from TradeOptMatch only where the product of 0.005 * TradeOptMatch.StockPrice is greater than the option price.

CREATE OUTPUT STREAM TradeOptMatch 
		SCHEMA OutSchema  
AS
		SELECT 
    t.Ts as Ts,
    o.Ts as OptionTs,
    t.Symbol as Symbol,
    t.Price as StockPrice,
    t.Volume as StockVolume,
    o.StockSymbol as StockSymbol,
    o.OptionSymbol as OptionSymbol,
    o.Price as OptionPrice,
    o.Volume as OptionVolume
		FROM 
    InTrades  as t,
    InOptions as o
		MATCHING  
    [1 seconds: t , o ]
		ON
    t.Symbol = o.StockSymbol 

CREATE OUTPUT stream TradeOptFilter 
		SCHEMA OutSchema
 AS 
  SELECT * FROM TradeOptMatch 
    WHERE 0.005 * TradeOptMatch.StockPrice < TradeOptMatch.OptionPrice
    
;

The example attaches a File CSV Input adapter named csvInConn1 to InTrades, and a File CSV Input adapter named csvInConn2 to InOptions. The example also attaches a File CSV Output adapter named outAdapter to TradeOptFilter to publish the filter results to a file, since data cannot be viewed in-stream.