Archived | Build a financial stress-test app with natural language generation

Archived content

Archive date: 2019-05-01

This content is no longer being updated or maintained. The content is provided “as is.” Given the rapid evolution of technology, some content, steps, or illustrations may have changed.


In these volatile economic times, investors need to better understand the effects of different market conditions on their portfolios. This code pattern shows you how to build a stress-testing app for investment portfolios that has the added benefit of integration with natural language generation (NLG) so you can produce detailed, well-written portfolio analyses.


The financial markets are always on the move. Anyone with an investment portfolio knows how stressful it can be to watch the markets move and not know what the effects will be on their investment portfolio.

For developers, the challenge comes in providing insight and accurate predictions about how a portfolio might perform under a wide variety of conditions. In addition, we need to provide results that can be easily understood by financial advisors and the wider public. It doesn’t make sense to create a complex application if it can’t produce data and reports that are easily interpreted by the people who need the information.

This code pattern shows you how to compute a stress test using multiple services. You apply the Predictive Market Scenario service and Simulated Instrument Analytics service to a set of investments maintained in the Investment Portfolio service. Then, you narrate the results in the form of a textual report using the Arria NLG service.

The Investment Portfolio service manages and stores portfolios and financial security information, such as the set of eligible investments, benchmarks, and user portfolios. The Predictive Market Scenarios service generates a scenario representing an alternative, potential state of the market, which can then be applied to the assets in the Investment Portfolio service using the Simulated Instrument Analytics service.

The results that you generate include observed correlations and co-variances of market risk factors (for example, interest rates, equity indexes, and foreign exchange rates), expected possible movements based on a user-defined market shock, and profits and losses for each asset in the investment portfolio. And because results from this kind of stress-testing can be difficult to interpret and parse for meaning, you implement natural language generation. Instead of poring over complex data, you pipe the results to the Arria NLG service, which generates a human-readable interpretation of the results.

This pattern walks you through the steps required to build a web app that integrates sophisticated analysis with innovative new NLG technology. You’ll create a simplified user interface that demonstrates how to collect information on any type of stress that the user wants to observe, and then formulates a narrative to be displayed alongside the charts and graphical representation of the results. For anyone looking to build in-demand, innovative, and practical skills in a financial development environment, this is the place to start.



  1. The user seeds the Investment Portfolio service with portfolio specific information before running the application.
  2. The user enters information to a web interface, such as the content of the portfolio, the risk factors, and the shock magnitude.
  3. The IBM Cloud Predictive Market Scenario service generates the scenario from the risk factor and shock magnitude inputs.
  4. The IBM Cloud Simulated Instrument Analytics service calculates the stressed value for each holding in the portfolio using the scenario generated in the previous step.
  5. The results are passed to the Arria NLG service to generate a narrative to be returned to the user alongside the numerical results.


Find detailed technical steps for this code pattern in the file in the GitHub repository.

  1. Create the Arria service.
  2. Create the IBM Cloud services.
  3. Clone the repository.
  4. Configure the .env file.
  5. Load the investment portfolio.
  6. Run the application.
  7. Deploy the application to IBM Cloud.