SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Tue Sep 24, 2019 11:47 am

All times are UTC + 3 hours




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Resume from crash
PostPosted: Thu Jan 22, 2015 6:34 pm 
Offline

Joined: Thu Jan 22, 2015 6:23 pm
Posts: 11
Hi,
Is there a way, when loading OQ, to re-create the portfolio to the same state before OQ was shut down?
i.e. suppose OQ is currently trading 1 or more instruments and you want to add changes in the strategy so you have to restart OQ, but still want to be synced again with the open positions in market.


Top
 Profile  
 
 Post subject: Re: Resume from crash
PostPosted: Thu Jan 22, 2015 6:49 pm 
Offline

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

are we talking about OQ 2013 or 2014?

Regards,
Anton


Top
 Profile  
 
 Post subject: Re: Resume from crash
PostPosted: Sun Jan 25, 2015 4:26 pm 
Offline

Joined: Thu Jan 22, 2015 6:23 pm
Posts: 11
Hi,
We're talking about OQ 2013.


Top
 Profile  
 
 Post subject: Re: Resume from crash
PostPosted: Sun Jan 25, 2015 4:52 pm 
Offline

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

you can use GetBrokerInfo in OnStrategyStart to request information about your account and positions from a broker (if this feature is supported for your particualr broker) and then add corresponding transactions to your startegy Portfolio, so that your broker and OpenQuant prortfolio get synchronized.

Regards,
Anton


Top
 Profile  
 
 Post subject: Re: Resume from crash
PostPosted: Sun Jan 25, 2015 4:53 pm 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6816
PS. You can take a look at this thread to get more info anout BrokerInfo and broker positions viewtopic.php?f=64&t=6516


Top
 Profile  
 
 Post subject: Re: Resume from crash
PostPosted: Thu Jan 29, 2015 6:08 pm 
Offline

Joined: Thu Jan 22, 2015 6:23 pm
Posts: 11
Thanks.
The post clarifies one side of the story.
The question remains how can i now use BrokerAccount.Orders & BrokerAccount.Positions object to set in OnStrategyStart() the portfolio & OrderManager? since i didn't see any option to add orders & positions to those objects.
Sell i use the BrokerOrder.AddOrder & BrokerOrder.AddPosition methods for that purpose?


Top
 Profile  
 
 Post subject: Re: Resume from crash
PostPosted: Tue Feb 03, 2015 4:11 pm 
Offline

Joined: Thu Jan 22, 2015 6:23 pm
Posts: 11
I've found also this post helpful -

viewtopic.php?f=41&t=9833&p=31093&hilit=AddPosition#p31093

but the question still remains - how to sync the positions in portfolio using the the positions fetched from DataManager.GetBrokerInfo(..)

Appreciate your assistance.


Top
 Profile  
 
 Post subject: Re: Resume from crash
PostPosted: Tue Feb 03, 2015 4:17 pm 
Offline

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

basically you need to add correcting transactions to OQ prortfolio in OnStrategyStart to synch broker positions and OQ portfolio positions.

Strategy.Portfolio

public void Add(DateTime datetime, Side side, double qty, Instrument instrument, double price, double commission, CommType commType)

or

public void Add(Transaction transaction)

Regards,
Anton


Top
 Profile  
 
 Post subject: Re: Resume from crash
PostPosted: Tue Feb 03, 2015 7:57 pm 
Offline

Joined: Thu Jan 22, 2015 6:23 pm
Posts: 11
Hi Anton,
Thanks for your input.

If i use Portfolio.Add(..) then as far as i can see it's only adds the transaction but when i look afterwards on the Portfolio window still the upper 'Position' control is still empty.
Usually when the strategy sends order that get filled in the market then we see it in OQ Portfolio window both as Transaction and Position.
I guess I'm wondering what am i missing here?
said that, what is the use then for -

- BrokerAccount.AddOrder(..)?
- BrokerAccount.AddPosition(..)?
- BrokerPosition & BrokerOrder objects?

I'm aiming towards fully sync OQ when it starts to get the position & orders info using DataManager.GetBrokerInfo(..)
Any chance you have a code snippet to support this?

also, following your response i've tested the following code on clean strategy in OnStrategyStart() -

try
{
this.Portfolio.Add(Clock.Now, TransactionSide.Buy, 50, new OpenQuant.API.Instrument(InstrumentType.Stock, "MSFT"), 41.27);
}
catch (Exception ex)
{
Console.WriteLine(string.Format("{0} -->> {1}",ex.Message , ex.StackTrace));
}

and keep getting the following error -
Object reference not set to an instance of an object. -->> at SmartQuant.Instruments.PositionList.get_Item(Instrument instrument)
at SmartQuant.Instruments.Portfolio.Add(Transaction transaction)
at OpenQuant.API.Portfolio.Add(DateTime datetime, TransactionSide side, Double qty, Instrument instrument, Double price, String text)
at OpenQuant.API.Portfolio.Add(DateTime datetime, TransactionSide side, Double qty, Instrument instrument, Double price)


Top
 Profile  
 
 Post subject: Re: Resume from crash
PostPosted: Wed Feb 04, 2015 2:42 pm 
Offline

Joined: Thu Jan 22, 2015 6:23 pm
Posts: 11
Hi,
Managed to figure it out.
It's impossible to add to portfolio transaction on instrument that does not exists in the instruments list.
Once i've created MSFT instrument it worked just fine.

thanks.


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