Greedy Search
Greedy Search
greedySearch(OF, algo, ...)
OF |
The objective function, to be minimised. Its first
argument needs to be a solution; |
algo |
List of settings. See Details. |
... |
Other variables to be passed to the objective function and to the neighbourhood function. See Details. |
A greedy search works starts at a provided initial solution (called the current solution) and searches a defined neighbourhood for the best possible solution. If this best neighbour is not better than the current solution, the search stops. Otherwise, the best neighbour becomes the current solution, and the search is repeated.
A list:
|
best solution found. |
|
objective function value associated with best solution. |
|
a matrix with two
columns. |
|
a list |
|
the value of
|
|
the initial solution |
|
the number of iterations after which the search stopped |
Enrico Schumann
Gilli, M., Maringer, D. and Schumann, E. (2019) Numerical Methods and Optimization in Finance. 2nd edition. Elsevier. https://www.elsevier.com/books/numerical-methods-and-optimization-in-finance/gilli/978-0-12-815065-8
Schumann, E. (2019) Financial Optimisation with R (NMOF Manual). http://enricoschumann.net/NMOF.htm#NMOFmanual
LSopt
na <- 100 inc <- 5 R <- randomReturns(na = na, ns = 1000, sd = seq(0.01, 0.02, length.out = 100), rho = 0.5) S <- cov(R) OF <- function(x, S, ...) { w <- 1/sum(x) sum(w * w * S[x, x]) } x <- logical(na) x[1:inc] <- TRUE all.neighbours <- function(x, ...) { true <- which( x) false <- which(!x) ans <- list() for (i in true) { for (j in false) { ans1 <- x ans1[i] <- !x[i] ans1[j] <- !x[j] ans <- c(ans, list(ans1)) } } ans } algo <- list(loopOF = TRUE, maxit = 1000, all.neighbours = all.neighbours, x0 = x) system.time(sol.gs <- greedySearch(OF, algo = algo, S = S)) sqrt(sol.gs$OFvalue)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.