{"id":8167,"date":"2012-08-20T09:51:05","date_gmt":"2012-08-20T08:51:05","guid":{"rendered":"https:\/\/www.portfolioprobe.com\/?p=8167"},"modified":"2012-08-21T11:00:54","modified_gmt":"2012-08-21T10:00:54","slug":"another-comparison-of-heuristic-optimizers","status":"publish","type":"post","link":"https:\/\/www.portfolioprobe.com\/2012\/08\/20\/another-comparison-of-heuristic-optimizers\/","title":{"rendered":"Another comparison of heuristic optimizers"},"content":{"rendered":"<p>A herd of heuristic algorithms is compared using a portfolio optimization.<\/p>\n<h2>Previously<\/h2>\n<p><a href=\"https:\/\/www.portfolioprobe.com\/2012\/07\/23\/a-comparison-of-some-heuristic-optimization-methods\/\">&#8220;A comparison of some heuristic optimization methods&#8221;<\/a> used two simple and tiny <a href=\"https:\/\/www.portfolioprobe.com\/2012\/01\/05\/the-top-7-portfolio-optimization-problems\/\">portfolio optimization problems<\/a> to compare a number of optimization functions in the <a href=\"https:\/\/www.portfolioprobe.com\/user-area\/some-hints-for-the-r-beginner\/\">R language<\/a>.<\/p>\n<p>This post expands upon that by using a portfolio optimization problem that is of a realistic size (but still with an unrealistic lack of constraints).<\/p>\n<h2>Test case<\/h2>\n<p>The optimization problem is to select 30 assets out of a universe of 474 and find their best weights.\u00a0 The weights must be non-negative and sum to 1.\u00a0 The integer constraint is binding &#8212; more than 30 assets in the portfolio can give a better utility.\u00a0 The utility is mean-variance.<\/p>\n<p>Each optimizer was run 100 times.\u00a0 To have a fair comparison the amount of time that each run took was controlled to be about 1 kilosecond.\u00a0 (There are a couple that also have runs that take much less time.)<\/p>\n<p>The timings are not all particularly close to 1000 seconds, but they are probably all close enough that the picture is minimally distorted.<\/p>\n<p>Besides, the timing (on Windows) seems dodgy.\u00a0 It is supposed to be timing only the compute time (not elapsed time), but the timings don&#8217;t seem to be following a constant plus noise model.\u00a0 Figure 1 shows an example of the timing.<\/p>\n<p>Figure 1: The compute time reported for <code>genopt<\/code> in the order of the runs. <a href=\"https:\/\/www.portfolioprobe.com\/2012\/08\/20\/another-comparison-of-heuristic-optimizers\/genopttime\/\" rel=\"attachment wp-att-8168\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8168\" title=\"genopttime\" src=\"https:\/\/www.portfolioprobe.com\/wp-content\/uploads\/2012\/08\/genopttime.png\" alt=\"\" width=\"512\" height=\"480\" srcset=\"https:\/\/www.portfolioprobe.com\/wp-content\/uploads\/2012\/08\/genopttime.png 512w, https:\/\/www.portfolioprobe.com\/wp-content\/uploads\/2012\/08\/genopttime-250x234.png 250w\" sizes=\"(max-width: 512px) 100vw, 512px\" \/><\/a>The timings are a bit suspect, but should be good enough.<\/p>\n<h2>The optimizers<\/h2>\n<p>Most of the optimizers used in <a href=\"https:\/\/www.portfolioprobe.com\/2012\/07\/23\/a-comparison-of-some-heuristic-optimization-methods\/\">&#8220;A comparison of some heuristic optimization methods&#8221;<\/a> are also used here.\u00a0 The exception is the functions from <code>NMOF<\/code> because they don&#8217;t have explicit box constraints (there is a mechanism for imposing constraints though).\u00a0 The only unconstrained method that was run was the <code>SANN<\/code> method of the <code>optim<\/code> function.<\/p>\n<p>Three methods were added.<\/p>\n<h3>pso package<\/h3>\n<p>The <code>psoptim<\/code> function from <a href=\"http:\/\/cran.r-project.org\/web\/packages\/pso\/index.html\" target=\"_blank\"><code>pso<\/code><\/a> implements a particle swarm algorithm.<\/p>\n<h3>nloptr package<\/h3>\n<p>The Controlled Random Search (CRS) method was done via the <code>nloptr<\/code> function in the <a href=\"http:\/\/cran.r-project.org\/web\/packages\/nloptr\/index.html\" target=\"_blank\"><code>nloptr<\/code> package<\/a>.<\/p>\n<p>This has the unexpected behavior of not respecting default values of arguments in the function to be optimized.\u00a0 You need to specify additional arguments to the function even when they have default values.<\/p>\n<h3>cmaes package<\/h3>\n<p>The Covariance Matrix Adapting Evolutionary Strategy is implemented in the <a href=\"http:\/\/cran.r-project.org\/web\/packages\/cmaes\/index.html\" target=\"_blank\"><code>cmaes<\/code> package<\/a>.<\/p>\n<p>When the version from CRAN (1.0-11) was used on this problem, it got nowhere.\u00a0 The results presented here are from an R-forge version.\u00a0 Apparently the difference is the default values for control variables.\u00a0 Adjusting default values is a work in progress.<\/p>\n<h2>Results<\/h2>\n<p><a href=\"https:\/\/www.portfolioprobe.com\/features\/computing-engine\/\">Portfolio Probe<\/a> consistently gets the same (best) answer in about 3 to 4 seconds.<\/p>\n<p>Figure 2 shows the distribution of deficiencies from the best answer for the methods.<\/p>\n<p>Figure 2: Difference in utility from optimal (ordered by median). <a href=\"https:\/\/www.portfolioprobe.com\/2012\/08\/20\/another-comparison-of-heuristic-optimizers\/lackingall\/\" rel=\"attachment wp-att-8178\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8178\" title=\"lackingall\" src=\"https:\/\/www.portfolioprobe.com\/wp-content\/uploads\/2012\/08\/lackingall.png\" alt=\"\" width=\"512\" height=\"480\" srcset=\"https:\/\/www.portfolioprobe.com\/wp-content\/uploads\/2012\/08\/lackingall.png 512w, https:\/\/www.portfolioprobe.com\/wp-content\/uploads\/2012\/08\/lackingall-250x234.png 250w\" sizes=\"(max-width: 512px) 100vw, 512px\" \/><\/a>The methods &#8220;soma(54)&#8221; and &#8220;psoptim(55)&#8221; are sets of runs where the time was significantly less than 1000 seconds.\u00a0 The number in parentheses is the mean time in seconds for the runs.<\/p>\n<p>Figure 3 has the same information as Figure 2, but the sign of the numbers is changed and the plot is on the logarithmic scale.<\/p>\n<p>Figure 3: Logarithm of negative difference in utility from optimal (ordered by median). <a href=\"https:\/\/www.portfolioprobe.com\/2012\/08\/20\/another-comparison-of-heuristic-optimizers\/lackingalllog-2\/\" rel=\"attachment wp-att-8202\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8202\" title=\"lackingalllog\" src=\"https:\/\/www.portfolioprobe.com\/wp-content\/uploads\/2012\/08\/lackingalllog1.png\" alt=\"\" width=\"512\" height=\"480\" srcset=\"https:\/\/www.portfolioprobe.com\/wp-content\/uploads\/2012\/08\/lackingalllog1.png 512w, https:\/\/www.portfolioprobe.com\/wp-content\/uploads\/2012\/08\/lackingalllog1-250x234.png 250w\" sizes=\"(max-width: 512px) 100vw, 512px\" \/><\/a><\/p>\n<h2>Comments<\/h2>\n<p>Private correspondence with <a href=\"https:\/\/www.portfolioprobe.com\/2011\/10\/27\/introduction-to-numerical-methods-and-optimization-in-finance\/\">Enrico Schumann<\/a> improved this section.<\/p>\n<h3>Defaults<\/h3>\n<p>This is not a comparison of algorithms.\u00a0 This is a comparison of algorithms with their mildly modified default values on <strong>one<\/strong> problem.<\/p>\n<p>The importance of default parameters is evident with <code>cmaes<\/code>.\u00a0 The CRAN set didn&#8217;t even get out of the starting gate.\u00a0 The set that was used didn&#8217;t compare very favorably with the other optimizers.\u00a0 But it seems certain that there is a set of control parameters for it that would do very well.<\/p>\n<h3>Applications matter<\/h3>\n<p>The problem that is being solved has an effect on which algorithms (plus control parameters) work best.\u00a0 There is not a uniformly best algorithm.<\/p>\n<h3>Experimentation is useful<\/h3>\n<p>Experimenting with different algorithms and their settings is likely to pay off if you are doing the same sort of optimization repeatedly.<\/p>\n<h3>What is good enough?<\/h3>\n<p>There is almost always a point at which moving to a more optimal answer is not of practical relevance.\u00a0 That point will of course depend on the actual problem.<\/p>\n<p>&#8220;What is good enough for portfolio optimization?&#8221; is an excellent question that I don&#8217;t think anyone has a good answer to.\u00a0 It does obviously depend on the quality of the inputs &#8212; if the inputs are complete garbage, then it doesn&#8217;t matter how close to optimal you are.\u00a0 (The correct answer in that case is not to trade at all.)<\/p>\n<h3>Clustering<\/h3>\n<p>Both <code>soma<\/code> and <code>psoptim<\/code> (and perhaps others) get relatively good answers within a minute, but then they never seal the deal, so to speak.\u00a0 They don&#8217;t get especially close to the best objective.<\/p>\n<p>You may naively think that the longer runs would be scattered between where they are after a minute and the best solution.<\/p>\n<p>Given:<\/p>\n<ul>\n<li>a problem<\/li>\n<li>an algorithm<\/li>\n<li>its control parameters<\/li>\n<li>the amount of time it runs<\/li>\n<\/ul>\n<p>then there is an expected value for that random process.\u00a0 The <a href=\"http:\/\/en.wikipedia.org\/wiki\/Law_of_large_numbers\" target=\"blank\">Law of Large Numbers<\/a> says that the actual result for any run is likely to be close to the expected value. That is the clustering we are seeing.<\/p>\n<h3>One star<\/h3>\n<p>There is one algorithm (besides Portfolio Probe) that has done well in all of the problems in this and the previous comparison: <code>GenSA<\/code>.<\/p>\n<p>We don&#8217;t know how specific that is to the problems posed and its default parameters.\u00a0 But it seems worth keeping an eye on it.<\/p>\n<h2>Appendix R<\/h2>\n<p>The functions and data to reproduce this analysis are in <a href=\"https:\/\/www.portfolioprobe.com\/R\/blog\/heuristic_objs2.R\" target=\"_blank\">heuristic_objs2.R<\/a> (4 MB). The utility that Portfolio Probe achieves is -0.35776787228876. The non-zero optimal weights (to six decimal places) are in <a href=\"https:\/\/www.portfolioprobe.com\/R\/blog\/optimalWeightsAll.csv\" target=\"_blank\">optimalWeightsAll.csv<\/a>.<\/p>\n<p>In case you want to test routines on these problems outside R: the variance is in <a href=\"https:\/\/www.portfolioprobe.com\/R\/blog\/varianceall.csv\" target=\"_blank\">varianceall.csv<\/a> (4 MB) and the expected return vector is in <a href=\"https:\/\/www.portfolioprobe.com\/R\/blog\/expectedreturnsall.csv\" target=\"_blank\">expectedreturnsall.csv<\/a>.<\/p>\n<p>&nbsp;<\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>A herd of heuristic algorithms is compared using a portfolio optimization. Previously &#8220;A comparison of some heuristic optimization methods&#8221; used two simple and tiny portfolio optimization problems to compare a number of optimization functions in the R language. This post expands upon that by using a portfolio optimization problem that is of a realistic size &hellip; <a href=\"https:\/\/www.portfolioprobe.com\/2012\/08\/20\/another-comparison-of-heuristic-optimizers\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46,6],"tags":[262,170,263,260],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.portfolioprobe.com\/wp-json\/wp\/v2\/posts\/8167"}],"collection":[{"href":"https:\/\/www.portfolioprobe.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.portfolioprobe.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.portfolioprobe.com\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.portfolioprobe.com\/wp-json\/wp\/v2\/comments?post=8167"}],"version-history":[{"count":0,"href":"https:\/\/www.portfolioprobe.com\/wp-json\/wp\/v2\/posts\/8167\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.portfolioprobe.com\/wp-json\/wp\/v2\/media?parent=8167"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.portfolioprobe.com\/wp-json\/wp\/v2\/categories?post=8167"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.portfolioprobe.com\/wp-json\/wp\/v2\/tags?post=8167"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}