Modern Portfolio Manager Explained

Vidyasagar Machupalli
4 min readSep 28, 2017

Heard about “Investment Insights for Asset Managers”? Not yet? you must read our previous post that introduces you to this application which is a modern portfolio manager that provides real-time insights into how news around the world can impact a given portfolio.

In this post, you will learn more in-depth about the investment insights application — how it’s built, request and response of each service and how the Financial services are chained with Watson Discovery to assert the magic of news articles impacting the shock value. The shock value is then used with Simulated Instrument Analytics service on IBM Cloud to predict the Stressed price.

The project deploys a node.js Cloud Foundry application and uses the following services:

The application uses the financial services to analyze a stock portfolio in regards to various risk factors. Risk factors include things like currency fluctuations or changes in the price of oil and gold.

Flow

A user selects a risk factor to consider.

  1. Using Watson Discovery, the app looks for articles related to the risk factor.
  2. The app computes a shock value based on the sentiment of the articles.
  3. The app calls the Predictive Market Scenarios service to create conditional scenarios to model how given a change to a subset of factors the broader set of market factors are expected to change.
  4. Finally, it computes analytics on the portfolio stocks under the given scenarios.

For instructions to deploy and run the app, refer README file

Testing the API

Before testing the APIs, let’s get authenticated with AppID and set the cookie. Run the below cURL command on the terminal

curl -v {App or localhost url}/auth/loginanon

Pick the Location value from the response and run the below comment by passing the location value between the double quotes

curl -v "{Location Value}"

You should see a response — HTTP/1.1 302 Moved Temporarily. Repeat the above step with the new Location value.

Now, you can find the cookie in the response — HTTP/1.1 302 Found under set-cookie. Let’s make our first API call with the cookie to GET your portfolios created as part of the application.

curl -v --cookie "{complete cookie value}" {App or localhost url}/api/v1/portfolios

Note: Don’t forget to pass the cookie with all your API requests.

Now, you know how to explore the APIs. Let’s see some internals and other API calls.

Computing the shock value

As described by the Predictive Market Scenarios API documentation, the shock value is a ratio of the new to old values of the risk factor. Basically, it means if you want to simulate a fall, the ratio needs to be lower than 1 and if you want to simulate a rise, it needs to be greater than 1.

Let’s say you want to apply a 1.3% fall. This would translate to a shock value (ratio) of 0.987 (1–0.013 = 0.987). A 1.3% rise would be 1.013 (1 + 0.013 = 1.013).

In the demo, This shock value is derived from the analysis performed in the News Analysis page.

Running the simulation

When the user runs a simulation, the client calls the /api/v1/simulation endpoint passing the risk factor, the shock value and the portfolio holdings (their instrument IDs to be more specific). It happens in routes/simulation.js.

The first step is to generate what-if scenarios using the Predictive Market Scenarios service. There we pass the risk factory and the shock value:

POST /api/v1/scenario/generate_predictive
{
market_change: {
risk_factor: 'CX_EQI_SPDJ_USA500_BMK_USD_LargeCap_Price',
shock: 1.013
}
}

The service returns a JSON response with a scenario file:

{
file: ""
}

The file content is actually a CSV but we don’t really need to know that. In the next step, we call the Simulated Instrument Analytics service with this content. The service expects a list of instrument IDs and a scenario file. We could save the file content in a temporary file to pass it to the next service but we can use a nice trick to avoid this by directly passing the string as the file content:

formData: {
instruments: req.body.instrumentIds.toString(),
scenario_file: {
value: csvFileContent,
options: {
filename: 'predictions.csv',
contentType: 'text/plain'
}
}
}

For the respective service API request URLs and details, refer /routes/*.js files.

For request URLs, body and other details, refer API Explorer.

If you want to try the application, it is deployed at http://investment-insights-am.mybluemix.net

Try the live app

--

--

Vidyasagar Machupalli

Architect, Developer, IBMer, Speaker, Blogger, Teetotaller, Geek & many more…