IBM/predictive-market-using-arria

Name: predictive-market-using-arria

Owner: International Business Machines

Description: 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.

Created: 2017-12-05 19:51:10.0

Updated: 2018-05-01 15:53:51.0

Pushed: 2018-05-17 21:18:07.0

Homepage: https://developer.ibm.com/code/patterns/build-a-stress-test-app-for-financial-portfolios

Size: 8722

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Predictive Market Using Arria

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:

Architecture flow

Included Components

Offered on IBM Cloud:

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

Automatically Deploying the Application to IBM Cloud

![Deploy to IBM Cloud]

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.

Manually Deploying the Application to IBM Cloud

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

Prerequisite
Steps
  1. Create Arria service
  2. Create IBM Cloud services
  3. Clone the repo
  4. Configure .env file
  5. Load Investment Portfolio
  6. Run Application
  7. Deploy to IBM Cloud

1. Create Arria service

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.

2. Create IBM Cloud services

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.

3. Clone the repo

Clone the Predict Market Using Arria repo locally. In a terminal, run:

$ git clone https://github.com/IBM/predictive-market-using-arria.git

4. 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 in terminal:

 .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
ED_PORTFOLIO_USERID_W=
ED_PORTFOLIO_PWD_W=
ED_PORTFOLIO_USERID_R=
ED_PORTFOLIO_PWD_R=
ED_PORTFOLIO_URL=https://investment-portfolio.mybluemix.net/

Predictive Market Scenario
ED_PREDICTIVE_MARKET_SCENARIO_URL=https://fss-analytics.mybluemix.net/
ED_PREDICTIVE_MARKET_SCENARIO_ACCESSTOKEN=

Simulated Instrument Analytics
ED_SIMULATED_INSTRUMENT_ANALYTICS_URL=https://fss-analytics.mybluemix.net/
ED_SIMULATED_INSTRUMENT_ANALYTICS_ACCESSTOKEN=

Arria Natural Language Generation
ED_ARRIA_NATURAL_LANGUAGE_GENERATION_URL=https://stresstesting-narrativeapi.arria.com/services/rest/fullnarrative
ED_ARRIA_NATURAL_LANGUAGE_GENERATION_KEY=
ED_ARRIA_NATURAL_LANGUAGE_GENERATION_FACTORS=factors.csv
ED_ARRIA_NATURAL_LANGUAGE_GENERATION_VSV=vcv.csv
5. Load Investment Portfolio

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:

install
 investmentPortfolio.js -l MyFixedIncomePortfolio

To load holdings from holdings.sample.json into MyFixedIncomePortfolio, run:

 investmentPortfolio.js -l MyFixedIncomePortfolio -h holdings.sample.json

Similarly you can view your portfolios by running:

 investmentPortfolio.js -g

and view holdings for portfolio:

 investmentPortfolio.js -g MyFixedIncomePortfolio
6. Run Application

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

7. Deploy to IBM Cloud

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:

plications:
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 manfiest.yml file is configured, you can push to IBM Cloud. From your root directory login into IBM Cloud using CLI:

ogin

And push the app to IBM Cloud:

ush

Troubleshooting

ogs <application-name> --recent

License

Apache 2.0


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.