发布于2024-11-10 22:26 阅读(754) 评论(0) 点赞(20) 收藏(0)
我收到以下错误:
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);
}
}
如果我尝试在command
RI 中运行,则得到:
EOImpVol<-EuropeanOptionImpliedVolatility("看跌",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());
}
}
}
作者:黑洞官方问答小能手
链接:http://www.javaheidong.com/blog/article/693739/fd7bdac42a3c631bfea9/
来源:java黑洞网
任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任
昵称:
评论内容:(最多支持255个字符)
---无人问津也好,技不如人也罢,你都要试着安静下来,去做自己该做的事,而不是让内心的烦躁、焦虑,坏掉你本来就不多的热情和定力
Copyright © 2018-2021 java黑洞网 All Rights Reserved 版权所有,并保留所有权利。京ICP备18063182号-2
投诉与举报,广告合作请联系vgs_info@163.com或QQ3083709327
免责声明:网站文章均由用户上传,仅供读者学习交流使用,禁止用做商业用途。若文章涉及色情,反动,侵权等违法信息,请向我们举报,一经核实我们会立即删除!