Apama 10.3 | Apama Documentation | Developing Apama Applications | Developing Apama Applications in EPL | Working with Streams and Stream Queries | Using dynamic expressions in stream queries | Examples of using dynamic expressions in stream queries | Example of altering query window size or period
Example of altering query window size or period
The following code fragment shows part of a monitor that accepts requests from external entities to monitor/generate the volume-weighted average price (VWAP) for a given symbol. After you create a monitor like this, an external entity can, at any time, change the parameters that control the period over which the monitor calculates the VWAP and/or the output frequency of the VWAP events.
monitor VwapMonitor {
   VwapRequestParams params;
   action onload() {
      on all VwapRequest() as v spawn monitorVwap(v);
         // Simplified. Assumes no duplicate requests.
   action monitorVwap(VwapRequest v) {
      params := v.params;
      from t in all Ticks(symbol=v.symbol)
         within params.duration
         every params.period
         select Vwap(t.symbol,wavg(t.price,t.volume)) as vwap {
            route vwap;
      on all VwapRequestUpdate(symbol=v.symbol) as u {
         params := u.params;
When accumulating the raw tick data to generate the VWAP price, no prescience is involved. There is no anticipation that the window size is to be increased. Changing the within duration to a larger value causes the window duration to increase but does not recover historic events. Hence the effective sample duration over which the monitor calculates the VWAP will, over time (as new tick items arrive), extend from the smaller setting to the larger setting. When switching from a larger within duration to a smaller one, the change takes effect immediately. The correlator discards the items that are no longer in the within duration.

Copyright © 2013-2018 | Software AG, Darmstadt, Germany and/or Software AG USA, Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.