I have attached below one Mathematica notebook and a MATLAB file where I try to find the \theta which minimizes a function (variance over 1mln data-points).
The MATLAB code runs pretty fast, while the execution of the Mathematica code freezes my machine.
Any suggestions how to make the Mathematica code executable (at least)?
I don’t get any freeze with your code. However, it may run faster if you use the immediate assignment
fVarPut[\[Theta]_?NumberQ] =
Variance[E^(-r T) Ramp[
K - S E^(\[Alpha] T + \[Sigma] Sqrt[
T] (Z + \[Theta]))] E^(-\[Theta] (Z + \[Theta]) + \
\[Theta]^2/2)];
instead of the delayed assignment :=, because with delayed assignment Mathematica has to recalculate the Variance formula every time fVarPut is called.
This will calculate the variance in a symbolic way once; that might be or not be a smart idea depending on the number of points. Definitely not a smart move if n is large, it will do a lot of (comparatively) slow symbolic processing.
Frank Kampas’s solution is a good idea; to turn it into a numeric computation, which is very fast. It will avoid Mathematica trying to do any symbolic manipulation on it.