Video summary
Lecture 04 : Data Visualization- Part 2
Main summary
Key takeaways
Summary
The lecture demonstrates an R workflow for exploring and visualizing financial time-series data before moving on to portfolio analytics. The four asset series are Bitcoin, the S&P 500, an ESG fund, and European Union allowance (carbon-market) futures.
1. Load and inspect the data
- Load the R packages used in the session, including PortfolioAnalytics, tidyverse, and patchwork.
- Set the working directory to the folder containing the data files, so they can be accessed without repeatedly entering their full paths.
- Read the price and return data files. These are time-series objects, with dates stored as timestamps rather than as an ordinary data column.
- Inspect each dataset using commands such as:
class()to identify the object typehead()to view initial observationssummary()to review distribution summariesstr()anddim()to examine structure and dimensionsglimpse()for a compact overview
The price data contain 753 observations and five columns: a year field and four asset series. The return data have one fewer observation—752—because returns are calculated from successive prices.
2. Compare asset prices with the S&P 500
Use ggplot2 to create scatterplots with S&P 500 values on the x-axis and the values of one other asset on the y-axis. Add points with geom_point() and an OLS linear regression line with geom_smooth(method = "lm").
Create plots for Bitcoin, the ESG fund, and EU allowance futures, then combine them with patchwork. The plots show an overall positive, approximately linear relationship between the S&P 500 and each of the other series. The lecturer presents this as an exploratory visualization, not as a full statistical analysis.
3. Examine yearly density plots
Use density plots to explore how each asset’s observations are distributed across years. Map the year to a factor so that each year is treated as a category, and use different fills and boundary colors to distinguish the yearly curves. Apply transparency with alpha to make overlapping densities easier to see.
Combine the four asset plots, add a shared title, and adjust its position, size, and weight using a theme. The plots provide a visual check on distributional assumptions. The lecturer notes that the displayed distributions do not all look normally distributed; some appear skewed or bimodal. These visualizations are presented as a broad guide to the data’s shape.
4. Plot price movements over time
Make a copy of the price data to avoid altering the original object. Extract dates from the time-series index and plot each asset’s prices as a line over time.
Use separate colors and labels for Bitcoin, the ESG fund, the S&P 500, and EU allowance futures. Combine the four time-series plots and add a centered, larger, bold overall title. The resulting charts show how the four price series changed over the period covered by the data, approximately 2018–2021.
5. Compare yearly distributions with box plots
Create a box plot for each asset, grouping observations by year. Treat year as a factor to assign separate colors.
The lecture explains the main box-plot components:
- The bottom and top of the box represent the 25th and 75th percentiles.
- The line inside the box is the median, or 50th percentile.
- The whiskers extend according to the interquartile range (IQR), using the 1.5-IQR rule.
- Observations beyond the whiskers are identified as outliers.
Combine the four asset plots and add a shared title. The lecturer points out that the plots show differing levels of spread across assets and years, with notable outliers. The 2020 distributions appear more dispersed, which the lecture associates with COVID-era volatility.
Overall lesson
The session establishes a basic exploratory workflow: load and inspect prices and returns, then use scatterplots, density plots, time-series charts, and box plots to examine relationships, distribution shapes, trends, variability, and outliers. The next stage, described but not carried out here, is portfolio optimization and construction using the return data.
Speakers and sources featured
- Speaker: One lecturer or instructor, unnamed in the subtitles.
- Data series discussed: Bitcoin, the S&P 500, an ESG fund, and European Union allowance futures.
- Software and libraries demonstrated or mentioned: R; PortfolioAnalytics; tidyverse; ggplot2; patchwork; and zoo/xts time-series objects.
Rate this summary
Your feedback will help improve summaries.
Improve this summary
Reprocess with a stronger model when the summary feels incomplete or inaccurate.
Translate summary in another language
Ask questions to this video
Chat for follow-up questions, clarifications, and source-backed answers.