Optimize the units of a second option in portfolio when jump occurs in python

36 Views Asked by At

I'm trying to optimize the units for the second option when a jump occurs, but I'm not able to face this stuff in python (or any other code). As you already know, I've this inital situation:

\Pi[:,0] = C(0,K,s0) - (initial delta of first call + units of gamma * (initial delta of second option))* S[:,0] - gamma units * the second option

But I don't know how minimize the units of gamma in a for loop.

The algoritm of portfolio with only call option and underlying is:

C = lambda t,K,S0: BS_Call_Put_Option_Price(CP,S0,K,sigma,t,T,r)

Delta = lambda t,K,S0: BS_Delta(CP,S0,K,sigma,t,T,r)



# Setting up initial portfolio



PnL = np.zeros([NoOfPaths,NoOfSteps+1])

delta_init= Delta(0.0,K,s0)

PnL[:,0] = C(0.0,K,s0) - (delta_init+gamma_unit*delta_initOpt2) * s0 - gamma_unit* COpt2(0.0,K,s0)



CallM      = np.zeros([NoOfPaths,NoOfSteps+1])

CallM[:,0] = C(0.0,K,s0)

DeltaM     = np.zeros([NoOfPaths,NoOfSteps+1])

DeltaM[:,0] = Delta(0,K,s0)



for i in range(1,NoOfSteps+1):

    dt = time[i] - time[i-1]

    delta_old  = Delta(time[i-1],K,S[:,i-1])

    delta_curr = Delta(time[i],K,S[:,i])



    PnL[:,i] =  PnL[:,i-1]*np.exp(r*dt) - (delta_curr-delta_old + delta_currOpt2*gamma_curr-delta_oldOpt2)*S[:,i] - (gamma_curr-gamma_old)*CallMOpt2 # PnL

    CallM[:,i] = C(time[i],K,S[:,i])

    DeltaM[:,i]   =Delta(time[i],K,S[:,i])



# Final transaction, payment of the option (if in the money) and selling the hedge



PnL[:,-1] = PnL[:,-1] -np.maximum(S[:,-1]-K,0) +  (DeltaM[:,-1]+ DeltaMOpt2[:,-1]*GammaM[:,-1])*S[:,-1] + GammaM[:,-1]*np.maximum(S[:,-1]-K,0)

But when I want to hedge my position against the new source of risk added by jump, according to ch. 14 of "Volatility and Correlation" written by Rebonato, I've to include a new option, but I'm not able to minimize the gamma units in for...loop

C = lambda t,K,S0: BS_Call_Put_Option_Price(CP,S0,K,sigma,t,T,r)

Delta = lambda t,K,S0: BS_Delta(CP,S0,K,sigma,t,T,r)



# Setting up initial portfolio



PnL = np.zeros([NoOfPaths,NoOfSteps+1])

delta_init= Delta(0.0,K,s0)

PnL[:,0] = C(0.0,K,s0) - (delta_init+gamma_unit*delta_initOpt2) * s0 - gamma_unit* COpt2(0.0,K,s0)



CallM      = np.zeros([NoOfPaths,NoOfSteps+1])

CallM[:,0] = C(0.0,K,s0)

DeltaM     = np.zeros([NoOfPaths,NoOfSteps+1])

DeltaM[:,0] = Delta(0,K,s0)



for i in range(1,NoOfSteps+1):

    dt = time[i] - time[i-1]

    delta_old  = Delta(time[i-1],K,S[:,i-1])

    delta_curr = Delta(time[i],K,S[:,i])



    PnL[:,i] =  PnL[:,i-1]*np.exp(r*dt) - (delta_curr-delta_old + delta_currOpt2*gamma_curr-delta_oldOpt2)*S[:,i] - (gamma_curr-gamma_old)*CallMOpt2 # PnL

    CallM[:,i] = C(time[i],K,S[:,i])

    DeltaM[:,i]   =Delta(time[i],K,S[:,i])



# Final transaction, payment of the option (if in the money) and selling the hedge



PnL[:,-1] = PnL[:,-1] -np.maximum(S[:,-1]-K,0) +  (DeltaM[:,-1]+ DeltaMOpt2[:,-1]*GammaM[:,-1])*S[:,-1] + GammaM[:,-1]*np.maximum(S[:,-1]-K,0)
0

There are 0 best solutions below