Second derivative - passing from linear to non-linear formula

Hi guys!

I am interested about passing from this linear function created below, to a non-linear one, in order to estimate the second derivative. Is there exist some trick that I can use to have the second derivative different from zero? I am trying to estimate a greek called “Gamma” for a Call Option, that is priced using Montecarlo method

import torch as np
values = torch.tensor([1., 1.1, 1.2], requires_grad=True)

def delta_gamma(xi):

    k,T,j,sigma = 1.5,1.,10000,0.5  

    S = np.broadcast_to(xi,(j,) + xi.shape).T    

    mean = -.5 * sigma * sigma * T

    volatility = sigma

    BM = torch.randn(1, j)*volatility+mean   

    product = S*np.exp(BM)   

    p = torch.maximum(product-k,torch.zeros_like(product))   

    result = torch.mean(p, 1)

    return result

for i in values: