How to make some parameters in a function take multiple numbers and return the lowest value

I have the following Function:

Double.Historical.Sim.Var <- function(d1, wa=0.75, wb=0.25, pv=1000, cl=0.95) 
   {
   x <- pv
   w <- c(wa,wb)
   Pw <- -pv*w
   loss <- rowSums(t(Pw * t(d1)))
   result <- quantile(loss,0.95)
   return(result)
  }

I need a way for the function to take Wa from 0.01 to 1 with wb being (1-wa)
#and to tell me with which combination of wa and wb the value of this #function is the lowest.

Thanks in advance for any help !!

Can you provide some additional information on your function? For example, what is d1? Is it a vector, a matrix, a data frame? When you calculate loss, are you trying to do matrix multiplication, or did you really want to do standard multiplication? If you use the default arguments of the function and choose a specific d1, what do you expect the value of loss to be before running the quantile function?

For now, note that you don't need to have a separate argument for wb. You can remove the first two lines of the function and just do Pw <- -pv*c(wa, 1 - wa).

D1 is a dataframe of 2 columns, each columns is a stock returns over the years, the idea of the function is to calculate the value at risk of the portfolio and i need to find the weights to invest on each asset for the value at risk to be the minimum

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.