I have a dataset of daily prices for a portfolio (I do not have details about the constituents, simply the total daily price). My goal is to select n funds from a pool of funds and create a new portfolio with daily returns as close as possible compared to the original portfolio. I came up with the following formula to describe the problem:
with Yi the original portfolio returns, π the fund weights and X the fund returns.
Additionally, I defined 3 constraints:
To solve this I need to use ojAlgo. I tried the following but I almost instantly got stuck because of 2 issues.
public static void main(String[] [] args){
ExpressionsBasedModel model = new ExpressionsBasedModel();
float[] x1 = getDailyReturns("fund1");
float[] x2 = getDailyReturns("fund2");
float[] x3 = getDailyReturns("fund3");
Variable pi1 = new Variable("pi1");
Variable pi2 = new Variable("pi2");
Variable pi3 = new Variable("pi3");
List<Variable> variables = Arrays.asList(w1, w2, w3);
model.addVariables(variables);
Expression expr = model.addExpression("objective");
expr.setLinearFactor(pi1, x1);
expr.setLinearFactor(pi2, x2);
expr.setLinearFactor(pi3, x3);
expr.weight(1.0);
Optimisation.Result result = model.minimise();
}
First of all, I have X as a vector while .setLinearFactor can only use Number. Secondly I obviously missed something on how I should define the Expression.
Do you know where I could find examples helping me understanding how I am supposed to use the ExpressionBasedModel() for my problem?
Thank you