SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Thu Sep 24, 2020 9:47 pm

All times are UTC + 3 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Fri Oct 14, 2011 5:40 pm 
Offline

Joined: Wed Oct 08, 2003 1:06 pm
Posts: 833
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();
   }
}


Last edited by Baraz Sergey on Mon Apr 15, 2013 5:22 pm, edited 1 time in total.

Top
 Profile  
 
PostPosted: Thu Jun 28, 2012 3:25 pm 
Offline

Joined: Mon Feb 21, 2011 10:46 am
Posts: 48
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?


Top
 Profile  
 
PostPosted: Thu Jun 28, 2012 7:11 pm 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6817
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 3 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group