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.

comissions
 Post subject: comissions Post rating: 0   Post Posted: Wed 21 Dec, 2011, 06:18 

User rating: 0
Joined: Tue 22 Nov, 2011, 12:47
Posts: 130
Location: United States,
hi Support,

I would like to know what is the min required pips before closing a position so that I can at least cover the commissions.

Can you please show an example how to calculate that?


 
 Post subject: Re: comissions Post rating: 0   Post Posted: Wed 21 Dec, 2011, 08:03 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Commission policy is described here: https://www.dukascopy.com/swiss/english/ ... on-policy/


 
 Post subject: Re: comissions Post rating: 0   Post Posted: Wed 21 Dec, 2011, 10:56 

User rating: 0
Joined: Tue 22 Nov, 2011, 12:47
Posts: 130
Location: United States,
hi support,

I know this link and reviewed it.

My request is -

Can you please provide an example Strategy that creates an Order and calculates the minimum Take Profit in order to cover commission costs?

Many thanks!
cb888trader.


 
 Post subject: Re: comissions Post rating: 0   Post Posted: Tue 27 Dec, 2011, 16:51 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
It will be easier to do in next JForex Client release when new method
IOrder.getCommission()
will be available. Please follow the release information here: viewforum.php?f=71

For now please consider the following way how to calculate your order commission:
package jforex.account;

import java.text.DecimalFormat;
import java.util.SortedMap;

import com.dukascopy.api.Configurable;
import com.dukascopy.api.IAccount;
import com.dukascopy.api.IBar;
import com.dukascopy.api.IConsole;
import com.dukascopy.api.IContext;
import com.dukascopy.api.IMessage;
import com.dukascopy.api.IStrategy;
import com.dukascopy.api.ITick;
import com.dukascopy.api.Instrument;
import com.dukascopy.api.JFException;
import com.dukascopy.api.Period;
import com.dukascopy.api.RequiresFullAccess;
import com.dukascopy.api.system.ITesterClient;
import com.dukascopy.api.system.TesterFactory;

/**
 * The strategy prints out commissions of current Deposit, Equity and Turnorver limits for currencies
 * on deposits with Dukascopy Bank. For more details see:
 * https://www.dukascopy.com/swiss/english/forex/forex_trading_accounts/commission-policy/
 * Also the strategy prints out overnights, for more details see:
 * https://www.dukascopy.com/swiss/english/forex/forex_trading_accounts/overnight/
 *
 * Also the strategy calculates the commission for the given order amount
 */
@RequiresFullAccess
public class CommissionsTPCover implements IStrategy {

   @Configurable("Monthly turnover")
   public int monthlyTurnover = 10000000;
   // 22:00 GMT
   @Configurable("Equity at settlment")
   public int equityAtSettlment = 250000;
   @Configurable("Net deposit")
   public int netDeposit = 250000;
   @Configurable("Print commission info")
   public boolean printCommInfo = true;
   
   private ITesterClient client;
   private IConsole console;
   
   private final DecimalFormat df = new DecimalFormat("############");
   private final DecimalFormat dfComm = new DecimalFormat("0.000000");
   
   @Override
   public void onStart(IContext context) throws JFException {
      
      console = context.getConsole();
      
      try {
         client = TesterFactory.getDefaultInstance();
      } catch (Exception e) {
         console.getErr().println(e);
         context.stop();
         return;
      }
      
      if(printCommInfo){
         printCommissions(client.getCommissions().getDepositLimits(), "Deposit limits:");
         printCommissions(client.getCommissions().getEquityLimits(), "Equity limits:");
         printCommissions(client.getCommissions().getTurnoverLimits(), "Turnover limits:");
      }
      
      print("Commission for 1M: " + dfComm.format(getCommission(1)));
      print("Commission for 5M: " + dfComm.format(getCommission(5)));
   }
   
   private double getCommission(double amount){
      //commissions in units per 1 million order (e.g. in USD for 1M order)
      double depositComm = getCommission(client.getCommissions().getDepositLimits(), netDeposit);
      double equityComm = getCommission(client.getCommissions().getEquityLimits(), equityAtSettlment);
      double turnoverComm = getCommission(client.getCommissions().getTurnoverLimits(), monthlyTurnover);
      //min commission gets applied
      double commInUnits = Math.min(Math.min(depositComm, equityComm),turnoverComm);
      print("depositComm="+depositComm+" equityComm="+equityComm+" turnoverComm="+turnoverComm);
      //Order amounts are expressed in millions
      return (commInUnits / 1000000) * amount;
   }
   
   /**
    * Get commission by given limit -> commision map. Note the special case for the first
    * and the last limit
    *
    * @param commMap
    * @param limit
    * @return
    */
   private double getCommission(SortedMap<Double, Double> commMap, double limit){
      
      Double[] limitArray = commMap.keySet().toArray(new Double[0]);
      Double[] commissionArray = commMap.values().toArray(new Double[0]);
      
      //first limit
      if(limitArray[0] > limit){
         return commissionArray[0];
      }
      
      //second to second to last element
      for(int i=1; i < limitArray.length - 1; i++){
         if((limit >= limitArray[i] && limit < limitArray[i + 1])){
            return commissionArray[i];
         }
      }
      
      //last limit
      return commissionArray[commissionArray.length - 1];
      
   }   
   
   private void printCommissions(SortedMap<Double, Double> limitMap, String comment){
      print(comment.toUpperCase());
      Double firstKey = (Double)limitMap.keySet().toArray()[0];
      print("<" + firstKey + " = " + client.getCommissions().getMaxCommission() );
      for(Double key : limitMap.keySet()){
         print(">=" +df.format(key) + " = " + limitMap.get(key) );
      }
   }   
   
   private void print(Object o){
      console.getOut().println(o);
   }

   @Override
   public void onTick(Instrument instrument, ITick tick) throws JFException {}
   @Override
   public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {}
   @Override
   public void onMessage(IMessage message) throws JFException {}
   @Override
   public void onAccount(IAccount account) throws JFException {}
   @Override
   public void onStop() throws JFException {}

   
}


Attachments:
CommissionsTPCover.java [4.69 KiB]
Downloaded 438 times
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control on their content. Anyone accessing this webpage and downloading or otherwise making use of any document, data or information found on this webpage shall do it on his/her own risks without any recourse against Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from the use and/or reliance on any document, data or information found on this webpage.
 
 Post subject: Re: comissions Post rating: 0   Post Posted: Thu 29 Dec, 2011, 05:36 

User rating: 0
Joined: Tue 22 Nov, 2011, 12:47
Posts: 130
Location: United States,
hi Support,

I'm not interested in JForex Client. When will this functionality ( IOrder.getCommission() ) become available in JForex API / Standalone?

Again - thanks for the sample code!!


 
 Post subject: Re: comissions Post rating: 0   Post Posted: Thu 29 Dec, 2011, 08:48 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
cb888trader wrote:
When will this functionality ( IOrder.getCommission() ) become available in JForex API / Standalone?
It is already available in Standalone.


 
 Post subject: Re: comissions Post rating: 0   Post Posted: Thu 29 Dec, 2011, 08:49 

User rating: 0
Joined: Tue 22 Nov, 2011, 12:47
Posts: 130
Location: United States,
great thx!


 

Jump to:  

cron
  © 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