SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Sat Dec 14, 2019 3:58 am

All times are UTC + 3 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Thu Feb 12, 2009 5:23 pm 
Offline

Joined: Wed Feb 11, 2009 7:26 pm
Posts: 11
Location: Chicago, IL
Hi. I posted to the help desk forum but thought it might be more appropriate here...

I have been working with OQ for a week or so and I really like it but I am a little confused on how to manage orders (and hence risk) when I have a strategy running with multiple Instruments. For my strategy, on any new bar it is possible that multiple new orders (from different instruments) will be triggered and I would like to ensure that I don't place more orders than I can afford.

Is there a global list of all orders (for all Instruments) that have been initiated (like the one in the All tab in the Order Manager) that I can get access to? If so, would it immediately list an order after order.Send()? I tried a simple test with 15 Instruments in live mode (IB paper trade acct).

public override void OnStrategyStart()
{
Order marketOrder;
marketOrder = MarketOrder(OrderSide.Buy, 100, "Enter Long");
marketOrder.Send();
Console.WriteLine("Total Positions = " + Portfolio.Transactions.Count);
}

Which result in 15 orders being placed and Total Positions = 0 displayed 15 times.

I feel like I am missing something since my total exposure is based on the my current open positions plus any orders in the que but I am not seeing how to figure out how many orders (total for all Instruments) are currently qued. From a number of posts in this forum it feels like others have written their own order management utilities to deal with this problem but I wanted to check first before I do the same.

Thanks in advance.

Steve


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 19, 2009 5:11 am 
Offline

Joined: Mon Feb 27, 2006 9:07 pm
Posts: 52
Hello steveo311,

I check all positions and live orders. I'll paste the code I use here as an example. It has some things in it specific to what I do, but I hope it helps. Some of those specific things in there are: breaking out positions by sector or total (by sending indexCode = 0); breaking out long and short positions; ignoring orders over a certain age (orderViableMinutes defined elsewhere). I do not claim to be the best C# coder around so I am sure there are improvements which could be made. Good luck.

Code:
    void CalculatePositions(ref double totPositions, ref double totPositionsShort, ref double totPositionsLong, int indexCode)
    {
        //   PositionList[] positions = Portfolio.Positions;
        totPositions = 0;
        totPositionsLong = 0;
        totPositionsShort = 0;
        foreach (Position positionCheck in Portfolio.Positions)
        {
            if (int.Parse(positionCheck.Instrument.Sector) == indexCode || indexCode == 0)
            {
                totPositions += Math.Abs(positionCheck.Amount * positionCheck.EntryPrice);
                if (positionCheck.Side == PositionSide.Long)
                {
                    totPositionsLong += positionCheck.Amount * positionCheck.EntryPrice;
                }
                else
                {
                    totPositionsShort += Math.Abs(positionCheck.Amount * positionCheck.EntryPrice);
                }
                //      Console.WriteLine(acctID + " " + "position " + " " + positionCheck.Amount + " Tot " + totPositions + " " + " totPositionsLong " + totPositionsLong + " " + " totPositionsShort " + totPositionsShort);
            }
        }

        foreach (Order orderCheck in Orders)
        {
            if ((orderCheck.Account == acctID) && (orderCheck.IsDone == false) && (orderCheck.DateTime > Clock.Now.AddMinutes(-1 * orderViableMinutes)))
            {
                if (int.Parse(orderCheck.Instrument.Sector) == indexCode || indexCode == 0)
                {
                    totPositions += Math.Abs(orderCheck.Qty * orderCheck.Price);
                    //add amount to long side if order is a buy and we have no position or are long
                    // do not want to add to totPositionsLong if we are exiting a short position
                    if ((orderCheck.Side == OrderSide.Buy) && ((Portfolio.Positions[orderCheck.Instrument] == null) ||
                        Portfolio.Positions[orderCheck.Instrument].Side == PositionSide.Long))
                    {
                        totPositions += Math.Abs(orderCheck.Qty * orderCheck.Price);
                        totPositionsLong += orderCheck.Qty * orderCheck.Price;
                    }
                    if ((orderCheck.Side == OrderSide.Sell) && ((Portfolio.Positions[orderCheck.Instrument] == null) ||
                        Portfolio.Positions[orderCheck.Instrument].Side == PositionSide.Short))
                    {
                        totPositions += Math.Abs(orderCheck.Qty * orderCheck.Price);
                        totPositionsShort += Math.Abs(orderCheck.Qty * orderCheck.Price);
                    }
                }
            }
        }
    }


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 20, 2009 7:44 am 
Offline

Joined: Wed Feb 11, 2009 7:26 pm
Posts: 11
Location: Chicago, IL
Wow. Thanks a lot for posting that dwil! Its very helpful to see what how someone else is handling this. My main issue was tracking orders globally across instruments. Is your Orders variable a static that is shared across instruments?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 21, 2009 7:58 pm 
Offline

Joined: Mon Feb 27, 2006 9:07 pm
Posts: 52
Your welcome.

I run that to calculate the positions and potential positions each time the system checks to see if it has enough purchasing power to enter a position.

Orders itself is an OQ object.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 22, 2009 4:45 am 
Offline

Joined: Wed Feb 11, 2009 7:26 pm
Posts: 11
Location: Chicago, IL
Thats good info. I was under the assumption that Strategy.Orders was just for orders for Strategy.Symbol.

Steve


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 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