Intro

The Omega Point Optimization API is setup to fulfill a variety of objectives, including the mean-variance optimization. This optimization finds an ideal asset allocation that considers the trade-off between risk and return. By sending in your expected forecasts, then you can achieve a more optimal risk-adjusted return.

To perform this optimization, you should have already read the Optimization API: Getting Started guide.

Mean-Variance Optimization: Input

Mean-Variance is achieved by focusing on a utility function that minimizes total risk while taking into account your expected returns. With the Optimization API, it's just a matter of sending the proper parameters to receive a result that reduces your total risk, given your expected returns. Below are the steps required to perform a mean-variance optimization:

First, begin by setting the objective to the following:

{ "minimizeTotalRisk": true }

Alongside the objective, you'll also send in a forecast list. The forecast list includes a list of equities with their expected return (%), and a time horizon (in number of trading days). This is passed to the API in the following format:

{
  "horizon": 20,
  "equities": [{
    "id": { "ticker": "MSFT", "mic": "XNAS" },
    "expectedPercentReturn": 0.12
  }, {
    "id": { "ticker": "TSLA", "mic": "XNAS" },
    "expectedPercentReturn": 0.275
  }]
}

Now you are ready to send a query to the optimization API endpoint. The following query is set up to return risk characteristics of the optimized portfolio and the positionDeltas required to achieve the optimized portfolio.

Query

query (
  $model: String!
  $positionSet: PositionSetInput!
  $objective: [OptimizationObjective]!
  $constraints: OptimizationConstraints!
  $forecast: ForecastInput
){
  model(id: $model){
    optimization(positionSet: $positionSet, objective: $objective, constraints: $constraints, forecast: $forecast){
      exposure {
        date
        factors(id: "Software"){
          id
          net
        }
      }
      positionsDelta {
        date
        equities {
          id {
            ticker
            mic
          }
          economicExposure
        }
      }
    }
  }
}


Variables

The query variables below include the structure to pass in values for the model, objective, constraints, forecast, & positionSet parameters.

Note: Update the "model" variable below with an appropriate model ID value.
Note: The constraints parameter is set to an empty object, { } , for now. This parameter will be explored and filled in later, but an empty constraints object is necessary.

{
  "model": "xxxxx-xx",
  "objective": [{ "minimizeTotalRisk": true }],
  "constraints": {},
  "forecast": {
    "horizon": 20,
    "equities": [{
      "id": { "ticker": "MSFT", "mic": "XNAS" },
      "expectedPercentReturn": 0.12
    }, {
      "id": { "ticker": "TSLA", "mic": "XNAS" },
      "expectedPercentReturn": 0.275
    }]
  },
  "positionSet": {
    "dates": [
      {
        "date": "2017-06-30",
        "equities": [
          {
            "economicExposure": 100000,
            "id": { "ticker": "MSFT", "mic": "XNAS" }
          },
          {
            "economicExposure": 200000,
            "id": { "ticker": "TSLA", "mic": "XNAS" }
          }
        ]
      }
    ]
  }
}

Mean Variance Optimization: Output

Submitting this query with the associated query variables, the optimizer returns this JSON structure that mimics the original query structure:

{
  "data": {
    "model": {
      "optimization": {
        "exposure": [
          {
            "date": "2017-06-30",
            "factors": [
              {
                "id": "Software",
                "net": 0.41927898
              }
            ]
          }
        ],
        "positionsDelta": [
          {
            "date": "2017-06-30",
            "equities": [
              {
                "id": {
                  "ticker": "MSFT",
                  "mic": "XNAS"
                },
                "economicExposure": 159708.67037729573
              },
              {
                "id": {
                  "ticker": "TSLA",
                  "mic": "XNAS"
                },
                "economicExposure": -159708.67037729593
              }
            ]
          }
        ]
      }
    }
  }
}

Two things register after receiving this result: 

  1. The optimizer trades out of TSLA, but your conviction in TSLA remains high (especially considering a higher expected return), so you would rather keep your position size within an acceptable range. 
  2. Although this optimization favors trading into MSFT in order to minimize total risk, notice that your exposure to Software increased from .33 to .42.  (Note: The current Software exposure z-score was determined by running a Simulation query against the API.)

Setting Up Constraints

You'd like to maintain your current exposure level and provide a position size range; the optimization allows additional constraints to be passed in to achieve these targets. The original query variable is modified to include the following 1) security target and 2) exposure constraints:

...
  "constraints": {
    "securities": {
      "equities": [{
        "id": { "ticker": "TSLA", "mic": "XNAS" },
        "minEconomicExposure": 150000,
        "maxEconomicExposure": 250000
      }]
    },
    "exposure": [{
      "id": "Software",
      "max": 0.40,
      "min": 0.30
    }],
  }
...

Note: A full list of constraints is available in the Optimization GraphQL Parameters article.

By passing in these constraints, you will receive a new optimization that satisfies these requirements. The updated output returns:

{
  "data": {
    "model": {
      "optimization": {
        "exposure": [
          {
            "date": "2017-06-30",
            "factors": [
              {
                "id": "Software",
                "net": 0.3529412
              }
            ]
          }
        ],
        "positionsDelta": [
          {
            "date": "2017-06-30",
            "equities": [
              {
                "id": {
                  "ticker": "MSFT",
                  "mic": "XNAS"
                },
                "economicExposure": 20000
              },
              {
                "id": {
                  "ticker": "TSLA",
                  "mic": "XNAS"
                },
                "economicExposure": -20000
              }
            ]
          }
        ]
      }
    }
  }
}

These results show that the updated exposure to Software of .35 falls within the min-max exposure range of .30 - .40.

The results also show that the trade size of $20,000 out of TSLA and into MSFT satisfies the TSLA security constraint — where the optimizer sizes TSLA at $180,000, which is within the range of  $150,000 - $250,000 position size constraint.

Conclusion

This guide has demonstrated how to set up a mean-variance optimization with additional security and exposure constraints. Other common objectives can be found in the common objectives article.

Did this answer your question?