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.

R integration in JForex crashes
 Post subject: R integration in JForex crashes Post rating: 1   New post Posted: Fri 06 Apr, 2012, 18:10 
User avatar

User rating: 11
Joined: Tue 27 Mar, 2012, 17:47
Posts: 111
Location: GermanyGermany
Hello,

I'm trying to integrate R(similar to Matlab) within JForex via rJava and JRI, see here.
Here is a code snippet:
public void onStart(IContext context) throws JFException {
        this.engine = context.getEngine();
        this.console = context.getConsole();
        this.history = context.getHistory();
        this.context = context;
        this.indicators = context.getIndicators();
        this.userInterface = context.getUserInterface();
        this.account = context.getAccount();
       
        try {
            String[] test={"--no-save"};
            consolePrint("Creating Rengine (with arguments)");
            Rengine re=new Rengine(test, false, null);
            consolePrint("Rengine created, waiting for R");
            if (!re.waitForR()) {
                consolePrint("Cannot load R");
                return;
            }
            /* HERE OCCURS JFOREX CRASH ! */
            REXP x=re.eval("1+1");
            //consolePrint("R response: "+x.asInt());
        } catch (Exception e) {
            // TODO Auto-generated catch block
            consolePrint("exception "+e);
        }
       
        //Create instruments objects
        for(Instrument i : Instruments){
            InstrumentObject iState = new InstrumentObject(i);
            InstrumentStateList.add(iState);
        }
    }

Running this code results in a JForex crash.
The problem is that JForex just closes immediatley and no error message is given.
When removing this critical line:
REXP x=re.eval("1+1");

then JForex runs stable.
If someone here uses also R it would be nice how to run it within JForex.

@Support: Is there any log file where one can see critical crash messages? When JForex closes it also closes the Java console.
Is there any more native debug possibilty?

Thanky you and best regards,
Juergen


 
 Post subject: Re: R integration in JForex crashes Post rating: 0   New post Posted: Fri 06 Apr, 2012, 19:03 
User avatar

User rating: 11
Joined: Tue 27 Mar, 2012, 17:47
Posts: 111
Location: GermanyGermany
Ok, I figured out that the formentioned line is not responsible for the crash.
The real problem is that the strategy can only start once and is able to communicate with the Rengine object.
After stopping the strategy and restarting, thenJForex crashes.
I suspect some DLL or class loading issues??!!
How can one really clean up everything in the onStop method?
And still, are there any log files for JForex crashes?

Thanks,
Juergen


 
 Post subject: Re: R integration in JForex crashes Post rating: 0   New post Posted: Fri 06 Apr, 2012, 22:53 
User avatar

User rating: 11
Joined: Tue 27 Mar, 2012, 17:47
Posts: 111
Location: GermanyGermany
If someone is interested, there is a solution to this problem.
Rengine is not able of multithreading, so on re-initialisation of a strategy the JVM crashes rather badly.
See here for a similar question.
This means that one has to restart JForex before calling a strategy twice or uses Rserve instead.
This is a server for R which listens on a TCP/IP port and is easy to use.

Happy trading with R, you quant-guys :)
Juergen


 

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