Introduction
The Portfolio Optimization service helps investment managers understand the optimal trade-offs between risk and reward based on changes in the portfolio. The framework is built upon a flexible mathematical model which allows for solving a wide range of investment problems based on the objectives and constraints.
Methods
Construct an optimal portfolio
This operation constructs a portfolio given certain constraints.
Use this operation to construct a new portfolio from a defined universe of assets. You must specify an investable amount.
The operation builds the optimal portfolio given a universe of assets, an objective, and constraints. This operation can be done on an absolute (no benchmark) or relative (against a benchmark) basis.
POST /portfolio/construct
Request
Custom Headers
API key obtained when you created the service
The specifications for constructing the portfolio
Specifies the relation to impose when optimizing the portfolio. For example, you can specify allocation relation for specific categories, directional trade relations, number of trades allowed and cash flow.
For the construct endpoint, you must specify a constraint on the root portfolio that contains a positive value for CashAdjust. This value represents the amount to be invested into the new portfolio.
Specifies the objectives to target for the optimization of the root portfolio. The objective includes the name of the root portfolio, the measure to use (variance, return, or tracking error), whether to minimize or maximize the measure, and whether this objective is to be met now or in 30 days.
Each portfolio contains the portfolio name, type, and the assets. For each asset, specify the identifier and current quantity. You can specify three types of portfolios:
You must specify a portfolio of type root that contains the full set of assets to optimize. For the construct problem, the asset quantities in the root portfolio are set to 0.
You can specify a portfolio of type subportfolio that contains assets in the type root and grouped based on similar characteristics. For the construct problem, the asset quantities are set to 0.
You can specify a portfolio of type benchmark that contains assets in a benchmark fund. For the construct problem, these assets have quantities and do not need to be part of the root type.
curl --request POST --url https://ibm.com/api/v1/optimization/portfolio/construct --header 'accept: application/json' --header 'content-type: application/json' --header 'x-ibm-access-token: string' --data '{"constraints":[{"CashAdjust":0,"InPortfolio":"string","attribute":"string","constant":0,"description":"string","measure":"string","members":"string","portfolio":"string","relation":"string","timestep":0}],"objectives":[{"TargetPortfolio":"string","attribute":"string","description":"string","measure":"string","portfolio":"string","sense":"string","timestep":0}],"portfolios":[{"ParentPortfolio":"string","holdings":[{"asset":"string","quantity":0}],"name":"string","type":"string"}]}'
HttpResponse<String> response = Unirest.post("https://ibm.com/api/v1/optimization/portfolio/construct") .header("x-ibm-access-token", "string") .header("accept", "application/json") .header("content-type", "application/json") .body("{"constraints":[{"CashAdjust":0,"InPortfolio":"string","attribute":"string","constant":0,"description":"string","measure":"string","members":"string","portfolio":"string","relation":"string","timestep":0}],"objectives":[{"TargetPortfolio":"string","attribute":"string","description":"string","measure":"string","portfolio":"string","sense":"string","timestep":0}],"portfolios":[{"ParentPortfolio":"string","holdings":[{"asset":"string","quantity":0}],"name":"string","type":"string"}]}") .asString();
import http.client conn = http.client.HTTPSConnection("ibm.com") payload = "{"constraints":[{"CashAdjust":0,"InPortfolio":"string","attribute":"string","constant":0,"description":"string","measure":"string","members":"string","portfolio":"string","relation":"string","timestep":0}],"objectives":[{"TargetPortfolio":"string","attribute":"string","description":"string","measure":"string","portfolio":"string","sense":"string","timestep":0}],"portfolios":[{"ParentPortfolio":"string","holdings":[{"asset":"string","quantity":0}],"name":"string","type":"string"}]}" headers = { 'x-ibm-access-token': "string", 'accept': "application/json", 'content-type': "application/json" } conn.request("POST", "/api/v1/optimization/portfolio/construct", payload, headers) res = conn.getresponse() data = res.read() print(data.decode("utf-8"))
Response
Contains the information about all trades that are performed on the holdings. For each holding, the asset, quantity, value, and quantity of the trade are specified.
Contains the status of the portfolio, the message, status code, the result of the objectives specified in the request, the ID of the transaction, and the start and end times of the request.
Specifies the algorithm used to perform the optimization, how many threads were used, and how long the processing took.
Status Code
OK
Invalid input. The portfolio cannot be optimized.
Error occurred in the optimizer.
[ { "holdings": { "asset": "STRING", "optimizedQuantity": "DOUBLE", "optimizedTrade": "DOUBLE", "quantity": "DOUBLE" }, "metadata": { "message": "STRING", "objectiveValue": "DOUBLE", "status": "STRING", "statusCode": "DOUBLE" }, "performance": { "algorithm": "STRING", "threads": "DOUBLE", "time": "DOUBLE" } } ]
[ { "description": "STRING", "httpcode": "DOUBLE", "requestendtimestamp": "STRING", "requeststarttimestamp": "STRING", "transactionid": "STRING" } ]
[ { "description": "STRING", "httpcode": "DOUBLE", "requestendtimestamp": "STRING", "requeststarttimestamp": "STRING", "transactionid": "STRING" } ]
Rebalance the given portfolio
This operation optimizes a portfolio.
Use this operation to rebalance a portfolio based on an objective and constraints. The portfolio must be investable and contain assets with both values and quantities. This operation can be done on an absolute (no benchmark) or relative (against a benchmark) basis.
POST /portfolio/rebalance
Request
Custom Headers
API key obtained when you created the service
The specifications for rebalancing the portfolio
Specifies the relation to impose when optimizing the portfolio. For example, you can specify allocation relation for specific categories, directional trade relations, number of trades allowed and cash flow.
For the construct endpoint, you must specify a constraint on the root portfolio that contains a positive value for CashAdjust. This value represents the amount to be invested into the new portfolio.
Specifies the objectives to target for the optimization of the root portfolio. The objective includes the name of the root portfolio, the measure to use (variance, return, or tracking error), whether to minimize or maximize the measure, and whether this objective is to be met now or in 30 days.
Each portfolio contains the portfolio name, type, and the assets. For each asset, specify the identifier and current quantity. You can specify three types of portfolios:
You must specify a portfolio of type root that contains the full set of assets to optimize. For the construct problem, the asset quantities in the root portfolio are set to 0.
You can specify a portfolio of type subportfolio that contains assets in the type root and grouped based on similar characteristics. For the construct problem, the asset quantities are set to 0.
You can specify a portfolio of type benchmark that contains assets in a benchmark fund. For the construct problem, these assets have quantities and do not need to be part of the root type.
curl --request POST --url https://ibm.com/api/v1/optimization/portfolio/rebalance --header 'accept: application/json' --header 'content-type: application/json' --header 'x-ibm-access-token: string' --data '{"constraints":[{"CashAdjust":0,"InPortfolio":"string","attribute":"string","constant":0,"description":"string","measure":"string","members":"string","portfolio":"string","relation":"string","timestep":0}],"objectives":[{"TargetPortfolio":"string","attribute":"string","description":"string","measure":"string","portfolio":"string","sense":"string","timestep":0}],"portfolios":[{"ParentPortfolio":"string","holdings":[{"asset":"string","quantity":0}],"name":"string","type":"string"}]}'
HttpResponse<String> response = Unirest.post("https://ibm.com/api/v1/optimization/portfolio/rebalance") .header("x-ibm-access-token", "string") .header("accept", "application/json") .header("content-type", "application/json") .body("{"constraints":[{"CashAdjust":0,"InPortfolio":"string","attribute":"string","constant":0,"description":"string","measure":"string","members":"string","portfolio":"string","relation":"string","timestep":0}],"objectives":[{"TargetPortfolio":"string","attribute":"string","description":"string","measure":"string","portfolio":"string","sense":"string","timestep":0}],"portfolios":[{"ParentPortfolio":"string","holdings":[{"asset":"string","quantity":0}],"name":"string","type":"string"}]}") .asString();
import http.client conn = http.client.HTTPSConnection("ibm.com") payload = "{"constraints":[{"CashAdjust":0,"InPortfolio":"string","attribute":"string","constant":0,"description":"string","measure":"string","members":"string","portfolio":"string","relation":"string","timestep":0}],"objectives":[{"TargetPortfolio":"string","attribute":"string","description":"string","measure":"string","portfolio":"string","sense":"string","timestep":0}],"portfolios":[{"ParentPortfolio":"string","holdings":[{"asset":"string","quantity":0}],"name":"string","type":"string"}]}" headers = { 'x-ibm-access-token': "string", 'accept': "application/json", 'content-type': "application/json" } conn.request("POST", "/api/v1/optimization/portfolio/rebalance", payload, headers) res = conn.getresponse() data = res.read() print(data.decode("utf-8"))
Response
Contains the information about all trades that are performed on the holdings. For each holding, the asset, quantity, value, and quantity of the trade are specified.
Contains the status of the portfolio, the message, status code, the result of the objectives specified in the request, the ID of the transaction, and the start and end times of the request.
Specifies the algorithm used to perform the optimization, how many threads were used, and how long the processing took.
Status Code
OK
Invalid input. The portfolio cannot be optimized.
Error occurred in the optimizer.
[ { "holdings": { "asset": "STRING", "optimizedQuantity": "DOUBLE", "optimizedTrade": "DOUBLE", "quantity": "DOUBLE" }, "metadata": { "message": "STRING", "objectiveValue": "DOUBLE", "status": "STRING", "statusCode": "DOUBLE" }, "performance": { "algorithm": "STRING", "threads": "DOUBLE", "time": "DOUBLE" } } ]
[ { "description": "STRING", "httpcode": "DOUBLE", "requestendtimestamp": "STRING", "requeststarttimestamp": "STRING", "transactionid": "STRING" } ]
[ { "description": "STRING", "httpcode": "DOUBLE", "requestendtimestamp": "STRING", "requeststarttimestamp": "STRING", "transactionid": "STRING" } ]