SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Thu Jun 20, 2019 4:09 pm

All times are UTC + 3 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Tue Jan 27, 2009 10:44 am 
Offline

Joined: Wed Sep 26, 2007 10:03 pm
Posts: 100
Hi

I am wondering why OpenQuant does not open a position after a partial fill on the broker side. Is this the way it should behave?

It might be that it take a couple of minutes until an order is filled and during this time, there are open positions on the broker side but no open positions within OpenQuant. I would have expected that after the first partial fill OnPositionOpened() is fired and then after each additional PartialFill OnPositionChanged() is fired.

Why is this not the case?

Regards,
Boris


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 29, 2009 7:29 am 
Offline

Joined: Thu Apr 03, 2008 6:28 am
Posts: 49
I believe you can use OnOrderPartiallyFilled() to handle partial fills. At that point your Order should also have a status of IsPartiallyFilled = True as well (instead of IsPendingNew).

Also, I think that OnPositionChanged() does reflect partial fills. I cannot speak to why it was designed this way, though, in addition to why OnPositionOpened does not fire until after the order is changed from IsPartiallyFilled (or from IsPendingNew) to IsFilled.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 29, 2009 4:47 pm 
Offline

Joined: Wed Sep 26, 2007 10:03 pm
Posts: 100
OnPositionChanged() is also not activated after partial fills. See the log messages below I acquired during live trading on an paper trading account:

Quote:
29.01.2009 14:35:07 OnNewOrder. Symbol=MNG9. Time=14:35:07. Status=PendingNew. Qty=10. LastQty=0. LeavesQty=0. CumQty=0. Price=8525. AvgPrice=0. LastPrice=0. Text=ENTRY SELL LIMIT ORDER.
29.01.2009 14:35:07 OnOrderStatusChanged. Symbol=MNG9. Time=14:35:07. Status=New. Qty=10. LastQty=0. LeavesQty=10. CumQty=0. Price=8525. AvgPrice=0. LastPrice=0. Text=ENTRY SELL LIMIT ORDER.
29.01.2009 14:35:15 OnOrderPartiallyFilled. Symbol=MNG9. Time=14:35:07. Status=PartiallyFilled. Qty=10. LastQty=1. LeavesQty=9. CumQty=1. Price=8525. AvgPrice=8525. LastPrice=8525. Text=ENTRY SELL LIMIT ORDER.
29.01.2009 14:35:15 OnOrderStatusChanged. Symbol=MNG9. Time=14:35:07. Status=PartiallyFilled. Qty=10. LastQty=1. LeavesQty=9. CumQty=1. Price=8525. AvgPrice=8525. LastPrice=8525. Text=ENTRY SELL LIMIT ORDER.
29.01.2009 14:35:15 OnOrderPartiallyFilled. Symbol=MNG9. Time=14:35:07. Status=PartiallyFilled. Qty=10. LastQty=2. LeavesQty=7. CumQty=3. Price=8525. AvgPrice=8525. LastPrice=8525. Text=ENTRY SELL LIMIT ORDER.
29.01.2009 14:38:14 OnOrderPartiallyFilled. Symbol=MNG9. Time=14:35:07. Status=PartiallyFilled. Qty=10. LastQty=1. LeavesQty=6. CumQty=4. Price=8525. AvgPrice=8525. LastPrice=8525. Text=ENTRY SELL LIMIT ORDER.
29.01.2009 14:38:32 OnOrderPartiallyFilled. Symbol=MNG9. Time=14:35:07. Status=PartiallyFilled. Qty=10. LastQty=1. LeavesQty=5. CumQty=5. Price=8525. AvgPrice=8525. LastPrice=8525. Text=ENTRY SELL LIMIT ORDER.
29.01.2009 14:39:45 OnOrderPartiallyFilled. Symbol=MNG9. Time=14:35:07. Status=PartiallyFilled. Qty=10. LastQty=4. LeavesQty=1. CumQty=9. Price=8525. AvgPrice=8525. LastPrice=8525. Text=ENTRY SELL LIMIT ORDER.
29.01.2009 14:39:59 OnOrderStatusChanged. Symbol=MNG9. Time=14:35:07. Status=Filled. Qty=10. LastQty=1. LeavesQty=0. CumQty=10. Price=8525. AvgPrice=8525. LastPrice=8525. Text=ENTRY SELL LIMIT ORDER.
29.01.2009 14:39:59 OnPositionOpened. MNG9. Time=14:39. Side=Short. Qty=10. EntryQty=10. EntryPrice=8525. StopPrice=8593. InstrumentCurrency=EUR. FXfactor=1. Multiplier=1. InitialMargin=80245.52 USD
29.01.2009 14:39:59 OnOrderFilled. Symbol=MNG9. Time=14:35:07. Status=Filled. Qty=10. LastQty=1. LeavesQty=0. CumQty=10. Price=8525. AvgPrice=8525. LastPrice=8525. Text=ENTRY SELL LIMIT ORDER.
29.01.2009 14:39:59 OnOrderDone. Symbol=MNG9. Time=14:35:07. Status=Filled. Qty=10. LastQty=1. LeavesQty=0. CumQty=10. Price=8525. AvgPrice=8525. LastPrice=8525. Text=ENTRY SELL LIMIT ORDER.


The first partial fill was on 14:35:15, the last on 14:39:45, the (complete) position was added to the OQ portfolio at 14:39:59, almost 5 minutes after the first partial fill. During this time, OQ and TWS were not in sync...

Regards,
Boris


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 30, 2009 2:57 pm 
Offline
Site Admin

Joined: Thu Jul 17, 2003 10:39 am
Posts: 1478
Hi,

OQ creates new transaction and open/close/change position when order is filled or canceled with partiall fills.

Regards,
Alex

_________________
SmartQuant Development Team


Top
 Profile  
 
PostPosted: Sat Jan 14, 2012 3:12 pm 
Offline

Joined: Sun Oct 30, 2011 12:12 am
Posts: 220
Something is confusing in this post.

If a strategy which has no position (Position == null) sends an order which gets partially filled (say 75 shares out of 100), does the Position property remain null or will it reflect the partial position (ie 75 shares)?

Also, I'm coding features to log all Transactions in a CSV file, including partial fills, in OnOrderFilled() and OnOrderPartiallyFilled().
Surprisingly, there's no Transactions property in the Order class.
I was tempted to use Position.Transactions.Last() but Position will be null after an exit order (stop or profit target) is fully filled.
So I considered Portfolio.Transactions.Cast<Transaction>().Where(x => x.Instrument == Instrument).Last() but I wonder about multithreading.
Question: calling the above, can I be 100% sure that Portfolio.Transactions hasn't been updated by another thread (ie Last() wouldn't be referring anylonger to the Transaction I'm trying to log)?

Also, is OnOrderPartiallyFilled() called for the last partial fill before?
For example, for a 100 shares buy order:
- 25 shares filled: OnOrderPartiallyFilled called (total = 25)
- 50 shares filled: OnOrderPartiallyFilled called (total = 75)
- 25 shares filled: is OnOrderPartiallyFilled called or just OnOrderFilled?

Thanks!


Top
 Profile  
 
PostPosted: Mon Jan 16, 2012 9:54 am 
Offline
Site Admin

Joined: Thu Jul 17, 2003 10:39 am
Posts: 1478
Hi,

As I mentioned above, new Transaction is created when an order is done only. So, Portfolio.Transactions will not contain new transaction at partial fill.
You can safely enumerate transactions from the following callbacks:
OnOrder***
OnPosition***

_________________
SmartQuant Development Team


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 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:  
Powered by phpBB® Forum Software © phpBB Group