Repository navigation
Conversation
|
I checked the new formula against the old one outside the library (numpy and scipy, same expressions as the diff,
So the two agree to the last digit or two where the old one is finite, and the new one stays finite where One edge I would add a test for: a zero-row input. |
|
Hi @galafis, I am going to reject this pull request, as all the errors occur in scenarios that are not realistic. It is actually a good thing that the function failed when faced with a returns vector that do not correspond to reality. If there is a 100% loss (Not possible in finance), all returns are the same, or a sample is too small, the problem is the data. Please read about financial theory before submitting a pull request. Best, |
Entropic_RM and the _Entropic_RM objective used by EVaR_Hist compute log(mean(exp(-X/z))) directly. Valid finite inputs overflow or underflow when |X/z| is large: a constant return of -1 at z=.001 produces infinity instead of the finite result 1-.001*log(.05). Positive constant returns underflow to zero inside the logarithm.
Evaluate the same expression with scipy.special.logsumexp, subtracting log(T) and log(alpha), in both paths. No risk-measure definition or optimizer choice changes.
Eight regression cases cover positive/negative constants, mixed returns and ordinary values in the public function and optimizer callback. Constant and mixed-case expectations use independent closed forms. Before: six fail on overflow or log(0), two ordinary controls pass. After: eight pass. git diff --check passes.
Related historical report: #51; the failure is reproducible on current NumPy 2.5.4/SciPy 1.18.1, Python 3.12.14. SciPy documents logsumexp as the numerically stable log of a sum of exponentials: https://docs.scipy.org/doc/scipy/reference/generated/scipy.special.logsumexp.html .
Validation uses current Python source plus the same-version 7.4.0 wheel's compiled extension and generated version metadata. The full optimizer/golden-file suite was not run.