Dukascopy
 
 
Wiki JStore Search Login

Attention! Read the forum rules carefully before posting a topic.

    Try to find an answer in Wiki before asking a question.
    Submit programming questions in this forum only.
    Off topics are strictly forbidden.

Any topics which do not satisfy these rules will be deleted.

Amount Rounding
 Post subject: Amount Rounding Post rating: 0   New post Posted: Mon 10 Dec, 2012, 16:35 

User rating: 0
Joined: Tue 22 Nov, 2011, 12:47
Posts: 130
Location: United States,
please advice how to write a method that makes sure a certain amount is rounded to a valid value.


 
 Post subject: Re: Amount Rounding Post rating: 0   New post Posted: Mon 10 Dec, 2012, 16:48 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
See:
https://www.dukascopy.com/wiki/#Rounding_prices


 
 Post subject: Re: Amount Rounding Post rating: 0   New post Posted: Mon 10 Dec, 2012, 16:56 

User rating: 0
Joined: Tue 22 Nov, 2011, 12:47
Posts: 130
Location: United States,
I am well aware of that sample code.

I'm not talking about rounding prices. I'm talking about rounding Amounts.

please advice on exact rounding scheme and provide example code.


 
 Post subject: Re: Amount Rounding Post rating: 0   New post Posted: Mon 10 Dec, 2012, 16:59 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
There is no rounding required from the JForex-API side, for more on order amounts see:
https://www.dukascopy.com/wiki/#Order_Amounts


 
 Post subject: Re: Amount Rounding Post rating: 0   New post Posted: Mon 10 Dec, 2012, 17:03 

User rating: 0
Joined: Tue 22 Nov, 2011, 12:47
Posts: 130
Location: United States,
support - you are wrong.

from exactly the URL that you are suggesting:

Quote:
However, the following code will create an order of amount of 1235 units in EUR/USD (note the rounding):
engine.submitOrder("order1", Instrument.EURUSD, OrderCommand.BUY, 0.00123456789);


please provide a rounding scheme and an example code that prevent the above from happening. I want to send to the server a rounded amount so I need a validation function that rounds the given amount (0.00123456789) into a rounded amount (0.0012345)

and please make sure that the example supports all instruments.


 
 Post subject: Re: Amount Rounding Post rating: 0   New post Posted: Tue 11 Dec, 2012, 08:52 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
cb888trader wrote:
support - you are wrong.

from exactly the URL that you are suggesting:
Quote:
However, the following code will create an order of amount of 1235 units in EUR/USD (note the rounding):
engine.submitOrder("order1", Instrument.EURUSD, OrderCommand.BUY, 0.00123456789);

So where does it say, that the strategy has to do the amount rounding? It is done on the server side.
cb888trader wrote:
please provide a rounding scheme and an example code that prevent the above from happening. I want to send to the server a rounded amount so I need a validation function that rounds the given amount (0.00123456789) into a rounded amount (0.0012345)
Please refer to the first articles method round, but use BigDecimal.ROUND_DOWN for your case:
https://www.dukascopy.com/wiki/#Rounding_prices


 
 Post subject: Re: Amount Rounding Post rating: 0   New post Posted: Tue 11 Dec, 2012, 09:30 

User rating: 0
Joined: Tue 22 Nov, 2011, 12:47
Posts: 130
Location: United States,
It is really hard to get information from support.

so the rounding scheme is BigDecimal.ROUND_DOWN - OK.

what about decimal places? what value should be used for amounts ?

finally - is the rounding calc is similar for ALL instruments?? if not - please advice how to adapt for all instruments.

Why can't support provide an example method for rounding Amounts? my time is wasted with all this round trips!!


 
 Post subject: Re: Amount Rounding Post rating: 0   New post Posted: Tue 11 Dec, 2012, 09:40 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
cb888trader wrote:
what about decimal places? what value should be used for amounts ?
This can be found in the aforementioned wiki article:
Quote:
In JForex API amounts of orders are represented in millions, meaning that by submitting a long order with amount 1 and instrument EUR/USD, on full, successful fill 1 million units (i.e. 1'000'000 USD) will get bought. The minimum order amount is 1000 units (with the exception of XAG/USD and XAU/USD which have the minimum amounts 50 and 1 units (i.e. 50 and 1 ounces) respectively).

cb888trader wrote:
finally - is the rounding calc is similar for ALL instruments?? if not - please advice how to adapt for all instruments.
From the same wiki article:
Quote:
Order amount minimum increment is one unit.

cb888trader wrote:
Why can't support provide an example method for rounding Amounts? my time is wasted with all this round trips!!
All the relevant information is given and supported with examples.


 
 Post subject: Re: Amount Rounding Post rating: 0   New post Posted: Tue 11 Dec, 2012, 10:36 

User rating: 0
Joined: Tue 22 Nov, 2011, 12:47
Posts: 130
Location: United States,
from the information that you provided - it seems that rounding should be handled differently for XAG/USD and XAU/USD

I don't want to make mistakes, can you please provide an example method that receives amount (of type double) and an instrument and returns a rounded amount accordingly?

Again - from the material that you pasted up to now, one should collect the information from various URLs / sources and construct the method from those information pieces. This is risky and could lead to bugs.

For my strategy it is crucial to know exactly what amount is being sent to the server.

Can support provide an example method??


 
 Post subject: Re: Amount Rounding Post rating: 2   New post Posted: Fri 28 Dec, 2012, 03:01 
User avatar

User rating: 70
Joined: Sat 22 Sep, 2012, 17:43
Posts: 118
Location: Brazil, Fortaleza, Ceará
Dear Mr cb888trader,

if you're going to make a point of being rude to people that offer valuable time trying to help you,
you're going to have to smarten up and work out how to solve simple problems on your own!!

Everything you need to know is not "various URLs" away but right here on this very page.

With respect to currencies:

"1" means 1 million currency units (1,000,000) - 7 significant digits.

"0.000001" (7 significant digits) means 1 currency unit.

"0.001000" (the MINIMUM) means 1000 currency units - 0.001

Without clicking any of the URLs above it's clear that the quote you have provided:

that rounds the given amount (0.00123456789) into a rounded amount (0.0012345)

makes no sense as the minimum tradeable unit is 1000 currency units or 0.001000

meaning rounding your given 0.00123456789 produces 0.001234 (truncated) or 0.001235 (rounded up/traditional) or 0.001234 (rounded down).


With respect to gold (xau/usd):

"1" means 1 million ounces (1,000,000) - 7 significant digits.

"0.000001" (7 significant digits) means 1 ounce.

"0.000001" (the MINIMUM) means 1 ounce - 0.000001


With respect to silver (xag/usd):

"1" means 1 million ounces (1,000,000) - 7 significant digits.

"0.000001" (7 significant digits) means 1 ounce.

"0.000050" (the MINIMUM) means 50 ounces - 0.00005

IN ALL CASES MINIMAL INCREMENTS ABOVE THE MINIMUMS IS ONE UNIT

0.000001 - 7 significant digits

If one sticks to this minimal increment rule there is no chance to generate more than 7 significant digits and therefore no rounding issue.
Rounding of course meaning having to deal with cutting away extra digits provided.

So no increments of 0.00000101 (more than 0.000001 sure but less than 0.000002 the next valid amount)

In elementary school we are often thought to "round up" such that if the digit following the last significant digit we are looking at is a 5 or more,
we should add a 1 to the last significant digit we are interested in.

E.g. 1.23447 rounded to 5 significant digits yields 1.2345 as the 6th digit we are not interested in is 5 or more.

Support has told you that there is a need IN YOUR CASE to "round down" at your end.

This means contrary to what we are initially taught, when the digit following the last significant digit we are interested in is 5 or more,
we do not add a 1 to the last significant digit we are interested in.

If that extra digit is >= 5, we leave all alone and truncate.

So 1.23445 rounded down to 5 significant digits yields 1.2344
and 1.23446 rounded down to 5 significant digits yields 1.2344

The reason you round down is because 1234 currency units is 1234 currency units
until it becomes 1235 (minimum increments of 1 unit no fractional increases).

If you order 1234.56789 units (which is what "0.00123456789") looks like to the trading server, if it's left to the standard java maths libraries
this becomes 1235 when rounded to the 7 significant digits needed (0.001235).

Acceptable parameters to avoid this are all over the wiki, docs and forum chats.

If you parse the order amounts yourself, you have the chance to round it down if your
strategies works in a any that it might generate fractional order amounts that do
not follow guidelines. This means even if the 8th significant digit is 5, 6, 7, 8 or 9
you don't add any 1 to the 7th digit before it - that's your order amount filter.

ORDER AMOUNT FILTER

So in java you just want the floor() after multiply by 1,000,000 then you
divide by 1,000,000 again

//turn orderamt 0.00123456789 into 1234.56789 and floor it to get 1234
long check = Math.floor(orderamt * 1000000);
//turn 1234 into 0.001234 ready for use.
orderamt = check / 1000000;


//turn orderamt 2500 ($2.5B) into 2500000000 and floor it to get 2500000000
long check = Math.floor(orderamt * 1000000);
//turn 2500000000 into 2500.0 ready for use.
orderamt = check / 1000000;


or the round down BigDecimal things support mentioned.

I'm writing this stuff off the top of my head so just take the general idea.

MINIMUM CURRENCY TEST

if order amount < "0.001000"

WILL THERE BE A SERVER ROUNDING EVENT ON CURRENCY ORDER TEST

if order amount contains more than 7 significant digits and the 8th digit is >= 5
OR
if order amount * 1000000 contains a fractional component >= 0.5
OR
use some function that lets you know if it will or won't round a given number up when returned to N=7 significant digits

0.000009 - Minimum Fail / Rounding doesn't matter
0.00000900 - Minimum Fail / Rounding doesn't matter
0.00000990 - Minimum Fail / Rounding doesn't matter but would round to 0.000010
0.009000 - Minimum Pass / No Rounding
0.00900923 - Minimum Pass / No Rounding becomes 9009 units
0.00900925 - Minimum Pass / No Rounding becomes 9009 units
0.00900953 - Minimum Pass / Rounding becomes 9010 units
0.00099965 - Minimum Fail / Rounding doesn't matter but
would round to 0.001000 hit the minimum and generate an order

MINIMUM GOLD TEST

if order amount < "0.000001"

WILL THERE BE A SERVER ROUNDING EVENT ON GOLD ORDER TEST

if order amount contains more than 7 significant digits and the 8th digit is >= 5
OR
if order amount * 1000000 contains a fractional component >= 0.5
OR
use some function that lets you know if it will or won't round a given number up when returned to N=7 significant digits

0.00000010 - Minimum Fail / Rounding doesn't matter
0.00000015 - Minimum Fail / Rounding doesn't matter but would round to 0.000000[20]
0.00000092 - Minimum Fail / Rounding doesn't matter but
would round to 0.000001 hit the minimum and generate an order
0.000009 - Minimum Pass / No Rounding
0.00000901 - Minimum Pass / No Rounding becomes 9 units
0.00000923 - Minimum Pass / No Rounding becomes 9 units
0.00000953 - Minimum Pass / Rounding becomes 10 units
0.00049905 - Minimum Pass / No Rounding becomes 499 units
0.00049950 - Minimum Pass / Rounding becomes 500 units

MINIMUM SILVER TEST

if order amount < "0.000050"

WILL THERE BE A SERVER ROUNDING EVENT ON SILVER ORDER TEST

if order amount contains more than 7 significant digits and the 8th digit is >= 5
OR
if order amount * 1000000 contains a fractional component >= 0.5
OR
use some function that lets you know if it will or won't round a given number up when returned to N=7 significant digits

0.000009 - Minimum Fail / Rounding doesn't matter
0.00000900 - Minimum Fail / Rounding doesn't matter
0.00000990 - Minimum Fail / Rounding doesn't matter but would round to 0.000010
0.000060 - Minimum Pass / No Rounding
0.00006923 - Minimum Pass / No Rounding becomes 69 units
0.00005048 - Minimum Pass / No Rounding becomes 50 units
0.00005050 - Minimum Pass / Rounding becomes 51 units
0.00004994 - Minimum Fail / Rounding doesn't matter but
would round to 0.000050 hit the minimum and generate an order


Excuse all typos - If everything here is all wrong the mango rum is still wearing off, at least I tried :)


 

Jump to:  

  © 1998-2025 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com