space13left Solutions
spacer Case Studies
 
 
 
  Enterprise Info Mgmt
 
 
 
 
 
 
 
 
 
 
  Telecomm
 
 
 
  Financial Services
   
   
   
   
   
   
Trading Decision Support Systems

Trading systems are very important to broker/dealers, to hedge funds and to a great many other Financial Services companies.

The SQLstream RAMMS solution offers a powerful framework, methodology, and mechanism for developing and deploying decision support systems (DSS) for trading.

SQLstream's solution uses the natural expression of relational queries over streams of incoming messages comprising market data.

Examples

Here are some SQLstream examples that demonstrate the power of windowed aggregation applied to Trading Decision Support Systems.

Moving Average

One of the classical operations performed on stock market trade data is calculating moving averages. Here is a SQLstream statement to calculate the moving average for a stock over a rolling ten minute window:

CREATE STREAM tenMinuteMovingAverage AS
SELECT STREAM
       ticker,
       price,
       AVG(price) OVER last10mins AS ma10mins
FROM AllTrades
WINDOW last10mins AS
(     PARTITION BY ticker
                           RANGE INTERVAL '10' MINUTE PRECEDING
);

The keyword STREAM is added to the statement to indicate that a stream of results is required rather than a TABLE of results. Streams can be viewed as infinite tables to which messages are continually added. Selecting the STREAM yields the streams of changes (additions) made to the table.

Two Moving Averages

Now we extend this definition to two separate moving averages. We shall add one for the thirty minute moving average, and then compute them at the same time continuously.

CREATE STREAM dualMovingAverages AS
SELECT
              ticker,
              price,
              AVG(price) OVER last10mins AS ma10mins,
              AVG(price) OVER last30mins AS ma30mins
FROM AllTrades
WINDOW
              last10mins AS (PARTITION BY ticker
                            RANGE INTERVAL '10' MINUTE PRECEDING ),
              Last30mins AS (PARTITION BY ticker
                            RANGE INTERVAL '30' MINUTE PRECEDING );

Moving Average Cross-Over Points

In SQLstream, it is straightforward to capture the stream of moving average cross-over points, widely believed to signify important transitions in stock prices.

We first create a window (twoRows) comprising the last two messages, current and preceding. We then compare the preceding message's moving average with the current message's moving average, using the .FIRST operator. A cross-over has occurred when the sign of the difference between the two moving averages has flipped. That condition reflects the change where one moving average was previously larger than the other but, using the current message's moving average, that previously larger value is now the smaller.

SELECT STREAM ticker, price, ma10mins, ma50mins
FROM (       
          SELECT STREAM
                    ticker,
                    price,
                    AVG(price) OVER last10mins AS ma10mins,
                    AVG(price) OVER last30mins AS ma30mins
          FROM Trades
)
WHERE      FIRST(sign(ma10mins – ma30mins)) OVER twoRows 
                           != sign(ma10mins – ma30mins)
WINDOW
          last10mins AS (PARTITION BY ticker
                            RANGE INTERVAL '10' MINUTE PRECEDING ),
          last50mins AS ( PARTITION BY ticker
                            RANGE INTERVAL '30' MINUTE PRECEDING ),
          twoRows AS ( PARTITION BY ticker  
                            INTERVAL 1 ROWS  PRECEDING );

SQLstream Power

SQL provides a powerful declarative paradigm for market data processing.

The provided examples help demonstrate the power and expressiveness of SQLstream's SQL:2003-based SQL when applied to streams of trading data flowing continuously in time.

Once queries are written within SQLstream, they are easy to reuse as views, which can then be cascaded into other Views to feed other executing queries.

Beyond the SQL-based logic, however, applications sometimes require specific procedural logic or particular algorithms, which SQLstream readily accommodates through user-definable functions and stream transforms written in Java. These adapters and plug-ins are written using SQLstreams Software Development Kit (SDK). SQLstream's RAMMS will dynamically load and link in any such plug-ins as they are referenced and required within SQL statements, providing seamless integration.

These various capabilities enable SQLstream to operate as a great integration platform for managing all of the queries and views that are the key building blocks of trading decision support systems.

SQLstream provides an easy way for you to manage your dynamic data assets, queries, and views.