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());
}