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

Margin calucation logic for Forex / FX
http://www.smartquant.com/forums/viewtopic.php?f=59&t=10227
Page 1 of 1

Author:  drolles [ Sun Jun 17, 2012 6:29 pm ]
Post subject:  Margin calucation logic for Forex / FX

Greatly, appreciate anyone’s comments here?

Has anyone seen or is happy to share some good FX margin calculator code?

I’m trying to develop some code which will calculate margin on the fly and allow me to set parameters prior to strategy launch. E.g. margin rate = 200, don’t use more than 50% of account, etc.

A good base for the calculations required are here:

http://www.interactivebrokers.com/en/p. ... ex-default

http://ibkb.interactivebrokers.com/node/970

Thanks and regards,

drolles

Author:  drolles [ Wed Jul 11, 2012 9:58 pm ]
Post subject:  Margin Calcuation for FX

Hi,

I’m wondering if someone could please help.

I’m working with a broker who is providing 200:1 leverage / margin on positions.

I would like to model this so I can ensure that I’m always well within the account margin requirements.

I’ve searched the forum on Margin & Margin Requirements.

I can’t find any reference to Margin other than the open positions within the Portfolio screen.

In this thread the question gets asked if this is a percentage, dollars, etc: viewtopic.php?t=6858. It doesn’t get answered.

Given Currenex doesn’t provide broker information (which I assumes includes something like remaining margin: ) I need to calculate this manually.

Any thoughts?

Thanks,

drolles

Author:  drolles [ Thu Jul 12, 2012 12:43 am ]
Post subject:  Value vs Qty of position with margin calculation

I’ve done some further testing on this.

You can use the Instrument Margin as a decimal to achieve this. E.g. if leverage is 200:1 you can 1/200 = 0.005. This seems to work on most cases. However, the challenges is with JPY crosses. The differences between Qty and Value of the position.

I’ve got an example with USDJPY of this not being quite right. The margin is calculated on Qty and not Value. A broker with use margin on the value of the trade not on the Qty.

Strategy.Position does have GetValue. I’ve included a screen shot here:

1. Shows the position details in the Portfolio screen
2. Show the some of the Output screen with a line of code

Code:
Console.WriteLine("Position Margin is: " + Position.Margin + " Instrument = " + Instrument.ToString());

OQ support – Could we please have a comment here? This doesn’t appear to make sense. With FX should Margin be calculated on Value, as opposed to Qty?

Thanks and regards,

drolles

Attachments:
Margin calucation - value.JPG
Margin calucation - value.JPG [ 12.14 KiB | Viewed 6237 times ]
Margin calucation - position.JPG
Margin calucation - position.JPG [ 17.45 KiB | Viewed 6237 times ]

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