Skip to content

Code for creating normalized peak plot of Dow Jones Industrial Average (DJIA) in last 15 recessions

Notifications You must be signed in to change notification settings

OpenSourceEcon/DJIA_NormPeakPlot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

98 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OSE Lab cataloged Python 3.8.2+ Build Status Codecov

Normalized Peak Plot of Dow Jones Industrial Average (DJIA)

The code in this repository allows the user to create a normalized peak plot of the Dow Jones Industrial Average (DJIA) over the last 15 recessions, from the Great Depression (Aug. 1929 to Mar. 1933) to the most recent COVID-19 recession (Feb. 2020 to Apr. 2020). The dynamic version of this plot, which is updated regularly, is available to manipulate and explore at https://www.oselab.org/gallery/djia_npp. The core maintainer of this repository is Richard Evans (@RickEcon).

A normalized peak plot takes the maximum level of the DJIA at the beginning of a recession (within two months of the NBER declared beginning month) and normalizes the entire series so that the value at that peak equals 1.0. As such, the normalized time series shows the percent change from that peak. This is an intuitive way to compare the progression of average stock prices across recessions. The following figure is a screen shot of the normalized peak plot of the DJIA from Mar. 4, 2022.

This README.md is organized into the following three sections.

  1. Running the code and generating the dynamic visualization
  2. Functionality of the dynamic visualization
  3. Contributing to this visualization code

1. Running the code and generating the dynamic visualization

The code for creating this visualization is written in the Python programming language. It requires the following file:

  • djia_npp_bokeh.py: a Python module that defines two functions in order to create the HTML and JavaScript for the dynamic visualization of the DJIA normalized peak plot of the last 15 recessions.
    • get_djia_data() takes inputs for the date ranges to plot and whether to download the data directly from Stooq.com or retrieve the data from a file saved previously on your local hard drive in the data directory of this repository. Then the function collects, cleans, and returns the DJIA data.
    • djia_npp() creates the dynamic visualization of the normalized peak plot of the DJIA over the last 15 recessions. This script calls the get_djia_data() function. It then uses the Bokeh library to create a dynamic visualization using HTML and JavaScript to render the visualization in a web browser.

The most standard way to successfully run this code if you are using the Anaconda distribution of Python is to install and activate the djia-npp-dev conda environment defined in the environment.yml file, then run the djia_npp_bokeh.py module as a script with the defaults or import the djia_npp_bokeh.py module and run the djia_npp() function using the appropriate options. Use the following steps.

  1. Either fork this repository then clone it to your local hard drive or clone it directly to your local hard drive from this repository.
  2. Install the Anaconda distribution of Python to your local machine.
  3. Update conda and anaconda by opening your terminal and typing conda update conda and following the instructions, then typing conda update anaconda and following the instructions.
  4. From the terminal (or Conda command prompt), navigate to the directory to which you cloned this repository and run conda env create -f environment.yml. This will create the conda environment with all the necessary dependencies to run the script to create the dynamic visualization.
  5. Activate the conda environment by typing in your terminal conda activate djia-npp-dev.
  6. Create the visualization in one of two ways.
    • Run the djia_npp_bokeh.py module as a script with the default settings of the djia_npp() function. This will produce the dynamic visualization in which the data are downloaded from the internet, the end date is either the current day or the most recent day with DJIA closing data, and then the default months from peak.
    • Import the djia_npp_bokeh.py and execute the djia_npp() function by typing something like the following:
    import djia_npp_bokeh as djia
    
    djia.djia_npp(12, 2, 24, 6, '2020-07-01')
  7. Executing the function djia_npp() will result in three output objects: the dynamic visualization HTML file, the original time series of the DJIA, and the organized dataset of each recession's variables time series for the periods specified in the function inputs.

2. Functionality of the dynamic visualization

This dynamic visualization allows the user to customize some different views and manipulations of the data using the following functionalities. The default view of the visualization is shown above.

  • Highlight or mute specific recession time series by clicking on the series label in the legend on the right side of the plot. The screen shot below shows a version of the plot in which all the recession time series have been muted except for the current COVID-19 recession and the Great Depression. Note that even when muted, the time series are still faintly visible.
  • Hovertool display. If you select the hovertool button on the left side of the plot, which is the default for the plot, information about each point in each time series will be displayed when you hover your cursor over a given point in the plot area. The screen shot below shows a version of the plot in which the hovertool is selected and the information about the minimum point in the current recession is displayed.
  • Pan different areas of the data. If you click on the pan button on the left side of the plot, you can use your cursor to click and drag on the data window and change your view of the data.
  • Zoom in or out on the data. You can zoom in or zoom out on the data series in three different ways. You can use the box zoom functionality by clicking on its button on the left side of the plot and clicking and dragging a box on the area of the plot that you want to zoom in on. You can also zoom in by clicking on the zoom in button on the left side of the plot, then clicking on the area of the plot you want to center your zoom in around. Or you can zoom out by clicking on the zoom out button on the left side of the plot, then clicking on the area of the plot you want to center your zoom out around. The screen shot below shows a zoomed out version of the plot.
  • Save current view of data as .png file. You can save your current view of the data as a .png file to your local hard drive by clicking on the save button on the left side of the plot.
  • Undo and redo actions. You can undo or redo any of the plot changes that you make using the undo button or the redo button on the left side of the plot.
  • Reset the plot. After any changes you make to the plot, you can reset it to its original position by using the reset button on the left side of the plot.

3. Contributing to this visualization code

If you wish to improve or enhance this code or if you find errors or bugs, please consider the following ways to contribute to this project.

  • Browse the repository Issues for known areas that need attention.
  • Submit questions or suggestions by submitting a new issue in the repository Issues.
  • Submit a pull request with your proposed changes.

About

Code for creating normalized peak plot of Dow Jones Industrial Average (DJIA) in last 15 recessions

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published