Stock market is a place where people arrange a transaction for buying or selling shares of publicly listed company
Indonesia has been named as the Largest Economy in Southeast Asia by the World Bank. As one of the four most populous countries in the world with more than 200 million people living in this country, Indonesia has a bargaining power to emerge as one of the biggest economies in the world. Those promising prospect of Indonesia economic condition makes this country as one of the best choices to put your investment on.
Indonesia stock markets with more than 600 listed enterprises still on the uptrends before the coronavirus outbreak. Some of the listed enterprises are state-owned enterprises and for this case study, I will only analyze 17 state-owned enterprises which been a member of the latest IDX-BUMN20 Index.
Stock used for analysis:
ANTM.JK, BBNI.JK, BBRI.JK, BBTN.JK, BJBR.JK, BMRI.JK, ELSA.JK, JSMR.JK, KAEF.JK, PGAS.JK, PTBA.JK, PTPP.JK, SMGR.JK, TINS.JK, TLKM.JK, WIKA.JK, WSKT.JK
The assumption for this case study:
We will import stock price data using getSymbols() function from the quantmod package. getSymbols() function is a particular function to load and manage financial data from various sources, but for this example, we will use Yahoo Finance as our data source.
#Import Library
library(PerformanceAnalytics)
library(quantmod)
library(ggplot2)
library(xts)
library(zoo)
library(tidyverse)
library(dplyr)
library(PortfolioAnalytics)
#Set Default Time Period
setDefaults(getSymbols.yahoo, from = as.Date('2013/01/01'), to= as.Date('2020/07/26')) #Set GetSymbols default parameter such as Data Source and Time Periods
#IDX- BUMN20 Symbol List
IDXBUMN20 = c('ANTM.JK','BBNI.JK','BBRI.JK','BBTN.JK','BJBR.JK','BMRI.JK','ELSA.JK','JSMR.JK','KAEF.JK',
'PGAS.JK','PTBA.JK','PTPP.JK','SMGR.JK','TINS.JK','TLKM.JK','WIKA.JK','WSKT.JK')
weight = rep(1/length(IDXBUMN20), length(IDXBUMN20)) #Define Weight for every stock in Portfolio
#Import Stock Price from yahoo Finance
getSymbols(IDXBUMN20)
Import Stock Price Data from Yahoo Finance
In default, we will have every stock price data assigned to their stock code as xts object (ex: ANTM.JK prices will be stored in ANTM.JK variable as xts object). To make it easier for analysis, we should gather all these separate data into a single xts object.
#IDX-BUMN20 Create Dataframe
Index <- list(ANTM.JK,BBNI.JK,BBRI.JK,BBTN.JK,BJBR.JK,BMRI.JK,ELSA.JK,JSMR.JK,KAEF.JK,
PGAS.JK,PTBA.JK,PTPP.JK,SMGR.JK,TINS.JK,TLKM.JK,WIKA.JK,WSKT.JK)
names(Index) <- IDXBUMN20
Index <- lapply(Index, '[', i =,j = 6) #Select only Adjusted Close Price
Index <- do.call(cbind.data.frame, Index) #List To Dataframe
names(Index) <- IDXBUMN20 #Change Colnames
Index <- as.xts(Index)
view raw
Closing Adj. Price and Gather Object.R hosted with ❤ by GitHub
Gather separate data into a single xts object
Fig-1. Index xts object preview
We already made a portfolio, and it stored as single xts object in a variable named Index. The data that we store in this variable is still in closing price format for every market day, since most of the portfolio analytics method need to feed by return data, we have to calculate its Return first before taking a step into portfolio analysis.
#finance #towards-data-science #stock-market #portfolio #data-analysis #data analysis