Skip to content

Instantly share code, notes, and snippets.

@tomas-rampas
Created August 17, 2016 19:29
Show Gist options
  • Save tomas-rampas/c4c1d1ee69a09a8e6c49631264de2d9d to your computer and use it in GitHub Desktop.
Save tomas-rampas/c4c1d1ee69a09a8e6c49631264de2d9d to your computer and use it in GitHub Desktop.
import com.dukascopy.api.*;
import org.rosuda.JRI.REXP;
import org.rosuda.JRI.Rengine;
/**
* Created by tomas on 8/17/2016.
*/
public class JRITestStrategy implements IStrategy {
@Override
public void onStart(IContext context) throws JFException {
}
@Override
public void onTick(Instrument instrument, ITick tick) throws JFException {
}
@Override
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
if(period == Period.FIVE_MINS){
Rengine re = new Rengine(new String[]{"--no-save"}, false, null);
if (!re.waitForR()) {
System.out.println("Cannot load R");
return;
}
re.eval("msg<-'HI there'");
REXP s = re.eval(String.format("capture.output(source('%s'))", getClass().getClassLoader().getResource("rscript/test.R").getPath().substring(1)));
String[] output = s.asStringArray();
System.out.println(String.join("\n", output));
re.end();
}
}
@Override
public void onMessage(IMessage message) throws JFException {
}
@Override
public void onAccount(IAccount account) throws JFException {
}
@Override
public void onStop() throws JFException {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment