SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Wed Oct 28, 2020 12:08 pm

All times are UTC + 3 hours




Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Fri Dec 24, 2010 8:32 am 
Offline

Joined: Fri Dec 24, 2010 8:26 am
Posts: 9
Hi,
I am trying to code a logic for pair trading using open quant.
The problem is that i want to run the same code on like 500 pairs of stocks so creating individual instruments in the program doesnt make sense. Is there a way i can use a generic code and run it on all the instruments.

For eg.
I have two different instruments with prices of stock A and stock B
While writing the code i made individual instruments for the two and used them to trade.

But now i want to use this same logic for 500 pairs of instruments and i have their individual price data. Is there a way i can run that code on all the 500 pairs??

Regards
Kunal


Top
 Profile  
 
PostPosted: Fri Dec 24, 2010 8:48 am 
Offline

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

here is a FAQ that discusses spread/pair trading with OQ

viewtopic.php?f=64&t=6566&start=0

then you should either have one project per pair in OQ solution, or you can try to develop a code that will define pairs in OnStrategyStart and loop through pairs in OnBar / OnBarSlice.

PS. It will be possible to define solution instruments and project parameters programmatically in the coming OpenQuant 3.0 and this can simplify your development a lot, though you will need to define your 500 pairs somewhere anyway.

Regards,
Anton


Top
 Profile  
 
PostPosted: Fri Dec 24, 2010 8:58 am 
Offline

Joined: Fri Dec 24, 2010 8:26 am
Posts: 9
I understand that... and i have a list of pairs ready in an excel.....the problem is say if i want to run it first on stock A and Stock B. then after it has run the logic on this pair, i want to go to the next pair and so on and so forth. That is where creating multiple projects wont help because if i decide to change my strategy and create a new solution i will have to sit and add all these projects again. So i wanted to ask tht if i have 500 pairs in an excel is there a way where i can copy those pairs in a two dimensional array and then loop through this array such that i can create an instrument like

Instrument a = Instrument(Ratio[i][j]);

Also do you think there is a better way to do it.


Top
 Profile  
 
PostPosted: Fri Dec 24, 2010 9:13 am 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6817
You can define a hashtable that will return the second instrument in a pair using the first instrument as a key. Let's say you call it
MyPairs and you fill it with pairs in OnStrategyStart().

Then you can write your logic in a separate method

public void ProcessPair(Instrument instrument1, Instrument instrument2)
{

}

and then in OnBar() / OnBarSlice() you can have

public void OnBar(Bar bar)
{
Instrument instrument1 = this.Instrument;
Instrument instrument2 = MyPairs[instrument1];

ProcessPair(instrument1, instrument2);
}

Would this help?

Regards,
Anton


Top
 Profile  
 
PostPosted: Fri Dec 24, 2010 9:20 am 
Offline

Joined: Fri Dec 24, 2010 8:26 am
Posts: 9
Oh yess...this would help a lot...the only problem with this would be that my pairs wud be more like:
A,B
C,D
L,M

so the first instrument would not be constant. And i dont want my instrument to change on every bar but only after the whole strategy has been executed on one pair, coz im using this mostly for backtesting.

Or is there a way to simultaneously run the strategy on all pairs......


Top
 Profile  
 
PostPosted: Fri Dec 24, 2010 9:30 am 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6817
Tthe first instrument is hashtable key in my example, thus it should be unique, i.e. it should work fine in your case. It would be more complex if you have

A, B
A, C
B, D
B, E

Do you want to have results of your backtesting in one portfolio for all pairs or you just want to test 500 pairs and select profitable ones?


Top
 Profile  
 
PostPosted: Fri Dec 24, 2010 9:37 am 
Offline

Joined: Fri Dec 24, 2010 8:26 am
Posts: 9
Actually i will also have
A,B
A,C
and so on, i was just looking at my pairs.....

Well what i am trying to do is first build a strategy and then apply it on all the pairs. I would prefer to get results of the pairs separate for each coz in future i intend to write a strategy to select pairs as well.


Top
 Profile  
 
PostPosted: Fri Dec 24, 2010 9:43 am 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6817
Then I suggest you wait until OpenQuant 3.0 release. It will be possible to write a backtest scenario for your solution and then you can backtest your strategy for a list of pairs, select profitable pairs and so on in just one run.

Pairs selection looks like a perfect showcase for this new functionality. I think we will include it in OpenQuant 3.0 release today.


Top
 Profile  
 
PostPosted: Fri Dec 24, 2010 9:47 am 
Offline

Joined: Fri Dec 24, 2010 8:26 am
Posts: 9
BY when do you think the new version will be released???


Top
 Profile  
 
PostPosted: Fri Dec 24, 2010 11:09 am 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6817
Yesterday.... Joking... Today is the deadline.


Top
 Profile  
 
PostPosted: Fri Dec 24, 2010 11:14 am 
Offline

Joined: Fri Dec 24, 2010 8:26 am
Posts: 9
oh perfect....then ill just wait :D


Top
 Profile  
 
PostPosted: Mon Dec 27, 2010 9:00 am 
Offline

Joined: Fri Dec 24, 2010 8:26 am
Posts: 9
Has 3.0 been released??


Top
 Profile  
 
PostPosted: Mon Dec 27, 2010 11:16 am 
Offline

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

viewtopic.php?f=50&t=8607


Top
 Profile  
 
PostPosted: Mon Dec 27, 2010 11:21 am 
Offline

Joined: Fri Dec 24, 2010 8:26 am
Posts: 9
Super.............I shall return with my fresh set of queries :D


Top
 Profile  
 
PostPosted: Mon Dec 27, 2010 11:32 am 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6817
You are welcome to take a look at the Scenario Demo example included in the install (OQ Start Page). Ir runs SMA crossover startegy in the batch mode with three different sets of parameters. It also shows how to clear strategy instrument list and add new instruments.

What you can do is to modify this example to have a list with pairs in the beginning of the Scenario file and then

foreach pair in the list
{
clear instrument list
add instrument pair to the instrument list
Start()
output results (or select the best performing pairs)
}

Cool, right? :D


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next

All times are UTC + 3 hours


Who is online

Users browsing this forum: No registered users and 2 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