SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Thu Oct 01, 2020 10:30 am

All times are UTC + 3 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Sat Oct 20, 2012 7:22 pm 
Offline

Joined: Sat Feb 25, 2012 8:51 pm
Posts: 154
Hi,

Could someone please help?

I want to access a BarSeries of another instrument while in OnBar of the “main” instrument.

Let’s assume I’m trading futures.

I load a FDAX and a ES to look at the relationship between to the 2.

I create a BarSeries of ES in OnStrategyStart by doing this:
Code:
ES = InstrumentManager.Instruments["ES"];

        ES1 = GetBars(ES, BarType.Time, 60);
I add a bar to the BarSeries each bar I found that is 1 min within OnBar:

Code:
public override void OnBar (Bar bar)
   {


        if (Instrument == ES)
        {

            if (bar.Size == 60)
            {

                ES1.Add(bar);

            }

        }

I then ask for the Highest High of the ES series

Code:
spyfMax = ES1.HighestHigh(5);

And get an empty array exception….?

The other way is to create a timeSeries I guess. But how to I access that within the FDAX OnBar event?

Does a TimeSeries get created as default for each instrument added? If so, how do I access it from another instrument event fire of OnBar?

Thanks,

drolles


Top
 Profile  
 
PostPosted: Sun Oct 21, 2012 12:02 am 
Offline

Joined: Thu Jun 08, 2006 3:56 pm
Posts: 537
Location: BC Canada
I'm not at my main computer right now, so I can't check, but I think this issue was covered in one of the manuals. What I remember is that I always use specific syntax to GetBarSeries? to define references to various bar lengths (1min, 1hour, or whatever) to make them available in the code. Maybe check the Strategy Development manual. If you can't find the answer there or elsewhere, reply to this thread and I'll see your next posting on my main computer.

There is certainly a way to do it, if that makes you feel any better right now. :-)


Top
 Profile  
 
PostPosted: Sun Oct 21, 2012 1:52 am 
Offline

Joined: Thu Jun 08, 2006 3:56 pm
Posts: 537
Location: BC Canada
There are several things going on in your post, I think.

Regarding the HighestHigh operation, I don't know if HighestHigh is smart enough to do the right thing if the series contains less than 5 bars, when you say HighestHigh(5) bars. Perhaps you could test that case, or do an explicit test (if ES.Count > 5, then calc HighestHigh(5)).

It may be the case that no ES (xxx) bars of ANY size are getting into the code that you cite, because maybe ES is not listed in the Instrument section of your strategy project.

It may be the case that no ES (60) bars of 60 size are getting into the code that you cite, because the bar provider (in strategy Properties) might not be generating 60-size bars from the incoming ticks.

A second question you ask is how to reference one instrument (eg ES) from within the OnBar of another instrument, so to speak. As you surmise, OQ creates a new strategy-instrument object for each Instrument listed in the Instruments list for the strategy. If you want to reference each other's incoming data in OnBar, you'll have to store references in the global object store. This boils down to cross-strategy communication, which (AFAIK) must still be done by passing references through the global hash table. The references have to be set up in the OnStrategyStart code by each strategy-inst object that OQ creates.

I checked my notes, and using GetBars is the right thing to do, so you have that part right.


Top
 Profile  
 
PostPosted: Sun Oct 21, 2012 9:23 am 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6817
Hi,

I don't think it's a good idea to manually add bars to internal OQ series. Actually OQ does it automatically behind the scene and there is Strategy.GetBars method that takes an instrument as parameter

public BarSeries GetBars(
Instrument instrument,
BarType barType,
long barSize
)

so that you can access any bar series for any instrument in a strategy. Thus you don't need to bother adding bars manually and passing bar series to another strategy instance.

Though if you still would like to do it manually, I suggest you create another bar series and pass it between startegy instancies using Global table.

Regards,
Anton


Top
 Profile  
 
PostPosted: Sun Nov 18, 2012 2:50 pm 
Offline

Joined: Sat Feb 25, 2012 8:51 pm
Posts: 154
Ok, thanks very much for that.

BarSeries doesn’t include the correlation method. I’m assuming that I need to create a TimeSeries to make use of that method. But, how do I do that while ensuring that the timeseries and barseries of each of those are synced.

The worst case scenario is that I get incorrect results given the 4 things (2 bar series (FDAX & ES) and 2 timeseries (FDAX & ES)) are out of sync.

Thanks and regards,

drolles


Top
 Profile  
 
PostPosted: Sun Nov 18, 2012 6:30 pm 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6817
Hi,

I guess TimeSeries Correlation method uses entries with identical DateTime to calculate correlation...

Regards,
Anton


Top
 Profile  
 
PostPosted: Sun Nov 18, 2012 8:19 pm 
Offline

Joined: Sat Feb 25, 2012 8:51 pm
Posts: 154
Thanks very much for the reply on a weekend no less.

So that means that the best way to do this is to create a TimeSeries object of the 2 instruments (adding each bar as the new data arrives) and manually manage that TimeSeries?

Thanks and regards,

drolles


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