Skip to main content
khaslbeck
Gold ⭐️
Jun 11, 2016 5:45 AM UTC

Predicting Stock Portfolio Gains using Monte Carlo Simulation in Spark + Zeppelin

  • Oct 5, 2026 9:39 AM UTC
  • 1 reply
  • 3935 views
  • Translate All

Predict Stock Portfolio Gains Using Monte Carlo

Why?

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. https://github.com/kirkhas/zeppelin-notebooks/

link to Vlad's article for history of Monte Carlo and VaR - https://community.hortonworks.com/articles/36321/predicting-stock-portfolio-losses-using-monte-carl.html

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.

4941-var.png

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

4943-portfoliovalue.png

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

Code View

https://www.zeppelinhub.com/viewer/notebooks/aHR0cHM6Ly9yYXcuZ2l0aHVidXNlcmNvbnRlbnQuY29tL2tpcmtoYXMvemVwcGVsaW4tbm90ZWJvb2tzL21hc3Rlci9Nb250ZUNhcmxvVmFyL25vdGUuanNvbg

Report View

https://www.zeppelinhub.com/viewer/notebooks/aHR0cHM6Ly9yYXcuZ2l0aHVidXNlcmNvbnRlbnQuY29tL2tpcmtoYXMvemVwcGVsaW4tbm90ZWJvb2tzL21hc3Rlci9Nb250ZUNhcmxvVmFyL1JlcG9ydFZpZXcvbm90ZS5qc29u


portfoliovalue.png

1 reply

abajwa
Gold ⭐️
Gold ⭐️
Jun 11, 2016 5:47 AM UTC

Upvoted! If the notebook works on sandbox, pls consider including it in https://github.com/hortonworks-gallery/zeppelin-notebooks. This is actually the set of demo notebooks that get automatically installed when zeppelin is installed via Ambari

Translate