Use Case 6

Goal

User wants to iterate into daily data of IBM. The user logic requires for each day:
   - the last earning value.
   - the date of the next earnings.
   - the corresponding 6-weeks exponential moving average of the close.

Solution

TimeSeries earning = ...; // Earning data
TimeSeries ibm_d = ...; // Daily market data
TimeSeries ibm_w = ...; // Weekly market data

   // Calculate the 6-weeks EMA.
   ibm_w.add( "EMA", ibm_w.get("Close").ema(6) );

   for each index in ibm_d
   { 
      TimeStamp now = ibm_d.timestamps[index];

      // Get a reference on the values we care about.
      Value a = earnings.latestFrom( now );
      Value b = earnings.following( now );
      Value c = ibm_w.get("EMA").latestFrom( now );

      // Make sure all the required data is valid.
      if( a.isDefined() && b.isDefined() && c.isDefined() )
      {
         // Get the latest earning data
         double lastEarnings = a.data;

         // Get the date of the next earning.
         Timestamp nextEarning = b.timestamp;

         // Get the weekly EMA.
         double ema_w = c.data;

         // ... user logic ...
      }     
   }

WARNING: Work in progress, solution provided is a vague proposal in no particular language and is VERY likely to change as the design/interface is defined.