Cep training
Download
1 / 70

CEP TRAINING - PowerPoint PPT Presentation


  • 178 Views
  • Uploaded on

CEP TRAINING. ALERI CEP PRODUCT SUITE DAY2 SESSION. LEADING CEP PLATFORMS FOR SOPHISTICATED EVENT-DRIVEN APPLICATIONS. Development Training Logistics Introduction to CEP and Aleri Lab: Install Aleri Studio – REFERENCE ONLY Studio Development Topics with Labs

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' CEP TRAINING' - derron


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Cep training

CEP TRAINING

ALERI CEP PRODUCT SUITE

DAY2 SESSION

LEADING CEP PLATFORMS FOR SOPHISTICATED EVENT-DRIVEN APPLICATIONS


Development

Training Logistics

Introduction to CEP and Aleri

Lab: Install Aleri Studio – REFERENCE ONLY

Studio Development Topics with Labs

Source, Aggregation, and Filter Streams

Copy Streams and Input Windows

Compute and Extend Streams

Join and Union Streams

Flex Streams radio button z

SPLASH

Data Connectors

Playback

Event Cache

Pattern Streams

Wrap-up and Q&A

TRAINING AGENDA - DAY 1


Development

Review Flex Streams and SPLASH

Studio Debugging

Publish and Subscribe API

Example in Java

Excel RTD Adapter

Performance Factors and Application Tuning

Advanced Installation and Configuration

Enterprise Features – HA and Cluster

Foreign Functions

Open Q&A (as time allows)

TRAINING AGENDA – DAY 2


REVIEW

Flex Streams

And

Pattern Streams


Most advanced stream

One or more input streams

Ideal for custom logic

Can “call out” to Java and C++ methods

Each input stream requires a “SPLASH method”

Output per SPLASH methods

SPLASH (Streaming Platform LAnguage SHell)

C Like procedural scripting language

FLEX STREAMS


Simple ex: print (‘generating new order\n’);

If-then-else

while

Iterators

For (rec in MktData_stream)

vectors

Event caches

Dictionaries

Built-in functions, ex: firstnonnull(null,3,4,8);

Declarations, ex: int32 eventCt; eventCt := 4;

Int32 eventCt := 4;

Cast

typedef

SPLASH


typedef money euros;

euros price := 10.70d;

typeof(price) newPrice := 10.70d; equivalent to

money newPrice := 10.70d;

if (temperature < 0) {

display := 'below zero';

} else if (temperature = 0) {

display := 'zero';

} else {

display := 'above zero';

}

SPLASH - continued


int32 i := 0, squares := 0;

while (i < 10) {

squares := squares + (i * i);

i++;

}

SPLASH - continued


Records, with primary key before |

[ Market = 'NYSE'; Symbol='T'; | Shares=10; Price=22.88; ]

[ Market = 'NYSE'; Symbol='GM'; | Shares=5; Price=16.81; ]

Using typeof(myFlexStream) arec – so arec will be output:

typeof(BuyThis) arec;

Next page will have arec set.

SPLASH - continued


arec :=[ ID=aID++;

symbol= FilterBuy.symbol;side= FilterBuy.side;Symbol= FilterBuy.Symbol;|

volume= FilterBuy.volume; slice= FilterBuy.slice;

venue= FilterBuy.venue;

stale= FilterBuy.stale; ask= FilterBuy.ask;

askSz= FilterBuy.askSz; askTime= FilterBuy.askTime;

askCond= FilterBuy.askCond; bid= FilterBuy.bid;

bidSz= FilterBuy.bidSz; bidTime= FilterBuy.bidTime;

bidCond= FilterBuy.bidCond;OrderQty = aproduct;

]; setOpcode(arec,upsert); output arec;

SPLASH - continued


Code Function, even recursive:

int32 factorial(int32 x) {

if (x <= 0) {

return 1;

} else {

return factorial(x-1) * x;

}

}

SPLASH - continued


Vector Example:

vector(double) roots;

int32 i := 0;

double pi := 3.1415926, e := 2.7182818, sum1 := 0;

resize(roots, 8); // new size is 8, with each element set to null

while (i < 8) {

roots[i] := e ^ ((pi * i) / 4);

i++;

}

SPLASH - continued


Dictionaries “map” keys to “values”. Example:

dictionary(string, money) convertFromUSD;

convertFromUSD ['EUR'] := 1.272d;

Loop through all Dictionary elements:

for (currency in convertFromUSD) {

if (convertFromUSD[currency] > 1) {

Print ('currency ', currency, ' is worth more than one USD.\n');

}

}

SPLASH - continued


Event Cache

special SPLASH data structure for grouping and storing events from an input stream.

Events are grouped into buckets.

run aggregate operations like count, sum, and max

Declare event cache in Local block of a stream using name of the input stream. For example:

eventCache(Trades) events;

the declaration

SPLASH - continued


Group events into buckets by specifying columns, say by Trades that have the same number of shares:

shareseventCache(Trades[Shares]) eventsByShares;

Maximum “window” or latest events of X seconds:

eventCache(Trades[Symbol], 20 seconds) eventsBySymbol20Seconds;

Maximum “window” or latest X events:

eventCache(Trades[Symbol], 10 events) eventsBySymbol10Events;

SPLASH - continued


Can sort and also designate records with “coalesce” instead of events:

eventCache(Trades, coalesce, Price desc) eventsOrderByPrice;

eQ is event cache of quotes ranking ask or sell price from lowest to highest. With nth, can retrieve

aask0 := nth(0,eQ.ask); // from eventCache

aaskPrior1 := nth(1,eQ.ask); // from eventCache

aaskPrior2 := nth(2,eQ.ask); // from eventCache

SPLASH - continued


Another use of ‘nth’ instead of events:

-vector(int32) vec; resize (vec,3); // 3 elements

- int32 r; int32 max := 3;

- for (r in eQ) {

if (r < max) {

vec[r] := nth(r,eQ.ask);

r++;

}

}

SPLASH - continued


Call-out to Java method instead of events:

Retrieve a result(double) as input to options pricing

Sy6 is input stream; note its columns as input to method signature

// callout for Volatility

d_volatility := foreignJava ("com/g/bottomline/TheoryPrice", GImpliedVol,'(Ljava/lang/String;DDIDDDD)D‘, sy6.stcode,d_stockprice,sy6.strike,n_daystomaturity,sy6.LastPrice,sy6.noriskrate,0.0,0.005);

SPLASH - continued


Instructor will demo PropTrade model instead of events:

Focus on Flex Streams:

FlexQuotesAsk, SellThis, NewOrderSingle, FlexAck1, EMS, Cancel

Also focus on global declarations that create dictionaries that multiple streams use for state and trading position Mgt.

LAB4 – FLEX STREAMS


PATTERN STREAMS instead of events:


PATTERN STREAMS instead of events:

This example identifies a high probability of a pending terror event. Three “derived” streams are created with a rating (0 to 10) based on word matching with many dictionaries to match related translated words such as “bomb” with “walk” and “bridge” implying Brooklyn Bridge is a target given its famous walkway. The three streams are then evaluated together by a Pattern Stream. The output with pertinent information is then directed to NYPD.

within 30 seconds

from NY[Rep=NYPD;Rate=10;K=bomb;M1=walk;M2=bridge] as Brooklyn,

Eur1[Rep=LON;Rate=7; K=bomb; M1=Brooklyn] as Plan,

Eur2[Rep=Bank; Rate=7; K=bomb; M1=New York] as Finance,

on Plan fby Finance fby Brooklyn

output [Rep=NYPD; Rate=8; K=bomb; M1=‘Brooklyn Bridge’;];

21


Pattern stream options straddle 1 call 1 put all attributes same
Pattern Stream Options Straddle: 1 call, 1 put, all attributes same

PATTERN STREAM

within 300 seconds

from

MktRef[Security=sym; OPT_EXPIRE_DT=e1; OPT_STRIKE_PX=sp1; OPT_PUT_CALL='Call'; OPT_CONT_SIZE=c1 ]

as call,

MktRef[Security=sym; OPT_EXPIRE_DT=e1; OPT_STRIKE_PX=sp1; OPT_PUT_CALL='Put'; OPT_CONT_SIZE=c1 ]

as put

on call and put

{

aATMcall := (call.UNDL_PX_AT_OPT_TRADE-sp1)/call.UNDL_PX_AT_OPT_TRADE;

aATMput := (sp1-put.UNDL_PX_AT_OPT_TRADE)/put.UNDL_PX_AT_OPT_TRADE;

s_trd1 := makeDetail('1', call.Topic, call.LAST_TRADE, call.SIZE_LAST_TRADE, c1);

s_trd2 := makeDetail('2', put.Topic, put.LAST_TRADE, put.SIZE_LAST_TRADE, c1);

aAlertText := concat('Possible At the Money Straddle in ',sym);

if ( (abs(aATMcall) < 0.05) and (abs(aATMput) < 0.05) ) {

output setOpcode

([Topic=call.Topic; Topic2=put.Topic; Security=sym; Security2=sym;

OPT_PUT_CALL='Call'; OPT_PUT_CALL2='Put'; Strategy='straddle'; |

StrategyA = aStraddle; SIZE_LAST_TRADE = call.SIZE_LAST_TRADE;

ATMcall=aATMcall; ATMput=aATMput;

AlertID=idNum++; AlertText=aAlertText; Sec1=s_trd1; Sec2=s_trd2;

],upsert);

}

}

.

22


Aleri Platform attributes same

Beyond Basics

Pattern Streams Demo

Options Strategies

DEVELOPMENT


Lab create strangle and put spread patterns
Lab: create strangle and put spread patterns attributes same

LAB – PATTERN STREAMS

.

LAB Details:

Strangle: same as straddle except different strike price.

Call Puts: 2 puts, same symbol, expiry, different strike price,

same or different contract sizes, last trade price and sizes

24


Performance attributes same

Aleri Platform Monitoring

Dev, QA, and Prod Environments

ADMINISTRATION


Studio has integrated “streams” performance monitor attributes same

Very useful to assist in optimizing model designs

Key metrics include:

Individual Stream CPU utilization, rows processed, queues

Useful in Dev, QA, and Production

SERVER MONITORING


Data Connector attributes same

Platform to Platform

DEVELOPMENT


Plug-Ins attributes same

Real Time Excel

ADAPTERS


Allows one to publish to and subscribe to Aleri Platform attributes same

Can also dynamically change model inputs

Ex: increase amount to trade (a stock position) half way through trading

Return to Prop Trade model for in depth examination of integrating both Pub and Sub aspects of Excel RT

EXCEL RT


To demo pub and sub features in one model, return to Prop Trade model.

Start PropTrade.xml. 

Open Excel 2003 with C:\Aleri_Demo\apps\PropTrade\excel\PropTrade.xls.

Open Aleri RT Excel Plug-In in Excel; then connect to Platform. 

Click on input sheet.

Highlight / Select A1:D4 and copy.

Return to plug in.

Select Publish then upsert and ellipsis. It should show A1:D4.

Make sure on right that you select source stream Input stream.

Click Publish. You should see “successfully published data”.

This publishes our beginning trading positions to the Platform.

PUB-SUB


Repeat similarly for ID sheet but select A1:B2 and ClOrdIDInput as the source stream.

This publishes our starting ID to the model; the ID will be used for unique Client Order ID’s.

Return to ID sheet. Next, just click on A2. Then in plug-in, select subscribe.

Select A2 and stream FlexID.

Click apply then start the query.

Excel will thus now subscribe to model output in from FlexID stream. This stream tracks latest ID which needs to increment.

EXCEL RT


Excel rt
Excel RT ClOrdIDInput as the source stream.


Excel rt1
Excel RT ClOrdIDInput as the source stream.


Excel rt2
Excel RT ClOrdIDInput as the source stream.


Excel rt3
Excel RT ClOrdIDInput as the source stream.


Excel rt4
Excel RT ClOrdIDInput as the source stream.


Excel rt5
Excel RT ClOrdIDInput as the source stream.


Excel rt6
Excel RT ClOrdIDInput as the source stream.


Excel rt7
Excel RT ClOrdIDInput as the source stream.


Excel rt8
Excel RT ClOrdIDInput as the source stream.


Excel rt9
Excel RT ClOrdIDInput as the source stream.


Excel rt10
Excel RT ClOrdIDInput as the source stream.


Aleri Platform ClOrdIDInput as the source stream.

Beyond Basics

User Defined Functions

Development


To demo performance monitoring: Run C:\Aleri_Demo\apps\PatternsOptionStrategies\models\PatternOptionStrategies.

Open C:\Aleri_Demo\apps\PatternsOptionStrategies\excelBook2e.xls with Aleri RT Plug-In. Connect to the Platform then open Subscription Wizard. Click on sheet alerts at A5. Subscribe to stream FlexExcel at A5 cell in alerts sheet. Enter 500 for Max Rows. Check off Get Base Transactions; click apply and then start.

In the Studio, click on Playback-Record and start playback of C:\Aleri_Demo\apps\PatternsOptionStrategies\recordings\recorded_data_PatternsOptionsStrategies.rec.

In Run-Test tab, click on Monitor, then icon with 3 streams connected, then the green arrow. Alternate between Queue Depth and Rows Processed/Sec for full suite of performance metrics.

SERVER MONITORING


Admin server monitoring cont
ADMIN – Server Monitoring (cont) C:\Aleri_Demo\apps\PatternsOptionStrategies\models\PatternOptionStrategies.

The Studio has a Repository where it looks for source code for projects. This repository is specified at install and then can be changed in the Studio: Tools Menu→Settings option.


Admin server monitoring cont1
ADMIN – Server Monitoring (cont) C:\Aleri_Demo\apps\PatternsOptionStrategies\models\PatternOptionStrategies.


Admin server monitoring cont2
ADMIN – Server Monitoring (cont) C:\Aleri_Demo\apps\PatternsOptionStrategies\models\PatternOptionStrategies.


Admin server monitoring cont3
ADMIN – Server Monitoring (cont) C:\Aleri_Demo\apps\PatternsOptionStrategies\models\PatternOptionStrategies.


Enterprise C:\Aleri_Demo\apps\PatternsOptionStrategies\models\PatternOptionStrategies.

Features

HIGH AVAILABILITY


Configurable to your level of availability C:\Aleri_Demo\apps\PatternsOptionStrategies\models\PatternOptionStrategies.

and flexibility needs

Rapid failover "hot" spare

highest degree of availability

recovery in seconds

Shared resources "warm" spares

flexible configurations

recovery in minutes

parallel & pipeline configurations

All managed by fault tolerant cluster

manager

HA / CLUSTER CONFIG


Flex Stream C:\Aleri_Demo\apps\PatternsOptionStrategies\models\PatternOptionStrategies.

Call-Outs to Java and C++ methods

FOREIGN CALL-OUTS


C/C++ and Java Functions can be called from Flex Streams C:\Aleri_Demo\apps\PatternsOptionStrategies\models\PatternOptionStrategies.

Functions include “foreign” and “foreignJava”

Examples follow:

FOREIGN CALL-OUTS


Function – foreign: C:\Aleri_Demo\apps\PatternsOptionStrategies\models\PatternOptionStrategies.

Calls method from a shared library

Syntax: foreign (sharedLibrary, function, type, expr, ... expr)

1st two arguments: identifiers

3rd argument: type name;

rest: function arguments.

function returns value of return type specified.

Example:

Foreign (&quot;distance.so&quot;, distance, double, u.a, u.b)

FOREIGN CALL-OUTS


Function – foreignJava: C:\Aleri_Demo\apps\PatternsOptionStrategies\models\PatternOptionStrategies.

Calls static Java method

Syntax: foreignJava(className, function, type, expr, …expr)

1st two arguments: identifiers

3rd argument: string of function type

rest: function arguments.

function returns value of return type specified.

Example:

foreignJava(Funs, distance, '(DD)D', u.a, u.b)

FOREIGN CALL-OUTS


To create a usable user-defined functions/methods in C/C++: C:\Aleri_Demo\apps\PatternsOptionStrategies\models\PatternOptionStrategies.

1. Write the function.

2. Build a shared library. Compile function into shared library.

3. Write the call to the function within the model.

Solaris and Linux:

gcc -fPIC -shared -m64 -I.. -c -o distance.o distance.cpp

gcc -fPIC -shared -m64 distance.o -o distance.so

Solaris and Linux: export path of shared library .so files

Foreign (&quot;distance.so&quot;, distance, double,u.a,u.b,u.c)

FOREIGN CALL-OUTS


To create a usable user-defined functions/methods in C/C++: C:\Aleri_Demo\apps\PatternsOptionStrategies\models\PatternOptionStrategies.

1. Write the function.

2. Build a shared library. Compile function into shared library.

3. Write the call to the function within the model.

Windows: use .dll instead of .so.

Recommend set PATH environment variable for place .dll files. If the .dll file is not found in home folder, other folders will then be searched, culminating in the directories specified in the PATH environment variable.

FOREIGN CALL-OUTS


Sample code: **** This will be “adapted” (4 slides forward)

#include math.h

double distance(int numvals, double * vals)

{

double sum = 0.0;

for (int i=0; i<numvals; i++)

sum += vals[i] * vals[i];

return sqrt(sum);

}

FOREIGN CALL-OUTS


As prior code needs to be adapter, note that arguments must be drawn from structured type that includes all possible types understood by the Aleri Streaming Platform internally. This type, called "DataValue", is found in the DataTypes.hpp

currently has the following definition: (next slide)

FOREIGN CALL-OUTS


struct DataValue { be drawn from structured type that includes all possible types understood by the Aleri Streaming Platform internally. This type, called "DataValue", is found in the DataTypes.hpp

union

{

int16_t int16v; int32_t int32v; int64_t int64v; money_t moneyv;

double doublev; time_t datev; timestampval_t timestampv;

const char * stringv; void * objectv;

} val;

bool null;

};

FOREIGN CALL-OUTS


Thus, the interface to a user-defined function is: be drawn from structured type that includes all possible types understood by the Aleri Streaming Platform internally. This type, called "DataValue", is found in the DataTypes.hpp

int32_t ForeignFunction(int numargs,

DataTypes::DataValue * top,

DataTypes::DataValue * nextArgs,

Std::vector<void *> & arena)

FOREIGN CALL-OUTS


#include math.h be drawn from structured type that includes all possible types understood by the Aleri Streaming Platform internally. This type, called "DataValue", is found in the DataTypes.hpp

#include <vector>

#include “Row.hpp”

#include “DataTypes.hpp”

extern “C” int32_t distance(int numargs,

DataTypes::DataValue * top,

DataTypes::DataValue * nextArgs,

Std::vector<void *> & arena)

{

double sum = 0.0;

if (numargs <= 0) {

top->null = false;

top->val.double = 0.0;

return 0;

}

//continued

FOREIGN CALL-OUTS


if (top->null) return 0; be drawn from structured type that includes all possible types understood by the Aleri Streaming Platform internally. This type, called "DataValue", is found in the DataTypes.hpp

double dist = top->val.doublev * top->val.doublev;

for (int i=numargs-2; i>=0; i--) {

if ((nextArgs + i)->null) {

top->null = true;

break;

}

dist +=(nextArgs + i)->val.doublev *(nextArgs + i)->val.doublev;

}

top->val.double = sqrt(dist);

return 0;

}

The “extern” declaration is n

FOREIGN CALL-OUTS


1. Write the function. be drawn from structured type that includes all possible types understood by the Aleri Streaming Platform internally. This type, called "DataValue", is found in the DataTypes.hpp

2. Compile the function (either into a .class file or a .jar file).

3. Write the call to the function within the model.

To Link User-Defined Functions in Java:

Aleri has default Java runtime environment built into it. All you need to do to is:

“link” the Java code into application and start server with a special flag:

sp -j /home/aleriusr/java/lib ...

The -j option specifies the classpath for the Java virtual machine.

FOREIGN CALL-OUTS


Aleri can call static Java functions defined in any class. be drawn from structured type that includes all possible types understood by the Aleri Streaming Platform internally. This type, called "DataValue", is found in the DataTypes.hpp

Here, is a class "Functions" that defines a number of callable functions

public class Functions {

public static int intFun0() { return 172836; }

public static int intFun1(int i,int j) { return i+j; }

public static long longFun0() { return 967346; }

public static long longFun1(long i,long j) { return i+j;}

public static double doubleFun0() { return 10.7152; }

public static double doubleFun1(double i, double j) { return i+j; }

public static String stringFun0() { return "hij"; }

public static String stringFun1(String i) { return i; }

}

FOREIGN CALL-OUTS


Arguments and return values of the Java types: be drawn from structured type that includes all possible types understood by the Aleri Streaming Platform internally. This type, called "DataValue", is found in the DataTypes.hpp

• int (32-bit integers)

• long (64-bit integers)

• double (double-precision floating point numbers)

• String (character strings)

Command:

foreignJava(Functions,intFunction1,'(II)I',1,2)

FOREIGN CALL-OUTS


Notes regarding prior slide: be drawn from structured type that includes all possible types understood by the Aleri Streaming Platform internally. This type, called "DataValue", is found in the DataTypes.hpp

3rd argument to foreignJava is a string, a representation of the type of the function being called.

You can obtain this string via the javap executable shipped with most versions of Java. For instance, if the class file is located in /home/aleriusr/java/lib, then

javap -s -classpath /home/aleriusr/java/lib Functions

Produces (next slide)

FOREIGN CALL-OUTS


public class Functions extends java.lang.Object{ be drawn from structured type that includes all possible types understood by the Aleri Streaming Platform internally. This type, called "DataValue", is found in the DataTypes.hpp

public Functions(); Signature: ()V

public static int intFun0(); Signature: ()I

public static int intFun1(int, int); Signature: (II)I

public static long longFun0(); Signature: ()J

public static long longFun1(long, long); Signature: (JJ)J

public static double doubleFun0(); Signature: ()D

public static double doubleFun1(double, double); Signature: (DD)D

public static java.lang.String stringFun0(); Signature: )Ljava/lang/String;

public static java.lang.String stringFun1(java.lang.String);

Signature: (Ljava/lang/String;)Ljava/lang/String;

} // *** Note (II)I for our example. “I” denotes a 32-bit integer, “J” a 64-bit //integer, “D” a double, and “Ljava/lang/String;” a string.

FOREIGN CALL-OUTS


Another example: be drawn from structured type that includes all possible types understood by the Aleri Streaming Platform internally. This type, called "DataValue", is found in the DataTypes.hpp

#include <time.h>

#include <vector>

#include "DataTypes.hpp"

extern "C" int32_t myRandom(int numargs, DataTypes::DataValue *top,DataTypes::DataValue * nextArgs, std::vector<void *> &arena) {

//if (top->null) return 0;

top->val.int32v = rand();

return 0;

}

FOREIGN CALL-OUTS


Another example: be drawn from structured type that includes all possible types understood by the Aleri Streaming Platform internally. This type, called "DataValue", is found in the DataTypes.hpp

#include <time.h>

#include <vector>

#include "DataTypes.hpp"

extern "C" int32_t myRandom(int numargs, DataTypes::DataValue *top,DataTypes::DataValue * nextArgs, std::vector<void *> &arena) {

//if (top->null) return 0;

top->val.int32v = rand();

return 0;

}

FOREIGN CALL-OUTS


In Model’s xml file (was tested in PropTrade model): be drawn from structured type that includes all possible types understood by the Aleri Streaming Platform internally. This type, called "DataValue", is found in the DataTypes.hpp

<Method name="quotesParse2" stream="quotesParse2">{

typeof(EMS)arec;

int32 price_change := 0;

int32 random_num := 0;

int32 dummy := 0;

random_num := foreign (&quot;/home/aleri/myRandom.so&quot;, myRandom, int32, dummy);

Print ('DEBUG: EMS:quotesParse2, Random Num:',string(random_num),' \n' );

FOREIGN CALL-OUTS


ad