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

stop loss for portfolio
http://www.smartquant.com/forums/viewtopic.php?f=42&t=9837
Page 1 of 1

Author:  dvnkng [ Tue Dec 20, 2011 11:23 pm ]
Post subject:  stop loss for portfolio

Does anyone know how to write fix stop order code for multiple instruments denominated different currencies ?
ex. I want to put stop market order if my portfolio goes down to $5000 from DAX, S&P combined.

Thanks

Author:  PBJ [ Wed Dec 21, 2011 2:08 am ]
Post subject:  Re: stop loss for portfolio

My first idea would be to monitor current P&L in realtime via OnQuote for both instruments when you have positions opened.

In OnQuote, I would check the P&L for each instrument: for example if you are long S&P and short DAX, compare the S&P bid (= price at which you can exit your long) and the DAX ask (= price at which you can exit your short) to your average entry prices for each instruments. P&L(instrument) = (current price(instrument) - avg entry price(instrument)) x position quantity(instrument).
Only issue remaining is currency conversion: if USD is your account base currency, you have to convert the DAX P&L from EUR to USD before adding it to your S&P P&L (which is already in USD).
Therefore: TotalUSDPnL = S&P PnL + (DAX PnL * EUR/USD).
Either you convert the DAX P&L using realtime rates (ie you have to subscribe to a third instrument: EUR/USD) or on a hard coded basis (ie store a member in your class "double _eurusdRate = 1.30783"). I'd suggest the realtime rates for pair trading.

There are certainly more elegant ways to do that.
For example, P&L is already calculated in Position.GetPnL and a few other methods (GetUnrealizedPnL()...).
If you're pair trading, enter this in Google without quotes: "site:smartquant.com pair trading".

Hope it helps.

Author:  dvnkng [ Thu Dec 22, 2011 9:05 pm ]
Post subject:  Re: stop loss for portfolio

Hi, Thank you so much your reply.

Is there a way to read directly read or monitor the PnL in execution platform ? I am running OpenQuant with TT API and wondering if OQ can monitor the PnL value in X_Traeder's fill window..

Thanks

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