Community Articles

Find and share helpful community-sourced technical articles.
Welcome to the upgraded Community! Read this blog to see What’s New!
Rising Star

Predict Stock Portfolio Gains Using Monte Carlo


Why create yet another VaR example? To demonstrate VaR running on a modern architecture that has no vertical limit. This is a functional, immutable, scaleable interpretation of a basic technique commonly used in finance. Code Available here and on github.

link to Vlad's article for history of Monte Carlo and VaR -

Some modifications from original posting include: scala calling Yahoo API directly, alleviating the need for shell scripting and adding interopability between variables. All data loaded dynamically in memory, removing the need to store files (which inherently adds manual customizations to a generic process). Code all in Zeppelin for readability. Visualizations in Zeppelin. Inputs built in using Zep forms so the user can interact with the model. Percentiles not only on what's at risk each day but also on final portfolio value.

Figure 1.0 shows the risk you would take on per each day holding these 3 stocks.


Figure 2.0 shows what a reasonable projected outcome might be after holding this position for 100 days.


Checkout the code it has a lot more visuals. Key takeaway: "You should have purchased shares of HDP in mid Feb 2016!"

Code View

Report View


Upvoted! If the notebook works on sandbox, pls consider including it in This is actually the set of demo notebooks that get automatically installed when zeppelin is installed via Ambari

Version history
Last update:
‎09-16-2022 01:34 AM
Updated by: