Displaying 3 results from an estimated 3 matches for "w_2".
Did you mean:
w2
2011 Oct 03
1
Matrix/Vector manipulation
...e/volume (v). Now I recurse into the vector (from left to right) with what you have left from the difference of volume minus current weight, and stop when the difference is less than or equal to the current weight.
Vectors W and R have the same length, and v is always a positive integer.
W: {w_1 w_2 .. w_m}
R: {r_1 r_2 .. r_m}
my_cumsum <- function(v, R, W) {
if (v <= W[1]) # check the head
v*R[1]
else
W[1]*R[1] + my_cumsum(v - W[1], R[2:length(R)], W[2:length(W)]) # recurse the tail
}
Any help is greatly appreciated!
Fernando Alvarez
"Great ideas originate in the muscles....
2012 Jul 18
4
The best solver for non-smooth functions?
...rating)
}
# The linear constraints
constr <- function(w) {
sum(w)
}
# Results' matrix (it's empty by now)
Results <- matrix(NA, nrow = 3, ncol = 4)
rownames(Results) <- list('donlp2', 'solnp', 'solnp2')
colnames(Results) <- list('w_1', 'w_2', 'w_3', 'Sharpe')
# See the differences between different solvers
rho
Results[1,1:3] <- round(donlp2(fn = sharpe, par = rep(1/N,N), par.lower =
rep(0,N), par.upper = rep(1,N), A = t(rep(1,N)), lin.lower = 1, lin.upper =
1)$par, 2)
Results[2,1:3] <- round(solnp(pars = re...
2002 Feb 06
4
Weighted median
Is there a weighted median function out there similar to weighted.mean()
but for medians? If not, I'll try implement or port it myself.
The need for a weighted median came from the following optimization
problem:
x* = arg_x min (a|x| + sum_{k=1}^n |x - b_k|)
where
a : is a *positive* real scalar
x : is a real scalar
n : is an integer
b_k: are negative and positive scalars