FxBarrierOption scenario pricing
In BlackBarrierPriceFormulaRepository there are some conditions on spot vs barrier level relation, namely
ArgChecker.isFalse(isDown && spot <= barrier.getBarrierLevel(), "The Data is not consistent with an alive barrier (DOWN and spot<=barrier).");
ArgChecker.isFalse(!isDown && spot >= barrier.getBarrierLevel(),"The Data is not consistent with an alive barrier (UP and spot>=barrier).");
However, when pricing using scenario framework, I'd like to shift fx spot value, which might lead to shifted spot breaching a barrier (for example resulting in zero value in case of knock out). Instead a get a Failure result, which is unexpected.
For future reference, our primary channel for user questions is our forum.
Are you looking to just remove these two lines of validation?
If the barrier is Knock-Out than option value is 0, if barrier is Knock-In than option value is equals to value of vanilla option.
These validations should be replaced by following code
if( (isDown && spot <= barrier.getBarrierLevel()) || (!isDown && spot >= barrier.getBarrierLevel())){
if(isKnockIn){
double df1 = Math.exp((costOfCarry-rate)*timeToExpiry);
double df2 = Math.exp(-rate*timeToExpiry);
double forward = spot*df1/df2;
return BlackFormulaRepository.price(forward, strike, timeToExpiry, lognormalVol, isCall);
}else{
return 0d;
}
}
so that the following additional test in BlackBarrierPriceFormulaRepositoryTest passes
public void barrierBreached(){
double newSpot = 120;
double callUpOut = BARRIER_PRICER.price(
newSpot, STRIKE_MID, EXPIRY_TIME, COST_OF_CARRY, RATE_DOM, VOLATILITY, true, BARRIER_UP_OUT);
assertEquals(callUpOut, 0d);
double newForward = newSpot * DF_FOR / DF_DOM;
double callUpIn = BARRIER_PRICER.price(
newSpot, STRIKE_MID, EXPIRY_TIME, COST_OF_CARRY, RATE_DOM, VOLATILITY, true, BARRIER_UP_IN);
double callVanilla = BlackFormulaRepository.price(newForward, STRIKE_MID, EXPIRY_TIME, VOLATILITY, true) ;
assertEquals(callUpIn, callVanilla);
}
The equivalent handling can be implemented in BlackFxSingleBarrierOptionProductPricer keeping the formula repositories purely mathematics.