Stock Analysis with Python
Using python and Yahoo finance API to analyze Telkom and XL Axiata performance from January 2016 to December 2021
The dataset I used consists of stock data for PT Telkom Indonesia Tbk and PT XL Axiata Tbk from January 2016 to December 2021. Both companies operate in the telecommunications sector and have been listed on the stock exchange for over 10 years, using stock codes TLKM and EXCL, respectively. Data for both companies was obtained from the Yahoo Finance API within the interval of January 2016 to September 2021. By processing the data for TLKM and EXCL, a comparative analysis of the technical aspects of both companies will be conducted.
I use 5 attributes : Open, High, Low, Close, and Volume, with each having 1507 instances.
- Open: The opening price of the first transaction on that day.
- High: The highest price during the trading period on that day.
- Low: The lowest price during the trading period on that day.
- Close: The closing price of the last transaction on that day.
- Volume: The number of transactions or trades that occurred.
You can find the source code in this github link : Stock-Analysis-with-Python
Stock Trend
Let’s see the trend to analyze Telkom and XL stock. I use smoothing method called Moving Average with 50 samples.
Telkom Stock Trend using Open Price Data :
XL Stock Trend using Open Price Data :
Observe the comparison :
Comparison of “Open Prices” between TLKM and EXCL
It can be observed that from 2016 to 2017, XL Axiata’s performance was not favorable, showing a downward trend. In contrast, Telkom continued to experience an upward trend during that year, eventually surpassing XL Axiata’s stock price, which had initially been higher than Telkom’s in early 2016. Since then, Telkom’s opening stock price has consistently remained above that of XL Axiata.
On March 20, 2020, EXCL recorded its lowest open price since 2016 at Rp1,410. Not far from that date, on March 26, 2020, TLKM also experienced a significant drop, registering an open price of Rp2,550. These declines in both companies’ stock prices are closely related to the COVID-19 pandemic situation, which was confirmed in Indonesia on March 2, 2020. Subsequently, on March 17, 2020, the BNPB (National Disaster Management Agency) announced an extension of the state of emergency due to the Corona virus in Indonesia.
Market Capitalization of TLKM vs EXCL
By using the Volume and Open Price data, we can determine the total number of shares traded on that day. The total traded amount is calculated as Open Price multiplied by Volume. The total traded amount serves as an indicator of a stock’s liquidity.
From the graph, it can be observed that generally, Telkom (TLKM) has a higher total traded amount compared to XL (EXCL). It can be concluded that TLKM’s stock has higher liquidity than EXCL’s.
Daily Percentage Change
Here we want to know how much return did we get if we sell our stock next day. Is it positive or negative. The larger return we got daily it means that the stock is volatile. This analysis can determine wether a stock stable or not. It is important for investing strategy. Return is calculated with Close Data.
Telkom Daily Return :
XL Daily Return :
The fatter our histogram, the more volatile. The width of those bell shape related to standar deviation of the distribution. The higgher standar deviation, the higher variance, the more volatile the stock.
Telkom vs XL Daily Return :
Here we can see that XL Axiata is more volatile than Telkom. It means that Telkom stock is more stable.
Visualizing the daily returns using a boxplot can also be used to determine the volatility of a stock. From the data above, it can be seen that XL Axiata has many varied outliers, suggesting that Telkom’s stock is more stable than XL Axiata’s.
Cummulative Return
Cumulative return compute return relative to the day investment has been made. It will give investor insight on a long-term investment. If I invested $1 the first day in the company, how much would it return today. If cumulative return above 1, we’re making provit.
From graph above, we can see that investing in Telkom will have higher probability to gain provit than in XL.