function diff_IV = objfun(Data, Spot, r, T, params, model, JT)
% Calibration on implied volatilities
m = Data(:,4);  % log-moneyness
Put = Data(m<0,:);
Call = Data(m>=0,:);

% Price computation with the COS method
CallPrices = COSmethod(Call(:,2),params,r,Spot,T,model, JT);
[~,PutPrices] = COSmethod(Put(:,2),params,r,Spot,T,model, JT);
Call(:,1) = CallPrices;
Put(:,1) = PutPrices;

% Model implied volatilities, flag = 1 for calls, flag = -1 for puts
IV_Call = IV_BS(Call,Spot,r,T,1);
IV_Put = IV_BS(Put,Spot,r,T,-1);

% Differences between market and model implied volatilities
diff_Call = IV_Call-Call(:,5);
diff_Put = IV_Put-Put(:,5);
diff_IV = [diff_Put; diff_Call];

end
