This repository will not be updated. The repository will be kept available in read-only mode.
This code pattern demonstrates how to compute a stress test using the Predictive Market Scenario service and Simulated Instrument Analytics service on a set of investments maintained in the Investment Portfolio service, and then narrate the results using the Arria NLG service.
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
- Pipe the results to the Arria NLG service which generates a human-readable interpretation of the results
Offered on IBM Cloud:
NOTE: These services are free for those who have a Lite account.
You will need to create Arria service in IBM Cloud and then bind the Arria NLG service to your application.
Go to your application page in IBM Cloud, under Connections choose Create Connection
:
Find your Arria Natural Language Generation service and choose Connect
:
Next, load investment portfolio before running the application. First clone the repo and then use the investmentPortfolio.js
script to load your portfolio.
Follow these steps to setup and run this pattern. The steps are described in detail below.
- Create Arria service
- Create IBM Cloud services
- Clone the repo
- Configure .env file
- Load Investment Portfolio
- Run Application
- Deploy to IBM Cloud
You will need Arria API key. Register for an Arria account here. Click Get Started
to sign up for an account.
After you have created your account, then login. Click Your API Key
. This will take you to your API key, which will be required in subsequent steps.
Explore Narrative APIs
. Here under Portfolio Management
, find Predictive Market Stress Testing
.
Next, create the Arria service in IBM Cloud.
For the Arria Natural Language Generation API
service in IBM Cloud you will need to provide your API Key from Arria.
For the url provide: https://stresstesting-narrativeapi.arria.com/services/rest/fullnarrative
. Click Create
to create the service in IBM Cloud.
Create the following services in IBM Cloud for financial services:
For each service, go to service credentials
on the left tab. Select New Credentials
Choose a name for your credentials, click Add
:
This will add credentials to your service.
Clone the Predict Market Using Arria repo
locally. In a terminal, run:
$ git clone https://github.com/IBM/predictive-market-using-arria.git
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 in terminal:
$ 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
CRED_PORTFOLIO_USERID_W=
CRED_PORTFOLIO_PWD_W=
CRED_PORTFOLIO_USERID_R=
CRED_PORTFOLIO_PWD_R=
CRED_PORTFOLIO_URL=https://investment-portfolio.mybluemix.net/
# Predictive Market Scenario
CRED_PREDICTIVE_MARKET_SCENARIO_URL=https://fss-analytics.mybluemix.net/
CRED_PREDICTIVE_MARKET_SCENARIO_ACCESSTOKEN=
# Simulated Instrument Analytics
CRED_SIMULATED_INSTRUMENT_ANALYTICS_URL=https://fss-analytics.mybluemix.net/
CRED_SIMULATED_INSTRUMENT_ANALYTICS_ACCESSTOKEN=
# Arria Natural Language Generation
CRED_ARRIA_NATURAL_LANGUAGE_GENERATION_URL=https://stresstesting-narrativeapi.arria.com/services/rest/fullnarrative
CRED_ARRIA_NATURAL_LANGUAGE_GENERATION_KEY=
CRED_ARRIA_NATURAL_LANGUAGE_GENERATION_FACTORS=factors.csv
CRED_ARRIA_NATURAL_LANGUAGE_GENERATION_VSV=vcv.csv
You will now need to create a portfolio in your Investment Portfolio service and create holdings for that portfolio. The holdings.sample.json
file provides you with sample holdings for a portfolio.
You can use the investmentPortfolio.js
script to load portfolio and holdings. The credentials for Investment Portfolio service are retrieved from .env
file as per the previous step or can be added directly to the script.
To load a portfolio named MyFixedIncomePortfolio
, first install dependencies and use the command-line with the investmentPortfolio.js
script to create portfolio. In the project directory, run the following commands in terminal:
$ npm install
$ node investmentPortfolio.js -l MyFixedIncomePortfolio
To load holdings from holdings.sample.json
into MyFixedIncomePortfolio
, run:
$ node investmentPortfolio.js -l MyFixedIncomePortfolio -h holdings.sample.json
Similarly you can view your portfolios by running:
$ node investmentPortfolio.js -g
and view holdings for portfolio:
$ node investmentPortfolio.js -g MyFixedIncomePortfolio
In your terminal, cd
into this project's root directory
- Run
npm install
to install the app's dependencies - Run
npm start
- Access the running app locally at http://localhost:8080/
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 IBM Cloud. The relevant portion of the manifest.yml
file looks like the following:
applications:
- path: .
memory: 256M
instances: 1
domain: mybluemix.net
name: arria-predictive-market
host: arria-predictive-market
disk_quota: 256M
buildpack: sdk-for-nodejs
services:
- {Investment-Portfolio service name}
- {Predictive-Market-Scenarios service name}
- {Simulated-Instrument-Analytics service name}
- {Arria-Natural-Language-Generaton service name}
NOTE: Add the name of your Arria NLG service to manifest file. This will deploy the application with the service without having to bind later.
Once the manifest.yml
file is configured, you can push to IBM Cloud. 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.
This code pattern is licensed under the Apache Software License, Version 2. Separate third party code objects invoked within this code pattern are licensed by their respective providers pursuant to their own separate licenses. Contributions are subject to the Developer Certificate of Origin, Version 1.1 (DCO) and the Apache Software License, Version 2.