In 2nd , 3rd & 4th line of code , every price is divided by the first value of that series . What is the role of this ? why we have done that ?
# Plot the absolute price series
plt.figure(figsize=(10,7))
(price_data['AAPL']/price_data['AAPL'].iloc[0]).plot()
(price_data['AMZN']/price_data['AMZN'].iloc[0]).plot()
(price_data['MSFT']/price_data['MSFT'].iloc[0]).plot()
# Set the title and axes label
plt.title('Price in Change', fontsize=14)
plt.xlabel('Year-Month', fontsize=12)
plt.ylabel('Price Chnage', fontsize=12)
plt.legend()
# Show the plot
plt.show()
Hi Rajat,
As you have seen, Apple, Microsoft and Amazon have different price ranges.
If you try to plot them as it is, you will find that these prices will be graphed at different magnitudes and you wouldn't observe much from that.
Hence, one way is to divide it by the first price so that we can compare them on the same scale. This helps us to compare a 100+ stock with a stock whose price is in the 1000s.
You must have seen that this code helps us to put all three stocks in the same range and compare the price journeys.
Another way can be to find the percentage change in the prices, but that is a different topic.
I hope this helps.
Hi Rekhit ,
It was really helpful , now I got it.
Is there any defined term for this division ? Like what we call this process of dividing all prices to the first price of series to get a well defined range.
and lastly , does the percentage change and this process results the same ? Like can we use both as an alternative of each other or there are specific scenarios for each process of scaling.
Hi Rekhit ,
Are we still connected ?
It is equivalent to finding cumulative returns. That is if 100 is invested in each of the stocks how it will grow in each of the stocks.
You can calculate cumulative returns, it will yield the same answer as price divided by the first price.
Thanks