SmartQuant Discussion
http://www.smartquant.com/forums/

Resume from crash
http://www.smartquant.com/forums/viewtopic.php?f=44&t=10883
Page 1 of 1

Author:  shomen [ Thu Jan 22, 2015 6:34 pm ]
Post subject:  Resume from crash

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.

Author:  Dr. Anton Fokin [ Thu Jan 22, 2015 6:49 pm ]
Post subject:  Re: Resume from crash

Hi,

are we talking about OQ 2013 or 2014?

Regards,
Anton

Author:  shomen [ Sun Jan 25, 2015 4:26 pm ]
Post subject:  Re: Resume from crash

Hi,
We're talking about OQ 2013.

Author:  Dr. Anton Fokin [ Sun Jan 25, 2015 4:52 pm ]
Post subject:  Re: Resume from crash

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

Author:  Dr. Anton Fokin [ Sun Jan 25, 2015 4:53 pm ]
Post subject:  Re: Resume from crash

PS. You can take a look at this thread to get more info anout BrokerInfo and broker positions viewtopic.php?f=64&t=6516

Author:  shomen [ Thu Jan 29, 2015 6:08 pm ]
Post subject:  Re: Resume from crash

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?

Author:  shomen [ Tue Feb 03, 2015 4:11 pm ]
Post subject:  Re: Resume from crash

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.

Author:  Dr. Anton Fokin [ Tue Feb 03, 2015 4:17 pm ]
Post subject:  Re: Resume from crash

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

Author:  shomen [ Tue Feb 03, 2015 7:57 pm ]
Post subject:  Re: Resume from crash

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)

Author:  shomen [ Wed Feb 04, 2015 2:42 pm ]
Post subject:  Re: Resume from crash

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.

Page 1 of 1 All times are UTC + 3 hours
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/