function dPi = deltaPi_vs_lambda(lambda, D,G,Dstar,Gstar,C,min_deltaS,max_deltaS) % % lambda = the amount of the hedge instrument to % D = total Delta of instruments depending on the underlying with price S % G = total Gamma of instruments depending on the underlying with price S % Dstar = Delta of the hedge instrument % Gstar = Gamma of the hedge instrument % C = cost to buy/sell (trade) one unit of the the hedge instrument % min_deltaS = smallest move in the underlying % max_deltaS = largest most in the underlying % % Written by: % -- % John L. Weatherwax 2006-12-31 % % email: wax@alum.mit.edu % % Please send comments and especially bug reports to the % above email address. % %----- dp = D + lambda * Dstar; gp = G + lambda * Gstar; deltaS_worst = - dp/gp; if( (deltaS_worst < min_deltaS) || (deltaS_worst > max_deltaS) ) % we are outside of the allowable range v = min( min_deltaS * dp + 0.5 * ( min_deltaS^2 ) * gp, max_deltaS * dp + 0.5 * ( max_deltaS^2 ) * gp ); else % we are inside of the allowable range v = - ( dp^2 / ( 2 * gp ) ); end dPi = v - abs(lambda) * C;