SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Sat Feb 29, 2020 12:09 am

All times are UTC + 3 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Wed Feb 06, 2008 3:53 am 
Offline

Joined: Wed Nov 21, 2007 8:29 pm
Posts: 47
Does anyone know of a way to get the index of a bar on a specific date? You can get the bar by date easily, but there is no IndexOf method (or equivalent) in BarSeries or ISeries, and so other than iterating through the whole series looking for the date, I can't find an easy way to do it...

Thanks -


Top
 Profile  
 
PostPosted: Wed Feb 06, 2008 6:59 pm 
Offline

Joined: Wed Nov 21, 2007 8:29 pm
Posts: 47
It does appear missing from the API, which means there is no easy way to find a bar N bars ago from bar other than the most recent one (which is what the Ago method does). Here's a binary search method that finds a Bar in a BarSeries by matching the DateTime. You should make sure the BarSeries is of the same type of put additional criteria in for testing a match.

Code:
      ///<summary>
      /// Method to find the index in a Bar series of a known bar - missing from BarSeries.  Implements a binary search.
      /// </summary>
      /// <param name="seriesToSearch"></param>
      /// <param name="barToBeFound"></param>
      /// <returns></returns>

      private int getIndexOf (BarSeries seriesToSearch, Bar barToBeFound)
      {
         int low = 0;
         int high = seriesToSearch.Count - 1;
         int mid;

         while ( low <= high)
         {
            mid = (low + high) / 2;
            if (seriesToSearch[mid].DateTime > barToBeFound.DateTime)
            {
               high = mid - 1;
            }
            else if (seriesToSearch[mid].DateTime < barToBeFound.DateTime)
            {
               low = mid + 1;
            }
            else
            {
               return mid;
            }
         }

         throw new ApplicationException("Couldn't find index of a known bar in series!");

      }


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 08, 2008 8:23 am 
Offline

Joined: Thu Apr 03, 2008 6:28 am
Posts: 49
This might not be in the API documentation, but from looking at IntelliSense's options with the BarSeries, you may be able to use this instead:
Code:
BarSeries[DateTime]

...so if you know the date/time, you can just use that basically as an index


Top
 Profile  
 
PostPosted: Thu May 08, 2008 10:55 am 
Offline

Joined: Fri May 06, 2005 1:40 am
Posts: 521
dg773 wrote:
Does anyone know of a way to get the index of a bar on a specific date? You can get the bar by date easily, but there is no IndexOf method (or equivalent) in BarSeries or ISeries


I have not checked in OpenQuant2 latest version, but there should be a BarSeries.GetIndex(DateTime) method. If its not there I am sure the SQ team will make it available since its already in the base framework.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 08, 2008 12:06 pm 
Offline

Joined: Thu Mar 20, 2008 4:41 pm
Posts: 273
Location: Sweden
I'm using 2.5, and I don't seem to have a BarSeries.GetIndex unfortunately.

If there is no such function, and dg773 has been kind enough to provide us with the code to accomplish the task, how would we go about adding this functionality to the BarSeries?

Create a new class, inherit from BarSeries, add the new functionality, put in a dll and include into OQ?

_________________
Asking smart qustions:
http://www.catb.org/~esr/faqs/smart-que ... html#intro

I don't mind when people PM me to see if I have the time to help, but please post in the forum FIRST, and then grab my attention so others can benefit aswell.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 08, 2008 1:07 pm 
Offline

Joined: Wed Oct 08, 2003 1:06 pm
Posts: 833
Hi,

ISeries.GetIndex(DateTime dateTime) method is added and will be available in the next version.

Regards,
Sergey.


Top
 Profile  
 
PostPosted: Fri Feb 10, 2012 9:41 pm 
Offline

Joined: Thu Mar 10, 2011 10:09 pm
Posts: 582
Hello,
could you tell what do your methods TimeSeries.GetIndex(DateTime dt) and BarSeries.GetIndex(DateTime dt) return if there is no value with appropriate DateTime in the series.

Regards, Dave


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

All times are UTC + 3 hours


Who is online

Users browsing this forum: No registered users and 3 guests


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