SmartQuant Discussion

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

All times are UTC + 3 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Mon Aug 01, 2011 11:34 pm 
Offline

Joined: Tue Mar 15, 2011 7:15 pm
Posts: 80
Hi,

I am writing a strategy that trades 3 different instruments as part of a butterfly trading combination. The forum postings on using OnBarSlice clearly show how to deal with all incoming bars, but I am unclear on how to deal with the OnPositionOpen, OnPositionChanged and OnPostionClosed events as these do not accept a Position object as parameter.

I send orders to open positions in the 3 instruments concurrently. So when the OnPositionOpened event fires, how do I know for which instrument the position was opened? I suppose I can use if(Portfolio.HasPosition(myInstrumentName) == true ) for each of the three legs and this will allow me to determine which instrument a position was opened for.

How can I determine which instrument the position was changed for in the OnPositionChanged event?

Determining when the orders are filled is quite easy because the OnOrderFilled events admits an Order parameter, so I can just evaluate the order.Instrument. There is no similiar parameter with the OnPosition events, so I am quite uncertain how to proceed.

Thanks.


Top
 Profile  
 
PostPosted: Mon Aug 01, 2011 11:56 pm 
Offline

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

OnPositionXXX is triggered in a strategy instance of corresponding instrument, which is Strategy.Instrument. Just try to add Console.WriteLine(Instrument); in OnPositionXXX event handler to see how it works.

Does this answer your question?

Cheers,
Anton


Top
 Profile  
 
PostPosted: Tue Aug 02, 2011 10:34 pm 
Offline

Joined: Tue Mar 15, 2011 7:15 pm
Posts: 80
I am still unclear how I would able to determine for which instrument the position was opened/changed/closed.

Could you provide 1-2 lines of sample code showing how I could figure out which instrument is triggering the OnPositionChanged event? A very simple example would be very instructive.

Thank you.


Top
 Profile  
 
PostPosted: Wed Aug 03, 2011 9:05 am 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6816
OnPositionOpened/Changed is called for Strategy.Instrument instrument.


Top
 Profile  
 
PostPosted: Wed Aug 03, 2011 4:29 pm 
Offline

Joined: Tue Mar 15, 2011 7:15 pm
Posts: 80
Say I have 2 instruments living within the same strategy:

Instrument instr1 = InstrumentManager.Instruments["DELL"];
Instrument instr2 = InstrumentManager.Instruments["CSCO"];

I understand there is a separate strategy instance created for each instrument, but I am still uncertain what code I should use to determine which instrument triggered the OnPositionChanged event.

From the FAQ: viewtopic.php?f=64&t=6566, I would seem that if inside the OnPositionChanged event I wrote:

OnPositionChanged
{
if (Instrument == instr1)....
}

This would solve my problem. Is there any way to determine which instrument caused the event to fire other than using if statements (or other looping procedure)?

Using if statements would be fine for a 2-3 instrument strategy, but if I build astrategy with numerous instruments, the code will rapidly become rather unweildy.

Thanks.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 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