Welcome to our final lesson in this course, Explorer! In this lesson, we will delve into the concept and calculation of Volume Weighted Average Price (VWAP) specifically for Tesla ($TSLA) stock data using Pandas. VWAP is a crucial indicator in trading that helps by providing the average price a security has traded at during the day, weighted by volume. By the end of this lesson, you'll be able to calculate VWAP and visualize it alongside the closing prices of Tesla stock data.
Let's start by importing the necessary libraries and loading the Tesla ($TSLA) stock data. We'll use the load_dataset function from the datasets library.
Next, we'll preprocess the data by converting the 'Date' column to datetime format and setting it as the index.
For better visualization, we'll filter the data to focus on the year 2018.
Now that we have our data preprocessed, we can calculate the VWAP. We'll use the cumulative sum (the running total, where each value is added to the sum of previous values) of the product of volume and close price and then divide it by the cumulative sum of the volume.

