这是我的userDetailsHOme.jsp。在这里,我设计了一个按钮“设置”。 一旦我点击“设置”,就会打开一个对话框弹出窗口,其中包含很少的文本字段和一个用于提交字段的继续按钮。 在提交按钮时,我将其映射到名为“BestStrategyAction”的操作,该操作又返回grid.jsp文件。 在reuturn语句之前的BestStrategyAction类中,我已经打印了SYSO,以确认所有内容都已执行。 问题是代码执行到Syso但不显示网格。
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
<%@ taglib prefix="sjg" uri="/struts-jquery-grid-tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<sj:head jqueryui="true" />
<s:head />
<script type="text/javascript" src="/OptionsTrader2/struts/js/base/jquery-1.5.2.min.js"></script>
<script type="text/javascript" src="/OptionsTrader2/js/jquery-ui-latest.js"></script>
<script type="text/javascript" src="/OptionsTrader2/struts/js/plugins/jquery.subscribe.min.js"></script>
<script type="text/javascript" src="/OptionsTrader2/js/jquery.layout-latest.js"></script>
<script type="text/javascript" src="/OptionsTrader2/js/jquery.tipsy.js"></script>
<script type="text/javascript" src="/OptionsTrader2/js/jquery.flot.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/OptionsTrader2/js/jqplot.highlighter.min.js"></script>
<script type="text/javascript" src="/OptionsTrader2/js/jqplot.cursor.min.js"></script>
<link rel="shortcut icon" type="image/x-icon" href="/OptionsTrader2/img/favicon.ico" />
<link id="jquery_theme_link" rel="stylesheet" href="/OptionsTrader2/css/absolution/jquery.ui.all.css" type="text/css" />
<link rel="stylesheet" type="text/css" href="/OptionsTrader2/css/jquery_layout.css" />
<link rel="stylesheet" href="/OptionsTrader2/css/tipsy.css" type="text/css">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<body>
<div class="ui-layout-center">
</div>
<div id="toolbar" class="ui-layout-north">
<button id="settingsButton" onclick="$('#settingsDialog').dialog('open')"
title="Click to customize your strategy settings.">Settings
</button>
</div>
<div id="settingsDialog"
style="font-size: 11px;" class="ui-layout-content ui-widget-content">
<form id="changeSetting" name="changeSetting">
<table>
<tr>
<td><label for="underlyingSelect">Select Underlying</label></td>
<td>
<sj:select href="underlyingAction" id="underlyingName" name="underlyingName" list="underlyingList" cssClass="text ui-widget-content ui-corner-all" />
</td>
</tr>
<tr>
<td><label for="enterinvestment">Enter Investment Amount in Rs. *</label></td>
<td><input type="text" name="amount" id="amount" class="text ui-widget-content ui-corner-all" value="100000"/></td>
</tr>
<tr>
<td><label for="enterlosslimit">Enter Loss limit *</label></td>
<td><input type="text" name="losslimit" id="losslimit" class="text ui-widget-content ui-corner-all" value="200"/></td>
<td>%</td>
</tr>
<tr>
<td><label for="monthIndex">Select Month</label></td>
<td><select id="monthIndex" name="monthIndex" class="text ui-widget-content ui-corner-all">
<option value="0">Current</option>
<option value="1">Next</option>
<option value="2">Far</option>
</select></td>
</tr>
<tr>
<td><label for="strategyType">Select Strategy</label></td>
<td><select id="strategyType" name="strategyType" class="text ui-widget-content ui-corner-all">
<option value="4">All</option>
<option value="0">Neutral</option>
<option value="1">Volatile</option>
<option value="2">Bearish</option>
<option value="3">Bullish</option>
</select></td>
</tr>
<tr>
<td><label for="maxNoLegs">Legs in Strategy</label></td>
<td><select id="maxNoLegs" name="maxNoLegs" class="text ui-widget-content ui-corner-all" >
<option value="4">Upto 4 Legs</option>
<option value="3">Upto 3 Legs</option>
<option value="2">Upto 2 Legs</option>
</select></td>
</tr>
<tr><td><label for="riskReward">Select Risk:Reward</label></td>
<td><input type="text" name="risk" id="risk" class="text ui-widget-content ui-corner-all" size="2"/>:
<input type="text" name="reward" id="reward" class="text ui-widget-content ui-corner-all" size="2"/></td></tr>
<tr><td><label for="ulRangeFrom">Underlying Range :</label></td>
<td><input type="text" name="ulFrom" id="ulFrom" class="text ui-widget-content ui-corner-all rangeClass" size=4/> To
<input type="text" name="ulTo" id="ulTo" class="text ui-widget-content ui-corner-all rangeClass" size=4/></td></tr>
<tr>
<td><label for="expectedROIPerc">Expected Return % p.a.</label></td>
<td><input type="text" name="expectedROIPerc" id="expectedROIPerc" class="text ui-widget-content ui-corner-all" value="11.52" size=4/></td>
</tr>
<tr><td>
<input type="checkbox" id="otm"/><label for="check">OTM and ATM only</label>
</td>
<td><input type="checkbox" id="deltaHedgeReqdd"/><label for="check"> Delta Hedge</label>
</td>
</tr>
<tr>
<td>
<input type="checkbox" id="unlimitedLossCheck"/><label for="check">Disable unlimited loss </label>
</td>
<td>
<input type="checkbox" id="check"/><label for="check">Futures</label>
</td>
</tr>
</table>
</div>
<script>
$("#settingsDialog").dialog({
modal: true,
autoOpen: false,
title: "<strong>Change Setting</strong>",
height: 350,
width: 500,
position: "center",
resizable: true,
draggable: false,
buttons: {
'Continue': function() {
var amount = $("#amount").val();
var losslimit = $("#losslimit").val();
var monthIndex = $("#monthIndex").val();
var type = $("#strategyType").val();
var derivativetype = $("#check").is(':checked');
var underlyingName = $("#underlyingName").val();
//alert("UL " + $("#underlyingList").val() + " " + $("#underlyingList").selected().value());
var risk = $("#risk").val();
var reward = $("#reward").val();
var riskReward = parseFloat(risk)/parseFloat(reward);
var ulFrom = $("#ulFrom").val();
var ulTo = $("#ulTo").val();
var otm = $("#otm").is(':checked');
var expectedROIPerc = $("#expectedROIPerc").val();
var maxNoLegs = $("#maxNoLegs").val();
var unlimitedLoss = $("#unlimitedLossCheck").is(':checked');
var deltaHedgeReqd = $("#deltaHedgeReqdd").is(':checked');
var dataString = '&amount='+ amount+ '&monthIndex=' + monthIndex+'&type='+type+'&derivativetype='+derivativetype+'&losslimit='+losslimit+'&riskReward='+riskReward+'&underlyingName='+underlyingName+'&ulFrom='+ulFrom+'&ulTo='+ulTo+'&otm='+otm+'&expectedROIPerc='+expectedROIPerc+'&maxNoLegs='+maxNoLegs+'&disableUnlimitedLoss='+unlimitedLoss+'&deltaHedgeReqd='+deltaHedgeReqd; //+ '&username=' + username + '&password=' + password + '&monthIndex=' + monthIndex;
if(amount==''|| monthIndex=='' || losslimit=='')// || username=='' || password==''
{
$('.success').fadeOut(500).hide();
$('.error').fadeOut(500).show();
}else{
$.ajax({
type: "post",
url: "bestStrategies",
data: dataString,
success: function(){
$('.success').fadeIn(200).show();
$('.error').fadeOut(200).hide();
$('#gridtable0').setGridParam({datatype:'json'});
$('#gridtable0').trigger( 'reloadGrid' );
}
});
$(this).dialog('close');
}
return false;
},
'Cancel': function() {
$(this).dialog('close');
},
},
});
</script>
</body>
</html>
这是我的BestStrategiesAction映射到提交按钮。
@Action(value = "bestStrategies", results = { @Result(location = "grid.jsp", name = "success") })
public String execute() throws Exception {
log.debug("==============best Strategy invoked :wih url :");
log.info("best Strategy invoked :wih url :");
StrategyService strategyService = strategyServiceFactory.getObject();
user = ((OptionsUser)SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUserr();
user = Userr.findUserr(user.getId());
List<Account> accountList = user.getAccounts();
BrokerageSlab brokerageSlab = user.getBrokerageslab();
log.debug("amount :"+amount+" monthIndex :"+monthIndex+" losslimit :"+losslimit+" nd underlyingName :"+underlyingName);
System.out.println("User name :"+user.getName()+" account id :"+accountList.get(0).getId());
Date date = new Date();
if(amount == ""){
amount = "0";
}
int investingAmount = Integer.parseInt(amount);
int strategyType = Integer.parseInt(type);
int selectedmonth = Integer.parseInt(monthIndex);
boolean derivativeType = Boolean.parseBoolean(derivativetype);
int currentMonth = date.getMonth();
int userlossLimit = Integer.parseInt(losslimit);
double riskRewardRatio = riskReward.equals("NaN")?0:Double.parseDouble(riskReward);
double ulRangeFrom = ulFrom.equals("")?0:Double.parseDouble(ulFrom);
double ulRangeTo = ulTo.equals("")?0:Double.parseDouble(ulTo);
boolean otmSelected = Boolean.parseBoolean(otm);
double expectedROI = expectedROIPerc.equals("")?0:Double.parseDouble(expectedROIPerc);
int maxNoLegsStrategy = maxNoLegs.equals("")?4:Integer.parseInt(maxNoLegs);
boolean isUnlimitedLoss = true;
if(Boolean.parseBoolean(disableUnlimitedLoss))
isUnlimitedLoss = false;
System.out.println("deltaHedgeReque ;;;;;"+deltaHedgeReqd);
boolean deltaHedge = Boolean.parseBoolean(deltaHedgeReqd)?true:false;
System.out.println(" underlying name ::"+underlyingName);
//underlyingList = getUnderlyingValues();
//System.out.println("underlying " + underlyingList.get(0));
//int maxLoss = accountList.get(0).getLossLimit().intValue();
/**
* If condition checks that user is coming for fresh case or overlay case by checking its previous combination.
* Taking positionCombinationArc list here , This list will return all d ex-positions of d user.
* this should b corrected to return only expiry month derviatives of d user.
*/
try{
Set<String> underlyingSet = new LinkedHashSet<String>();
if(accountList!=null && accountList.size() != 0){
List<PositionCombination> combinationsList = accountList.get(0).getAllPositions();
List<PositionCombinationArc> combinationsArc = accountList.get(0).getAllPositionsArc();
Map<String,List<PositionCombination>> combination = new LinkedHashMap<String, List<PositionCombination>>();
if(combinationsList !=null && combinationsList.size()>0){
for(int i=0;i<combinationsList.size();i++){
List<PositionCombination> combinationNewList = new ArrayList<PositionCombination>();
combinationNewList.add(combinationsList.get(i));
List<AbstractPosition> abstractPositions = combinationsList.get(i).getPositions();
AbstractPosition abstractPosition = abstractPositions.get(0);
underlyingSet.add(abstractPosition.getUnderlyingName());
if (combination.containsKey(abstractPosition.getUnderlyingName())) {
List<PositionCombination> combinationCurrentList =combination.get(abstractPosition.getUnderlyingName());
combinationCurrentList.addAll(combinationNewList);
combination.put(abstractPosition.getUnderlyingName(), combinationCurrentList);
}else{
combination.put(abstractPosition.getUnderlyingName(), combinationNewList);
}
}
if(combination.containsKey(underlyingName)){
List<PositionCombination> combinationCurrentList =combination.get(underlyingName);
strategyService.generateQuantReports(underlyingName, currentMonth, brokerageSlab,combinationCurrentList,combinationsArc,strategyType,investingAmount,selectedmonth,derivativeType,userlossLimit,riskRewardRatio,ulRangeFrom, ulRangeTo,otmSelected,expectedROI,maxNoLegsStrategy,isUnlimitedLoss,deltaHedge);
}
else{
strategyService.generateQuantReports(underlyingName, currentMonth, brokerageSlab,strategyType,investingAmount,selectedmonth,derivativeType,userlossLimit,riskRewardRatio,ulRangeFrom, ulRangeTo,otmSelected,expectedROI,maxNoLegsStrategy, isUnlimitedLoss,deltaHedge,underlyingSet);
}
}
else
strategyService.generateQuantReports(underlyingName, currentMonth, brokerageSlab,strategyType,investingAmount,selectedmonth,derivativeType,userlossLimit,riskRewardRatio,ulRangeFrom, ulRangeTo,otmSelected,expectedROI,maxNoLegsStrategy, isUnlimitedLoss,deltaHedge,underlyingSet);
//strategyService.generateQuantReportsGivenLeg(underlyingName, currentMonth, brokerageSlab,strategyType,derivativeType);
}
else{
System.out.println("hiii");
strategyService.generateQuantReports(underlyingName, currentMonth, brokerageSlab,strategyType,investingAmount,selectedmonth,derivativeType,userlossLimit,riskRewardRatio,ulRangeFrom, ulRangeTo,otmSelected,expectedROI,maxNoLegsStrategy, isUnlimitedLoss,deltaHedge,underlyingSet);
//strategyService.generateQuantReportsGivenLeg(underlying, currentMonth, brokerageSlab,strategyType);
//strategyService.generatePremiumQuantReportsPremium(underlying, currentMonth, brokerageSlab);
//generatePremiumPlayQuantReports
}
this.session.put("bestStrategies", strategyService);
this.session.put("userName",user.getName());
System.out.println("Exiting bestStrategies of BestStrategiesAction::");
return SUCCESS;
}
catch(Exception e){
e.printStackTrace();
log.debug("Exception in best strategies " + user.getEmail() + " " + e.getMessage());
return ERROR;
}
}
这是我从行动类
返回的grid.jsp<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
<%--grid.locale-en.js to be loaded before jqGrid js --%>
<%@ page import="com.uforic.optionstrader.domain.*,com.uforic.optionstrader.auth.OptionsUser,org.springframework.security.core.context.SecurityContextHolder"%>
<%Userr user = ((OptionsUser)SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUserr();
user = Userr.findUserr(user.getId());
int userType = user.getUserType();
%>
<script type="text/javascript" src="/OptionsTrader2/struts/i18n/grid.locale-en.js"></script>
<script type="text/javascript" src="/OptionsTrader2/struts/js/plugins/jquery.jqGrid.js"></script>
<link rel="stylesheet" type="text/css" href="/OptionsTrader2/struts/themes/ui.jqgrid.css"/>
<s:url id="remoteurl" value="strategyGrid"/>
<script type="text/javascript">
function resizeJqGrid() {
jQuery("#gridtable0").jqGrid('setGridWidth',$myLayout.state.center.innerWidth - 2 - 35, 'true');
jQuery("#gridtable0").jqGrid('setGridHeight',$myLayout.state.center.innerHeight - 85, 'true');
};
var analyseStrategyUrl = "analyseStrategyAction?"; //@tejas
var selectedS;
var createOrderUrl = "createOrderAction?";
var submitOrderUrl = "submitOrderAction?";
function onStrategySelect(id, status) {
$el = $("#radio3");
$el2 = $("#radio2");
if( $el.is(':checked') ) {
selectedS = 'ivh'+id;
}
else if( $el2.is(':checked') ) {
selectedS = 'grp'+id;
}
else {
var dataFromCellByColumnIndex = jQuery('#gridtable0').jqGrid ('getCell', id,"unName");
selectedS = "sid=stg"+id+"&unName="+dataFromCellByColumnIndex; //tejas
}
function getCreateOrderUrl() {
return createOrderUrl+selectedS;
}
function getSubmitOrderUrl(){
//var quantity = 'qty'+document.getElementById('qty').value;
return submitOrderUrl+selectedS;
}
function showGroupedStrategies() {
jQuery("#gridtable").setGridParam({url: 'groupedStrategyGrid'});
jQuery("#gridtable").trigger("reloadGrid");
}
function showListStrategies() {
alert("show list strategies");
jQuery("#gridtable").setGridParam({url: 'strategyGrid'});
jQuery("#gridtable").trigger("reloadGrid");
}
function showIvonhvStrategies() {
jQuery("#gridtable").setGridParam({url: 'ivonhvGrid'});
jQuery("#gridtable").trigger("reloadGrid");
}
</script>
<div style="height:0px">
<script type="text/javascript">
$("#radio").buttonset();
$('[for=radio1], #radio1').click( function(event) {
showListStrategies();
});
$('[for=radio2], #radio2').click(function(event) {
showGroupedStrategies();
});
$('[for=radio3], #radio3').click(function(event) {
showIvonhvStrategies();
});
</script>
</div>
<table id="gridtable0" style="clear:both;" class="tablesorter"></table>
<script type="text/javascript">
var userType = <%=userType%>;
var isUser = (userType==0)?true:false;
jQuery(document).ready(function () {
jQuery("#gridtable0").jqGrid({
url:'strategyGrid',
datatype: "json",
height: '500',
rownumbers: true,
rowNum: 1000,
cssClass: "ui-layout-content ui-widget-content",
pager: false,
scroll: true,
loadonce: true, // to enable sorting on client side
sortable: true, //to enable sorting
cell:"",
id:'0',
colNames:['Trade', 'Expected Profit % p.a.','Profit Probability','Strategy Type','Max Profit %','Max Loss %','BreakEvenPoint 1', 'BreakEvenPoint 2', 'Investment %','Total Delta','Total Gamma','Total Theta','unName'],
colModel:[
{name:'optionDescription',index:'optionDescription', width:100},
{name:'eplnppa',index:'eplnppa', sorttype:'float', width:50 , hidden: isUser},
{name:'profprob',index:'profprob',sorttype:'float', width:50},
{name:'strategytype',index:'strategytype',sorttype:'text', width:50},
{name:'maxprofit',index:'maxprofit', sorttype:'float', width:50},
{name:'maxloss',index:'maxloss', sorttype:'float', width:50},
{name:'breakUpPoint1',index:'breakUpPoint1', width:50, sorttype:'text'},
{name:'breakUpPoint2',index:'breakUpPoint2', width:50, sorttype:'text'},
{name:'investmentpercentage',index:'investmentpercentage',width:50, hidden: isUser},
{name:'delta',index:'delta',width:50},
{name:'gamma',index:'gamma',width:50},
{name:'theta',index:'theta',width:50},
{name:'unName',index:'unName',width:50},
],
sortname: 'epln',
viewrecords: true,
sortorder: "desc",
onSelectRow: onStrategySelect
});
});
</script>
<script type="text/javascript">
resizeJqGrid();
</script>
这是我的StrategyGrid类
package com.uforic.optionstrader.action;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.interceptor.SessionAware;
import org.json.simple.JSONValue;
import com.opensymphony.xwork2.ActionSupport;
@ParentPackage("layout")
@Namespace("/m")
public class StrategyGrid extends ActionSupport implements SessionAware {
Map session;
StrategyService strategyService;
String gridJson;
@Override
@Action(value = "strategyGrid", results = { @Result(location = "gridJson.jsp", name = "success") })
public String execute() {
System.out.println("Strategy grid action called correctly");
List<QuantReport> quantReports = getStrategies();
this.gridJson = createGridJson(quantReports);
System.out.println(" JSON CREATED :");
return SUCCESS;
}
@Action(value = "groupedStrategyGrid", results = { @Result(location = "gridJson.jsp", name = "success") })
public String executeGroupedStrategyGridJson() {
List<QuantReport> quantReports = getGroupedStrategies();
this.gridJson = createGridJson(quantReports);
return SUCCESS;
}
@Action(value = "ivonhvGrid", results = { @Result(location = "gridJson.jsp", name = "success") })
public String executeIvonhvGridJson() {
List<QuantReport> quantReports = getIvonhvReports();
this.gridJson = createGridJson(quantReports);
return SUCCESS;
}
public List<QuantReport> getStrategies() {
System.out.println("get strategies for current expiry date is called");
List<QuantReport> quantReports = strategyService.getCurrentExpiryQuantReports();
return quantReports;
}
public List<QuantReport> getGroupedStrategies() {
List<QuantReport> quantReports = strategyService.getTopGroupedQuantReports();
return quantReports;
}
public List<QuantReport> getIvonhvReports() {
List<QuantReport> quantReports = strategyService.getIvOnHvQuantReports();
return quantReports;
}
public String createGridJson(List<QuantReport> quantReports) {
DecimalFormat df = new DecimalFormat("#.##");
Map<String, Object> grid = new HashMap<String, Object>();
grid.put("page", "1");
grid.put("total", "1");
grid.put("records", quantReports.size());
List<Map<String, Object>> rows = new ArrayList<Map<String, Object>>();
for(int i=0; i<quantReports.size(); i++) {
CombiQuantReport report = (CombiQuantReport)quantReports.get(i);
Map<String, Object> row = new HashMap<String, Object>();
List<String> cell = new ArrayList<String>();
cell.add(report.getShortOptionDescription());
cell.add(df.format(report.getEPLNPPA().doubleValue()));
cell.add(df.format(report.getProfitProbability().doubleValue()));
int k = report.identifyStrategy();
String type = k == 0 ? "Neutral ": k == 1 ? "Volatile " : k == 2 ? "Bearish" : k == 3 ? "Bullish":"-";
cell.add(type);
String profitPerc = df.format((report.getMaxProfit().doubleValue()/report.getInvestmentAmountWithMargin().doubleValue())*100);
cell.add(profitPerc);
String lossPerc = df.format((report.getMaxLoss().doubleValue()/report.getInvestmentAmountWithMargin().doubleValue())*100);
cell.add(lossPerc);
cell.add(String.valueOf(k==2 && report.getActBreakEvenPoint2().intValue()==0?" ":(report.getBreakEvenSign1()== 0 ? "<":">")+" "+df.format(report.getActBreakEvenPoint1())));
cell.add(String.valueOf(k==2 && report.getActBreakEvenPoint2().intValue()==0? "< "+df.format(report.getActBreakEvenPoint1()):report.getActBreakEvenPoint2().intValue() == 0 ? " " : ((report.getBreakEvenSign2()== 0 ? "<":">")+" "+df.format(report.getActBreakEvenPoint2()))));
cell.add(df.format(report.getInvestmentPercentage()!=null?report.getInvestmentPercentage():BigDecimal.ZERO));//
cell.add(getStrategyDelta(report));
cell.add(getStrategyGamma(report));
cell.add(getStrategyTheta(report));
cell.add(report.getUnderlying());
row.put("id", Integer.toString(i));
row.put("cell", cell);
rows.add(row);
}
grid.put("rows", rows);
return JSONValue.toJSONString(grid);
}
public String getGridJson() {
return this.gridJson;
}
private String getStrategyDelta(CombiQuantReport report){
DerivativeCombination combination = report.getOptionCombination();
int numDerivatives = combination.numDerivatives();
BigDecimal delta = BigDecimal.ZERO;
for(int i=0; i< numDerivatives; i++) {
Derivative der = combination.getDerivative(i);
QuantReport quantRep = report.forecast.getQuantReport(der);
if(quantRep instanceof OptionQuantReport){
OptionQuantReport optionReport = (OptionQuantReport)quantRep;
delta = delta.add(optionReport.getDelta().setScale(4, RoundingMode.HALF_EVEN).multiply(BigDecimal.valueOf(der.getContractSize() * der.getQty())));
}
}
return delta.toString();
}
private String getStrategyGamma(CombiQuantReport report){
DerivativeCombination combination = report.getOptionCombination();
int numDerivatives = combination.numDerivatives();
BigDecimal gamma = BigDecimal.ZERO;
for(int i=0; i< numDerivatives; i++) {
Derivative der = combination.getDerivative(i);
QuantReport quantRep = report.forecast.getQuantReport(der);
if(quantRep instanceof OptionQuantReport){
OptionQuantReport optionReport = (OptionQuantReport)quantRep;
gamma = gamma.add((optionReport.getGamma().setScale(4, RoundingMode.HALF_EVEN).multiply(BigDecimal.valueOf(der.getContractSize()*der.getQty()))));
}
}
return gamma.toString();
}
private String getStrategyTheta(CombiQuantReport report){
DerivativeCombination combination = report.getOptionCombination();
int numDerivatives = combination.numDerivatives();
BigDecimal theta = BigDecimal.ZERO;
for(int i=0; i< numDerivatives; i++) {
Derivative der = combination.getDerivative(i);
QuantReport quantRep = report.forecast.getQuantReport(der);
if(quantRep instanceof OptionQuantReport){
OptionQuantReport optionReport = (OptionQuantReport)quantRep;
theta = theta.add((optionReport.getTheta().setScale(4, RoundingMode.HALF_EVEN).multiply(BigDecimal.valueOf(der.getContractSize()*der.getQty()))));
}
}
return theta.toString();
}
@Override
public void setSession(Map<String, Object> session) {
this.session = session;
this.strategyService = (StrategyService)session.get("bestStrategies");
}
}