commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From enzhong...@pnc.com
Subject Re: [math] BOBYQAOptimizer hang
Date Wed, 18 Dec 2013 22:14:17 GMT
The email dropped the attached file. Here is the test case code, we use 
commons-math3-3.2.

Andrew


import org.apache.commons.math3.analysis.MultivariateFunction;
import org.apache.commons.math3.distribution.NormalDistribution;
import org.apache.commons.math3.optim.InitialGuess;
import org.apache.commons.math3.optim.MaxEval;
import org.apache.commons.math3.optim.OptimizationData;
import org.apache.commons.math3.optim.PointValuePair;
import org.apache.commons.math3.optim.SimpleBounds;
import org.apache.commons.math3.optim.nonlinear.scalar.GoalType;
import org.apache.commons.math3.optim.nonlinear.scalar.ObjectiveFunction;
import 
org.apache.commons.math3.optim.nonlinear.scalar.noderiv.BOBYQAOptimizer;
import org.junit.Test;

public class BOBYQAOptimizerTest {
        @Test
        public void test1() {
                double[] x = new double[]{0.37215286535894443, 
0.4648383826282711, 0.5806074387095237, 0.7252090414280923, 
0.9058240020796098, 1.13142152933966, 1.413204633697474, 
1.7651664608765416, 2.204785181358541};
                double[] y = new double[]{-0.03858, -0.10265, -0.29995, 
-0.94505, -3.13887, -10.66503, -35.8148, -114.73309, -339.44331};

                double[] lower = new double[3];
                double[] upper = new double[3];
                double t1 = -511.14797785141417;        //t1 is used to 
transform the SwaptionBS function
                lower[0] = -10.0*Math.abs(t1);
                upper[0] = -lower[0];
                lower[1] = 0.02;
                upper[1] = 100.0;
                lower[2] = 0.02;
                upper[2] = 8.0;
 
                double[] p = new double[]{1.0, 1.0, 0.2995887592309402};
 
                LS ls = new LS(x,y, 1, -511.14797785141417);
                OptimizationData[] parm = new OptimizationData[]{new 
MaxEval(50000), new ObjectiveFunction(ls),
                                GoalType.MINIMIZE,      new 
InitialGuess(p), new SimpleBounds(lower, upper)};
 
                BOBYQAOptimizer op = new BOBYQAOptimizer(10);
                PointValuePair po = op.optimize(parm);
        }
 
        public static void main(String[] args) {
                BOBYQAOptimizerTest t = new BOBYQAOptimizerTest();
                t.test1();
        }
}

class LS implements MultivariateFunction {
        private BS bs = new BS();
        private double[] x;
        private double[] y;
        private double const1;
        private int optionType;

        public LS(double[] x, double[] y, int optionType, double const1) {
                this.x = x;
                this.y = y;
                this.optionType = optionType;
                this.const1 = const1;
        }

        @Override
        public double value(double point[]) {
                int len = x.length;
                double val = 0;
                for (int i=0; i<len; i++) {
                        double yc = bs.f2(x[i], point[0]*const1, point[1], 
point[2], optionType); 
                        val += Math.pow(yc-y[i], 2);
                }
                return val;
        }
 
}

class BS {
        public double blackScholes(double price, double strike, double 
time, double vol, int optionType) {
            double volrootime = Math.pow(time, 0.5) * vol;
            double topline1 = Math.log(price/strike);
            double topline2 = Math.pow(vol, 2)/2* time;
            double topline = topline1 + topline2;
            double d1 = topline / volrootime;
            double d2 = d1 - volrootime;
 
            double val = 0.0;
            NormalDistribution normal = new NormalDistribution();
            if (optionType==1)
                val = (price * normal.cumulativeProbability(d1) - strike * 
normal.cumulativeProbability(d2));
            else
                val = (strike * normal.cumulativeProbability(-d2) - price 
* normal.cumulativeProbability(-d1));
 
            return val;
        }

        public double f2(double x, double ah, double ai, double aj, int 
ak) {
                return ah*bScore(x, ai, aj, ak);
        }
 
        public double bScore(double price, double strike, double vol, int 
optionType) {
                return blackScholes(price, strike, 1, vol, optionType);
        }
}



From:
enzhong.fu@pnc.com
To:
"Commons Users List" <user@commons.apache.org>
Date:
12/18/2013 12:59 PM
Subject:
[math] BOBYQAOptimizer hang



I ran into a case that BOBYQAOptimizer hang in line 485. trsbox is pretty 
complex method and I'm not familiar with the algorithm. It seems going 
into infinite loop between different states. 

            final double[] dsqCrvmin = trsbox(delta, gnew, xbdi, s, 
                                              hs, hred); 

Here is the test case for it. After reducing the value to <2.24 it hang in 
trsbox method without progress. 


Can someone shed light on what might be happening, and how to deal with 
it? Thanks. 


Andrew 


The contents of this email are the property of PNC. If it was not 
addressed to you, you have no legal right to read it. If you think you 
received it in error, please notify the sender. Do not forward or copy 
without permission of the sender. This message may contain an 
advertisement of a product or service and thus may constitute a commercial 
electronic mail message under US Law. The postal address for PNC is 249 
Fifth Avenue, Pittsburgh, PA 15222. If you do not wish to receive any 
additional advertising or promotional messages from PNC at this e-mail 
address, click here to unsubscribe. 
https://pnc.p.delivery.net/m/u/pnc/uni/p.asp 
By unsubscribing to this message, you will be unsubscribed from all 
advertising or promotional messages from PNC. Removing your e-mail address 
from this mailing list will not affect your subscription to alerts, 
e-newsletters or account servicing e-mails.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org



The contents of this email are the property of PNC. If it was not addressed to you, you have
no legal right to read it. If you think you received it in error, please notify the sender.
Do not forward or copy without permission of the sender. This message may contain an advertisement
of a product or service and thus may constitute a commercial electronic mail message under
US Law. The postal address for PNC is 249 Fifth Avenue, Pittsburgh, PA 15222. If you do not
wish to receive any additional advertising or promotional messages from PNC at this e-mail
address, click here to unsubscribe. https://pnc.p.delivery.net/m/u/pnc/uni/p.asp 
By unsubscribing to this message, you will be unsubscribed from all advertising or promotional
messages from PNC. Removing your e-mail address from this mailing list will not affect your
subscription to alerts, e-newsletters or account servicing e-mails.



Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message