Code for a pattern that uses the Financial APIs (Investment Portfolio, Predictive Market Scenario and Simulated Instrumented Analytics) on IBM Cloud. This application uses these services to generate stress test on investment holdings.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.

Predictive Market Stress Testing

In this code pattern, we will use three IBM Cloud finance services to create a web application which performs stress test on an investment portfolio. The Investment Portfolio service is used to load the portfolio into the interface. The Predictive Market Scenario service will create a scenario csv file using risk factor and shock magnitude from user inputs. The Simulated Instrument Analytics service uses the scenario csv file with each holding in the portfolio to create a table displaying the current and stressed price of the investment holding.

This code pattern is designed for developers with interest in creating financial applications pertaining to investment portfolios. When the reader has completed this code pattern, they will understand how to:

  • Load and retrieve data from the Investment Portfolio service
  • Use the Predictive Market Scenario service to generate a scenario
  • Send data along with a scenario to the Simulated Instrument Analytics service to retrieve analytics

Included Components

Offered on IBM Cloud:

Note: these services are free for those who have a Lite account

Deploy to IBM Cloud

Create an IBM Cloud account and directly deploy the application using the button bellow.

Deploy to IBM Cloud

Be sure to load investment portfolio before running the application.

Running the Application

Follow these steps to setup and run this code pattern. The steps are described in detail below.



  1. Clone the repo
  2. Create IBM Cloud services
  3. Load Investment Portfolio
  4. Configure Manifest file
  5. Configure .env file
  6. Run Application

1. Clone the repo

Clone the Predictive-Market-Stress-Testing code locally. In a terminal, run:

$ git clone

2. Create IBM Cloud services

Create the following services in IBM Cloud. These services are part of either Free or Experimental plan.

3. Load Investment Portfolio

You can load your Investment Portfolio using curl commands in a terminal. For all these steps:

  • replace {service-user-id} the user id associated with your Investment Portfolio service
  • replace {service-user_password} with the password associated with your Investment Portfolio service

For Mac & Linux

i. Creating a portfolio entry in your Investment Portfolio service:

curl -X POST -u "{service-user-id}":"{service-user_password}" --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{ "name":"MyFixedIncomePortfolio", "timestamp": "2017-02-22T19:53:56.830Z", "closed": false, "data": { "manager": "Will Smith" }}' ''

ii. Creating holdings in your entry:

curl -X POST -u "{service-user-id}":"{service-user_password}" --header 'Content-Type: application/json' --header 'Accept:application/json' -d '{ "timestamp": "2017-06-04T19:53:56.830Z", "holdings": [ { "asset": "AMGN 4.1 06/15/21", "quantity": 10, "instrumentId": "CX_US031162BG42_USD", "companyName": "AMGEN INC"}, { "asset": "AMGN 5.15 11/15/41", "quantity": 30, "instrumentId": "CX_US031162BK53_USD", "companyName": "AMGEN INC" }, { "asset": "EVHC 5.625 07/15/22", "quantity": 50, "instrumentId": "CX_US03232PAD06_USD", "companyName": "ENVISION HEALTHCARE CORP"}, { "asset": "APC 4.85 03/15/21", "quantity": 40, "instrumentId": "CX_US032511BM81_USD", "companyName": "ANADARKO PETROLEUM CORP"}, { "asset": "ADI 3.5 12/05/26", "quantity": 30, "instrumentId": "CX_US032654AN54_USD", "companyName": "ANALOG DEVICES INC"}, { "asset": "ABIBB 2.65 02/01/21", "quantity": 20, "instrumentId": "CX_US035242AJ52_USD", "companyName": "ANHEUSER-BUSCH INBEV FIN"}, { "asset": "ABIBB 3.3 02/01/23", "quantity": 10, "instrumentId": "CX_US035242AL09_USD", "companyName": "ANHEUSER-BUSCH INBEV FIN"} ] }' ''

Find more information on Investment Portfolio api calls here.

For Windows

For windows, curl commands cannot include single quotes so provide json data as a separate file.

i. For creating a portfolio entry, create a json text file for data and save it i.e json.txt

{ "name":"MyFixedIncomePortfolio", "timestamp": "2017-02-22T19:53:56.830Z", "closed": false, "data": { "manager": "Will Smith" }}

In the same directory as the json.txt file, navigate to the folder in DOS prompt. And then run then the curl command:

curl -X POST -u "{service-user-id}":"{service-user_password}" --header "Content-Type: application/json" --header "Accept: application/json" -d @json.txt

ii. Similarly for creating holdings, create a json text file for data i.e json_holdings.txt

{ "timestamp": "2017-06-04T19:53:56.830Z", "holdings": [ { "asset": "AMGN 4.1 06/15/21", "quantity": 10, "instrumentId": "CX_US031162BG42_USD", "companyName": "AMGEN INC"}, { "asset": "AMGN 5.15 11/15/41", "quantity": 30, "instrumentId": "CX_US031162BK53_USD", "companyName": "AMGEN INC" }, { "asset": "EVHC 5.625 07/15/22", "quantity": 50, "instrumentId": "CX_US03232PAD06_USD", "companyName": "ENVISION HEALTHCARE CORP"}, { "asset": "APC 4.85 03/15/21", "quantity": 40, "instrumentId": "CX_US032511BM81_USD", "companyName": "ANADARKO PETROLEUM CORP"}, { "asset": "ADI 3.5 12/05/26", "quantity": 30, "instrumentId": "CX_US032654AN54_USD", "companyName": "ANALOG DEVICES INC"}, { "asset": "ABIBB 2.65 02/01/21", "quantity": 20, "instrumentId": "CX_US035242AJ52_USD", "companyName": "ANHEUSER-BUSCH INBEV FIN"}, { "asset": "ABIBB 3.3 02/01/23", "quantity": 10, "instrumentId": "CX_US035242AL09_USD", "companyName": "ANHEUSER-BUSCH INBEV FIN"} ] }

And next run the curl command:

curl -X POST -u "{service-user-id}":"{service-user_password}" --header "Content-Type: application/json" --header "Accept:application/json" -d json_holdings.txt`

4. Configure Manifest file

Edit the manifest.yml file in the folder that contains your code and replace with a unique name for your application. The name that you specify determines the application's URL, such as Additionally - update the service names so they match what you have in IBM Cloud. The relevant portion of the manifest.yml file looks like the following:

    label: fss-portfolio-service
    plan: fss-portfolio-service-free-plan
    label: fss-predictive-scenario-analytics-service
    plan: fss-predictive-scenario-analytics-service-free-plan
    label: fss-scenario-analytics-service
    plan: fss-scenario-analytics-service-free-plan
- path: .
  memory: 128M
  instances: 1
  name: Predictive-Market-Stress-Testing
  disk_quota: 1024M
  - Investment-Portfolio
  - Predictive-Market-Scenarios
  - Simulated-Instrument-Analytics
  buildpack: python_buildpack

5. Configure .env file

Create a .env file in the root directory of your clone of the project repository by copying the sample .env.example file using the following command:

cp .env.example .env

NOTE Most files systems regard files with a "." at the front as hidden files. If you are on a Windows system, you should be able to use either GitBash or Xcopy

You will need to update the credentials with the IBM Cloud credentials for each of the services you created in Step 2.

The .env file will look something like the following:

#Investment Portfolio

#Predictive Market Scenario

#Simulated Instrument Analytics

6. Run Application

In your terminal, cd into this project's root directory

  • Run pip install -r requirements.txt to install the app's dependencies
  • Run python
  • Access the running app in a browser at

You can push the app to IBM Cloud using IBM Cloud CLI. This will use the services and application name in the manifest.yml file. From your root directory login into IBM Cloud using CLI:

bx login

And push the app to IBM Cloud:

bx push


  • To troubleshoot your IBM Cloud application, use the logs. To see the logs, run:
bx logs <application-name> --recent
  • If you are running locally - inspect your environment variables closely to confirm they match. Try running each service as standalone:
  • If you receive ssl error running curl commands try curl --insecure which removes certificate verification


Apache 2.0