SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Tue Nov 21, 2017 11:24 am

All times are UTC + 3 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Mon Mar 19, 2012 12:02 am 
Offline

Joined: Sat Feb 25, 2012 8:51 pm
Posts: 154
Could you please help me?

This is possibly my misunderstand Enums, so hopefully the answer is an easy one.

InstrumentList is IEnmerable class which is good. There are only two Properties which can be used: Count and Item. Count giving the total number of instruments in the list. And Item which returns via the symbol name.

However, I want to run some code that talks to the Instrument List as an ordered list. That is, I have an array of Entry Orders which track orders against instruments. This is trick I’ve brought with me from NT.

Code:
   private Order[] entry_orders = {entry_order1, entry_order2, entry_order3, entry_order4, entry_order5, entry_order6,
      entry_order7, entry_order8, entry_order9, entry_order10}


Is there a way I can get the InstrumentList to return the order which the instrument comes in the list via its symbol?

At the moment I have to use a loop to determine where it comes in the list, then match that with the Entry Orders array.

Code:
   public override void OnPositionClosed()
   {

      CancelOrders();
      
      InstrumentList temp = this.Instruments;
      int inst_num = 0;
      int y = 0;
            
      foreach (Instrument x in temp) {
               
         if (x.Symbol == this.Instrument.Symbol) {
                  
            inst_num = y;
            break;
         }
               
         y++;
               
      }      
      
      entry_orders[inst_num] = null;
      
      //entry_orders[temp.Item[Position.Instrument.Symbol]] = null;
      
      
      //entry_orders[inst_num] = null;
      
      
   }



Thanks and regards,

drolles


Top
 Profile  
 
PostPosted: Mon Mar 19, 2012 10:49 am 
Offline

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

If your goal is to be able to get an order by intrument - it is better to use Dictionary<Instrument, Order> table. So, instead of "private Order[] entry_orders = ..." you can use "private Dictionary<Instrument, Order> entry_orders = ...".

To get needed order just write something like "Order myOrder = entry_orders[Instrument];"

To define variable of type Dictionary<Instrument, Order> you should add "using System.Collections.Generic;"

Regards,
Sergey.


Top
 Profile  
 
PostPosted: Thu Mar 22, 2012 2:08 am 
Offline

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

Thanks very much for your suggestion, I'll check it out. The other solution I was thinking was using an ArrayList. But what you are suggesting might be better. Thanks very much. drolles


Top
 Profile  
 
PostPosted: Tue Mar 27, 2012 12:59 am 
Offline

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

Thanks again for the suggestion.

I blended your method with the one I brought across from NT.

I did as you say crated a Dictionary for the instruments, but I linked them to a ordered list of int starting from 0.

But I also kept the array of entry orders. Why? Because if I understand the Dictionary collection it is meant to more static. And this is required to clobber the entry order object (regularly when I update with the next order)

I then used that in the referencing of the Instrument I use it this way:

Code:
      InstrumentList temp_list = this.Instruments;
      
      int y = 0;
      entry_orders = new Order [temp_list.Count];
      
      foreach (Instrument x in temp_list) {
      
         Order temp_order = LimitOrder(OrderSide.Buy, 0.0, 0.0);
            
         entry_order_dic.Add(x, y);

         y++;
         
      }


You can then refer in this way:

Code:
entry_orders[entry_order_dic[Instrument]] == null


Thanks,

drolles


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