If we buy an up-and-out European call and an up-and-in European call, then the following parity should hold good:
The logic is very simple—if the stock price reaches the barrier, then the first call is worthless and the second call will be activated. If the stock price never touches the barrier, the first call will remain active, while the second one is never activated. Either way, one of them is active. The following Python program illustrates such scenarios:
def upCall(s,x,T,r,sigma,nSimulation,barrier): import scipy as sp import p4f n_steps=100 dt=T/n_steps inTotal=0 outTotal=0 for j in range(0, nSimulation): sT=s inStatus=False outStatus=True for i in range(0,int(n_steps)): e=sp.random.normal() sT*=sp.exp((r-0.5*sigma*sigma)*dt+sigma*e*sp.sqrt(dt)) if sT>barrier: outStatus=False inStatus=True if outStatus==True: ...