Giter VIP home page Giter VIP logo

ashwinimahendiran / predictive-market-stress-testing Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ibm/predictive-market-stress-testing

0.0 2.0 0.0 663 KB

Code for a Developer Journey that uses the Financial APIs (Investment Portfolio, Predictive Market Scenario and Simulated Instrumented Analytics) on Bluemix. This application uses these services to generate stress test on investment holdings.

Home Page: https://predictive-market-stress-testing.mybluemix.net/

License: Apache License 2.0

Python 45.37% CSS 1.76% JavaScript 28.46% HTML 24.41%

predictive-market-stress-testing's Introduction

Predictive Market Stress Testing

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

Included Components

  • Bluemix Investment Portfolio
  • Bluemix Predictive Market Scenario
  • Bluemix Simulated Instrument Analytics

Deploy to Bluemix

Deploy to Bluemix

Be sure to load investment portfolio before running the application.

Running the Application

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

Prerequisite

Steps

  1. Clone the repo
  2. Create Bluemix 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 https://github.com/IBM/Predictive-Market-Stress-Testing.git

2. Create Bluemix services

Create the following services:

3. Load Investment Portfolio

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.

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 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

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 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=

6. Run Application

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/

Troubleshooting

  • 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

License

Apache 2.0

predictive-market-stress-testing's People

Contributors

raheelzubairy avatar ljbennett62 avatar stevemar avatar

Watchers

James Cloos avatar Ashiwni Mahendiran avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.