} else { // it is being used as control variate
runningLog = 1.0;
pastFixings = 0;
}
final Date referenceDate = process.riskFreeRate().currentLink().referenceDate();
final DayCounter rfdc = process.riskFreeRate().currentLink().dayCounter();
final DayCounter divdc = process.dividendYield().currentLink().dayCounter();
final DayCounter voldc = process.blackVolatility().currentLink().dayCounter();
// TODO: consider double[] instead
final List<Double> fixingTimes = new ArrayList<Double>();
/*@Size*/ int i;
for (i=0; i<a.fixingDates.size(); i++) {
if (a.fixingDates.get(i).ge(referenceDate)) {
/*@Time*/ final double t = voldc.yearFraction(referenceDate,
a.fixingDates.get(i));
fixingTimes.add(Double.valueOf(t));
}
}
/*@Size*/ final int remainingFixings = fixingTimes.size();
/*@Size*/ final int numberOfFixings = pastFixings + remainingFixings;
/*@Real*/ final double N = numberOfFixings;
/*@Real*/ final double pastWeight = pastFixings/N;
/*@Real*/ final double futureWeight = 1.0-pastWeight;
double timeSum = 0.0;
for (int k=0; k<fixingTimes.size(); k++) {
timeSum += fixingTimes.get(k);
}
/*@Volatility*/ final double vola = process.blackVolatility().currentLink().blackVol(a.exercise.lastDate(), payoff.strike());
/*@Real*/ double temp = 0.0;
for (i=pastFixings+1; i<numberOfFixings; i++) {
temp += fixingTimes.get(i-pastFixings-1)*(N-i);
}
/*@Real*/ final double variance = vola*vola /N/N * (timeSum+ 2.0*temp);
/*@Real*/ final double dsigG_dsig = Math.sqrt((timeSum + 2.0*temp))/N;
/*@Real*/ final double sigG = vola * dsigG_dsig;
/*@Real*/ final double dmuG_dsig = -(vola * timeSum)/N;
final Date exDate = a.exercise.lastDate();
/*@Rate*/ final double dividendRate = process.dividendYield().currentLink().
zeroRate(exDate, divdc, Compounding.Continuous, Frequency.NoFrequency).rate();
/*@Rate*/ final double riskFreeRate = process.riskFreeRate().currentLink().
zeroRate(exDate, rfdc, Compounding.Continuous, Frequency.NoFrequency).rate();
/*@Rate*/ final double nu = riskFreeRate - dividendRate - 0.5*vola*vola;