0

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:

enter image description here

with Yi the original portfolio returns, π the fund weights and X the fund returns.

Additionally, I defined 3 constraints:

enter image description here

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

Marco87
  • 11
  • 1
  • 1) That looks like a quadratic expression. Don't see you try to do anything quadratic in code. 2) You're using methods that are no longer available in recent versions. Suggest you update to the latest version. 3) Perhaps easier if you think of the objective as having multiple parts – one per day – and build one expression per day/part, then just weigh them together. – apete Nov 03 '22 at 17:34

0 Answers0