簡體   English   中英

Java中的RCaller和RQuantlib錯誤

[英]RCaller & RQuantlib error in java

我收到以下錯誤:

Exception in thread "main" rcaller.exception.RCallerExecutionException: RExecutable is not defined. Please set this variable to full path of R executable binary file.

話雖這么說,我已經分別測試了RCaller並使其工作(基本的1 + 1示例)。

我嘗試在Java中運行的代碼如下:

        public void computeImpliedVol(siteCall.reqObj rO) {
            try {
                double price;
                String modCP=callPut.contains("P")?"put":"call";
                SimpleDateFormat sf = new SimpleDateFormat("yyyyMMdd");
                DecimalFormat df = new DecimalFormat("########");

                Date dMat = sf.parse(df.format(maturity));
                Date dt;
                double diff;
                caller.setRscriptExecutable("C:/Program Files/R/R-2.15.2/bin/Rscript");

                String command;


                for (Double d : hTimeSeries.keySet()) {
                    caller.addRCode("library(RQuantLib)");
                    dt = sf.parse(df.format(d));
                    diff=(dMat.getTime()-dt.getTime())/(60.0*60.0*1000.0*24.0)/365.0;
                    if (longShort > 0) {
                        price = hTimeSeries.get(minDate).ask;
                    } else {
                        price = hTimeSeries.get(minDate).bid;
                    }
                    command = "EOImpVol<-EuropeanOptionImpliedVolatility(\"" + modCP + "\"," 
                           + price + "," + rO.requestObject.get(d).hAClose + "," + strike + ",0,.03," + 
                             diff + ",.2)";
                     caller.addRCode(command);
                     caller.runAndReturnResultOnline("EOImpVol");
                     double rDbl[]=caller.getParser().getAsDoubleArray("EOImpVol");
                     rDbl=rDbl;
                }
            } catch (ParseException ex) {
                Logger.getLogger(optionDB.class.getName()).log(Level.SEVERE, null, ex);
            }

        }

如果我嘗試在RI中運行command ,請獲取:

EOImpVol <-EuropeanOptionImpliedVolatility(“ put”,1.9,21.18,21.0,0,.03,0.10410958904109589,.2)EOImpVol $ impliedVol [1] 0.7518471

        $parameters
        $parameters$type
        [1] "put"

        $parameters$value
        [1] 1.9

        $parameters$underlying
        [1] 21.18

        $parameters$strike
        [1] 21

        $parameters$dividendYield
        [1] 0

        $parameters$riskFreeRate
        [1] 0.03

        $parameters$maturity
        [1] 0.1041096

        $parameters$volatility
        [1] 0.2


        attr(,"class")
        [1] "EuropeanOptionImpliedVolatility" "ImpliedVolatility" 

所以我認為它工作正常。 是否有明顯的事情發生,我沒有意識到是新事物?

非常感謝你

工作示例:

            /*
             * To change this template, choose Tools | Templates
             * and open the template in the editor.
             */
            package intelopts;

            import java.io.File;
            import rcaller.RCaller;
            import rcaller.RCode;

            /**
             *
             * @author Jason
             */
            public class rTest {

                public void test() {
                    try {
                        RCaller caller = new RCaller();
                        caller.setRscriptExecutable("C:/Program Files/R/R-2.15.2/bin/Rscript");

                        RCode code = new RCode();
                        code.clear();

                        code.addRCode("library(RQuantLib)");

                        code.addRCode(" EOImpVol<-EuropeanOptionImpliedVolatility(\"put\",1.9,21.18,21.0,0,.03,0.10410958904109589,.2)");


                        caller.setRCode(code);
                        caller.runAndReturnResult("EOImpVol");
                        double[] d=caller.getParser().getAsDoubleArray("impliedVol");

                    } catch (Exception e) {
                        System.out.println(e.toString());
                    }
                }
            }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM