SmartQuant Discussion
http://www.smartquant.com/forums/

How to define custom Market Data Filter
http://www.smartquant.com/forums/viewtopic.php?f=64&t=9740
Page 1 of 1

Author:  Baraz Sergey [ Fri Oct 14, 2011 5:40 pm ]
Post subject:  How to define custom Market Data Filter

Custom market data filters are usefull when you want to filter out "bad" ticks coming from real or simulation market data providers. To define a filter you should inherit from the OpenQuant.API.MarketDataFilter class and give the filter to the current provider in scenatio or strategy code. The code below shows how to create a market data filter and set it as a default filter of the current market data provider.

Code:
using System;
using System.Collections.Generic;

using OpenQuant.API;
using OpenQuant.API.Engine;

public class MyScenario : Scenario
{
   class MyFilter : MarketDataFilter
   {
      Dictionary<string, Trade> goodTrades = new Dictionary<string, Trade>();
      
      public override Trade FilterTrade(Trade trade, string symbol)
      {
         Trade lastGoodTrade = null;
         
         // check if the table contains the symbol
         if (goodTrades.TryGetValue(symbol, out lastGoodTrade))
         {
            // there is a good trade in the table
            
            // check if new trade differs from the last good not more than on 0.5%
            if (Math.Abs((1 - lastGoodTrade.Price / trade.Price) * 100) < 0.5)
            {
               // update the last good trade
               goodTrades[symbol] = trade;
               // accept the trade
               return trade;
            }
            else
               // ignore the "bad" trade
               return null;
         }
         else
         {
            // put the first trade for this symbol into the table
            goodTrades[symbol] = trade;
            // accept the trade, since this is the very first one
            return trade;
         }
      }
      
      public override Quote FilterQuote(OpenQuant.API.Quote quote, string symbol)
      {
         // accept all quotes
         return quote;
      }      
   }
   
   public override void Run()
   {
      // set the filter
      MarketDataProvider.Filter = new MyFilter();
      
      // start the solution
      Start();
   }
}

Author:  truebilly [ Thu Jun 28, 2012 3:25 pm ]
Post subject:  Re: How to define custom Market Data Filter

hi, sergey. In the current version of OQ, the methods FilterQuote() and FilterTrade() have a return type of Quote/Trade rather than bool, so how do I send back the filter result to OQ without using bool value?

Author:  Dr. Anton Fokin [ Thu Jun 28, 2012 7:11 pm ]
Post subject:  Re: How to define custom Market Data Filter

Hi,

simply return the same (or adjusted) quote or trade in case you want to pass it through or null if you want to filter it out. bool was changed to Trade/Quote to make it possible to adjust data in the filter.

Regards,
Anton

Page 1 of 1 All times are UTC + 3 hours
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/