In this developer journey, we will use three Bluemix 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.
When the reader has completed this journey, 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
- Bluemix Investment Portfolio
- Bluemix Predictive Market Scenario
- Bluemix Simulated Instrument Analytics
Be sure to load investment portfolio before running the application.
Follow these steps to setup and run this developer journey. The steps are described in detail below.
- Clone the repo
- Create Bluemix services
- Load Investment Portfolio
- Configure Manifest file
- Configure .env file
- Run Application
Clone the Predictive-Market-Stress-Testing code
locally. In a terminal, run:
$ git clone https://github.com/IBM/Predictive-Market-Stress-Testing.git
Create the following services:
You can load your Investment Portfolio using curl. 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
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" }}' 'https://investment-portfolio.mybluemix.net/api/v1/portfolios'
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"} ] }' 'https://investment-portfolio.mybluemix.net/api/v1/portfolios/MyFixedIncomePortfolio/holdings'
Find more information on Investment Portfolio api calls here.
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 your-application-name.mybluemix.net
. Additionally - update the service names so they match what you have in Bluemix. The relevant portion of the manifest.yml
file looks like the following:
declared-services:
Investment-Portfolio:
label: fss-portfolio-service
plan: fss-portfolio-service-free-plan
Predictive-Market-Scenarios:
label: fss-predictive-scenario-analytics-service
plan: fss-predictive-scenario-analytics-service-free-plan
Simulated-Instrument-Analytics:
label: fss-scenario-analytics-service
plan: fss-scenario-analytics-service-free-plan
applications:
- path: .
memory: 128M
instances: 1
name: Predictive-Market-Stress-Testing
disk_quota: 1024M
domain: mybluemix.net
services:
- Investment-Portfolio
- Predictive-Market-Scenarios
- Simulated-Instrument-Analytics
buildpack: python_buildpack
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 Bluemix credentials for each of the services you created in Step 2.
The .env
file will look something like the following:
#Investment Portfolio
CRED_PORTFOLIO_USERID_W=
CRED_PORTFOLIO_PWD_W=
CRED_PORTFOLIO_USERID_R=
CRED_PORTFOLIO_PWD_R=
URL_GET_PORTFOLIO_HOLDINGS=https://investment-portfolio.mybluemix.net/api/v1/portfolios/
#Predictive Market Scenario
CRED_PREDICTIVE_MARKET_SCENARIO_URL=https://fss-analytics.mybluemix.net/api/v1/scenario/generate_predictive
CRED_PREDICTIVE_MARKET_SCENARIO_ACCESSTOKEN=
#Simulated Instrument Analytics
CRED_SIMULATED_INSTRUMENT_ANALYTICS_URL=https://fss-analytics.mybluemix.net/api/v1/scenario/instrument/
CRED_SIMULATED_INSTRUMENT_ANALYTICS_ACCESSTOKEN=
cd into this project's root directory
- Run
pip install -r requirements.txt
to install the app's dependencies - Run
python run.py
- Access the running app in a browser at http://0.0.0.0:8080/
- To troubleshoot your Bluemix application, use the logs. To see the logs, run:
cf logs <application-name> --recent
- If you are running locally - inspect your environment variables closely to confirm they match. Try running each service as standalone:
python InvestmentPortfolio.py
python PredictiveMarketScenario.py
python SimulatedInstrumentAnalytics.py