Stock price and portfolio return visualization of S&P 500 stocks using Shiny

Avatar
Posted on Jun 30, 2019

Visit Shiny App here:

URL link: https://jessiec006.shinyapps.io/StockVisualization0630/

Introduction

Coming from a finance/accounting background and have worked as a transaction service advisor for publicly traded firms for 3 years, I have always been intrigued by the depth of information the seemingly “plain and simple” stock price can convey to informed audience.

For this project, I build a Shiny app that serves as a useful and informational visualization tool that helps user to visualize (1) historical stock price, (2) stock price forecast using traditional time -series predicting models, (3) stock trading volume heatmap and correlation analysis, and (4) stock portfolio return simulation. This blog is divided into such 4 sections as well.

Further note before we begin:

Dataset: daily stock price (low, high, open, close) and trading volume of all stocks on S&P 500 from February 2013 to February 2018 (5 years). Available on Kaggle at https://www.kaggle.com/camnugent/sandp500.

Dynamic listing: S&P 500 is a dynamic index that includes 500 companies with the largest market capitalizations listed on the NYSE and NASDAQ. This means that certain companies will leave and certain companies will join this index during the 5-year time span. This extra feature will bring interesting twists and dynamics to our visualization as I will demonstrate later.

Part 1: Stock price historical trend

In this section, users are able to input the ticker of the company of their choice, select the range of dates & type(s) of price (open price / close price / high price / low price). The app will display stock price over time using line chart, histogram, and bar chart to visualize the historical trend of stock price during the chosen time period. The metrics at the bottom allows users to understand how many days were the chosen stock listed on S&P 500 (particularly useful for those stocks that have exited/entered the index), the maximum close price, minimum close price, and average close price the during the chosen time period.

Part 2: Stock price forecasting models

In this section, users are able to input the ticker of the company of their choice, and visualize how accurate classical stock price time-series forecasting models predict the daily stock price from March 2017 to February 2018, using the historical daily price from February 2013 to March 2017 as training data.

Here, three forecasting models are included: (a) ARIMA (Autoregressive Integrated Moving Average), (b) Exponential Smoothing, and (c) Holt Winters Exponential Smoothing. For more information on the more complex theories and principles behind each of these statistical models, please refer to here.

Accuracy measurements, which include ME, MAE, RMSE, and MPE, are included at the bottom of the graph.

Part 3: Stock trading volume heatmap and correlation

In this section, users are able to visualize the historical monthly trading volume ratio of stocks that have been listed on S&P 500 during the 5-year time horizon.

Monthly trading volume heat ratio is calculated as the total trading volume of a given stock divided by the total trading volume of all S&P500 stocks in a given particular month.

Users can pick their desired date range as well as the stock ticker of their choice. If certain stock was not listed on S&P 500 during the selected date range (for example, Hilton [HLT] was not listed on S&P500 until 2017), the heatmap will automatically grey out the date where it was not listed. The heatmap allows users to visualize how the trading volume of  stocks fluctuates over time (relative to the entire S&P 500), and how correlated the trading volume of stocks they choose is.

Part 4: Stock portfolio return simulation

In this section, users are able to build a portfolio consisting of 5 stocks of their choice, and customize weights assigned to each stock. Weights have to add up to 100%. Users are also able to select their desired date range.

The app will display the movement of the hypothetical portfolio return of the 5 stocks during the chosen time frame. Note that, if any stock(s) was not present on S&P 500 during the chosen date range, I have built in an algorithm to redistribute the weight originally assigned to that stock(s) by users equally to the rest of the stocks.

I hope you enjoy reading this post and navigating through this app. Please do not hesitate to reach out to me at [email protected] for any comments and suggestions. Feedback is greatly appreciated!

About Author

Related Articles

Leave a Comment

No comments found.

View Posts by Categories


Our Recent Popular Posts


View Posts by Tags

#python #trainwithnycdsa 2019 airbnb Alex Baransky alumni Alumni Interview Alumni Reviews Alumni Spotlight alumni story Alumnus API Application artist aws beautiful soup Best Bootcamp Best Data Science 2019 Best Data Science Bootcamp Best Data Science Bootcamp 2020 Best Ranked Big Data Book Launch Book-Signing bootcamp Bootcamp Alumni Bootcamp Prep Bundles California Cancer Research capstone Career Career Day citibike clustering Coding Course Demo Course Report D3.js data Data Analyst data science Data Science Academy Data Science Bootcamp Data science jobs Data Science Reviews Data Scientist Data Scientist Jobs data visualization Deep Learning Demo Day Discount dplyr employer networking feature engineering Finance Financial Data Science Flask gbm Get Hired ggplot2 googleVis Hadoop higgs boson Hiring hiring partner events Hiring Partners Industry Experts Instructor Blog Instructor Interview Job Job Placement Jobs Jon Krohn JP Morgan Chase Kaggle Kickstarter lasso regression Lead Data Scienctist Lead Data Scientist leaflet linear regression Logistic Regression machine learning Maps matplotlib Medical Research Meet the team meetup Networking neural network Neural networks New Courses nlp NYC NYC Data Science nyc data science academy NYC Open Data NYCDSA NYCDSA Alumni Online Online Bootcamp Open Data painter pandas Part-time Portfolio Development prediction Prework Programming PwC python python machine learning python scrapy python web scraping python webscraping Python Workshop R R language R Programming R Shiny r studio R Visualization R Workshop R-bloggers random forest Ranking recommendation recommendation system regression Remote remote data science bootcamp Scrapy scrapy visualization seaborn Selenium sentiment analysis Shiny Shiny Dashboard Spark Special Special Summer Sports statistics streaming Student Interview Student Showcase SVM Switchup Tableau team TensorFlow Testimonial tf-idf Top Data Science Bootcamp twitter visualization web scraping Weekend Course What to expect word cloud word2vec XGBoost yelp