Dukascopy
 
 
Wiki JStore Search Login

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

    Submit JForex API bug reports in this forum only.
    Submit Converter issues in Converter Issues.
    Off topics are strictly forbidden.

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

JFUtils.convert returns false value
 Post subject: JFUtils.convert returns false value Post rating: 0   New post Posted: Thu 26 Feb, 2015, 16:37 
User avatar

User rating: 2
Joined: Wed 03 Sep, 2014, 09:11
Posts: 32
Location: GermanyGermany
Hi,

i think the JfUtils.convert method returns a false value if the pipvalues of given instruments not equal:


    2015-02-26 16:21:05.044 INFO - convert: amount 1,000000 instrumentFrom USD/CAD -> instrumentTo EUR/USD result=0,804790
    2015-02-26 16:21:05.045 INFO - convert: amount 1,000000 instrumentFrom GBP/JPY -> instrumentTo EUR/USD result=0,008410

convert amount 1.0 GBP/JPY to EUR/USD must be 0,8410 not 0,008410 in this example!


public class StrategyTestConvertUtils implements IStrategy, IFeedListener {

    private static final Logger LOGGER = LoggerFactory.getLogger(StrategyTestConvertUtils.class);
    private IContext context;
    private JFUtils utils;
    private Set<Instrument> instruments;
    private double equity;

    @Override
    public void onStart(IContext context) throws JFException {
        this.context = context;
        this.utils = context.getUtils();
        this.instruments = new HashSet<>();
        instruments.add(Instrument.EURUSD);
        instruments.add(Instrument.GBPJPY);
        instruments.add(Instrument.EURGBP);
        instruments.add(Instrument.EURCAD);
        instruments.add(Instrument.USDCAD);

        context.setSubscribedInstruments(instruments);
    }

    @Override
    public void onTick(Instrument instrument, ITick tick) throws JFException {
        if (equity == 0) {
            return;
        }
        double result;
        double amount = 1.0D;
        Instrument instrumentTo, instrumentFrom;

        instrumentTo = Instrument.EURUSD;
        instrumentFrom = instrument;

        if (instrumentFrom == Instrument.GBPJPY || instrumentFrom == Instrument.USDCAD) {
            result = utils.convert(instrumentFrom, instrumentTo, 1);
            String format = String.format("convert: amount %.06f instrumentFrom %s -> instrumentTo %s result=%.6f",
                                          new Object[]{amount, instrumentFrom, instrumentTo, result});
            context.getConsole().getInfo().print(format);
//            LOGGER.info(format);
//             context.stop();
        }
    }

    @Override
    public void onAccount(IAccount account) throws JFException {
        this.equity = account.getEquity();

    }

    @Override
    public void onMessage(IMessage message) throws JFException {

    }

    @Override
    public void onStop() throws JFException {

    }

    @Override
    public void onFeedData(IFeedDescriptor feedDescriptor, ITimedData feedData) {

    }

    @Override
    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {

    }

}



workaround:

double result;
double intermediateRate = utils.convert(instrumentFrom, instrumentTo, 1);
if (instrumentFrom.getPipValue() == instrumentTo.getPipValue()) {
       result = intermediateRate;
   } else {
       result = intermediateRate * (instrumentFrom.getPipValue() / instrumentTo.getPipValue());
   }


 
 Post subject: Re: JFUtils.convert returns false value Post rating: 0   New post Posted: Fri 27 Feb, 2015, 17:00 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
This is not a bug. When JFUtils converts 1 GBP/JPY to EUR/USD the result is equal to JPY/USD rather than GBP/USD. Hence GBP/JPY to EUR/USD must be 0,008410.


 
 Post subject: Re: JFUtils.convert returns false value Post rating: 0   New post Posted: Sat 28 Feb, 2015, 15:16 
User avatar

User rating: 2
Joined: Wed 03 Sep, 2014, 09:11
Posts: 32
Location: GermanyGermany
Hi,

thx for your answer but that can not be right!
Please calculate the pip value of both pairs in account currency (EUR) and then the comparable amount!
What is the result ???


 

Jump to:  

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