{"id":3680,"date":"2024-11-28T07:05:41","date_gmt":"2024-11-27T22:05:41","guid":{"rendered":"https:\/\/secondlife.lol\/?p=3680"},"modified":"2024-11-28T07:53:39","modified_gmt":"2024-11-27T22:53:39","slug":"dividend-stock-investment-analysis-korean-market","status":"publish","type":"post","link":"https:\/\/secondlife.lol\/en\/dividend-stock-investment-analysis-korean-market\/","title":{"rendered":"Why dividend stocks are so attractive: Analyzing the top 10 dividend stocks on the Korean stock market with R code"},"content":{"rendered":"<p class=\"wp-block-paragraph\">Hello, everyone! Today we're here to talk about something really exciting: dividend investing. Have you ever fallen for the lure of a steady stream of dividends every month? Or maybe you're still not sure what dividend investing is? Don't worry. By the time you're done reading today's post, you'll be hooked on the world of dividend investing! As a bonus, you'll be able to visualize it like this <\/p>\n\n\n<style>.kb-image3680_15b00a-3c .kb-image-has-overlay:after{opacity:0.3;border-top-left-radius:5px;border-top-right-radius:5px;border-bottom-right-radius:5px;border-bottom-left-radius:5px;}.kb-image3680_15b00a-3c img.kb-img, .kb-image3680_15b00a-3c .kb-img img{border-top-left-radius:5px;border-top-right-radius:5px;border-bottom-right-radius:5px;border-bottom-left-radius:5px;box-shadow:0px 0px 14px 0px rgba(0, 0, 0, 0.2);}<\/style>\n<div class=\"wp-block-kadence-image kb-image3680_15b00a-3c\"><figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"600\" height=\"841\" src=\"https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/11\/17324270883487966560796936942043-600x841.jpg\" alt=\"\ubc30\ub2f9\uc8fc \ud22c\uc790 - \uc0bc\uc131\uc804\uc790\" class=\"kb-img wp-image-3681\" srcset=\"https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/11\/17324270883487966560796936942043-600x841.jpg 600w, https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/11\/17324270883487966560796936942043-300x421.jpg 300w, https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/11\/17324270883487966560796936942043-768x1076.jpg 768w, https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/11\/17324270883487966560796936942043-1096x1536.jpg 1096w, https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/11\/17324270883487966560796936942043-9x12.jpg 9w, https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/11\/17324270883487966560796936942043.jpg 1200w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><figcaption>( Investing in Dividend Stocks - Samsung Electronics )<\/figcaption><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">In this post, we'll use R programming to analyze the top 10 dividend stocks on the Korean stock market in depth. From stock price movements to dividend yields to stock volatility, we've packed a lot of information into this post. Let's dive into the world of dividend investing together.<\/p>\n\n\n<style>.kb-table-of-content-nav.kb-table-of-content-id83_5f28a6-34 .kb-table-of-content-wrap{padding-top:var(--global-kb-spacing-sm, 1.5rem);padding-right:var(--global-kb-spacing-sm, 1.5rem);padding-bottom:var(--global-kb-spacing-sm, 1.5rem);padding-left:var(--global-kb-spacing-sm, 1.5rem);border-top:3px solid var(--global-palette2, #2B6CB0);border-right:3px solid var(--global-palette2, #2B6CB0);border-bottom:3px solid var(--global-palette2, #2B6CB0);border-left:3px solid var(--global-palette2, #2B6CB0);border-top-left-radius:5px;border-top-right-radius:5px;border-bottom-right-radius:5px;border-bottom-left-radius:5px;box-shadow:0px 0px 14px 0px rgba(0, 0, 0, 0.2);}.kb-table-of-content-nav.kb-table-of-content-id83_5f28a6-34 .kb-table-of-contents-title-wrap{padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;}.kb-table-of-content-nav.kb-table-of-content-id83_5f28a6-34 .kb-table-of-contents-title-wrap{color:var(--global-palette2, #2B6CB0);}.kb-table-of-content-nav.kb-table-of-content-id83_5f28a6-34 .kb-table-of-contents-title{color:var(--global-palette2, #2B6CB0);font-size:28px;font-weight:regular;font-style:normal;}.kb-table-of-content-nav.kb-table-of-content-id83_5f28a6-34 .kb-table-of-content-wrap .kb-table-of-content-list{color:var(--global-palette1, #3182CE);line-height:2em;font-weight:regular;font-style:normal;margin-top:var(--global-kb-spacing-sm, 1.5rem);margin-right:0px;margin-bottom:0px;margin-left:0px;}.kb-table-of-content-nav.kb-table-of-content-id83_5f28a6-34 .kb-table-of-content-wrap .kb-table-of-content-list .kb-table-of-contents__entry:hover{color:var(--global-palette6, #718096);}@media all and (max-width: 1024px){.kb-table-of-content-nav.kb-table-of-content-id83_5f28a6-34 .kb-table-of-content-wrap{border-top:3px solid var(--global-palette2, #2B6CB0);border-right:3px solid var(--global-palette2, #2B6CB0);border-bottom:3px solid var(--global-palette2, #2B6CB0);border-left:3px solid var(--global-palette2, #2B6CB0);}}@media all and (max-width: 1024px){.kb-table-of-content-nav.kb-table-of-content-id83_5f28a6-34 .kb-table-of-contents-title{font-size:28px;}}@media all and (max-width: 767px){.kb-table-of-content-nav.kb-table-of-content-id83_5f28a6-34 .kb-table-of-content-wrap{border-top:3px solid var(--global-palette2, #2B6CB0);border-right:3px solid var(--global-palette2, #2B6CB0);border-bottom:3px solid var(--global-palette2, #2B6CB0);border-left:3px solid var(--global-palette2, #2B6CB0);}.kb-table-of-content-nav.kb-table-of-content-id83_5f28a6-34 .kb-table-of-contents-title{font-size:28px;}}<\/style>\n\n\n<h2 class=\"wp-block-heading\">Why Invest in Dividend Stocks?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Investing in dividend stocks is one of the favorite investment strategies of many investors. Why? Apart from the ups and downs of the stock price, companies distribute a portion of their profits to shareholders in the form of dividends. Stocks that offer a steady stream of dividends are called dividend stocks.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">But can you just pick any stock and invest in it? No. There are many factors to consider when picking a good dividend stock. Today, we'll use R code to create an <a href=\"https:\/\/finance.naver.com\/sise\/\" target=\"_blank\" rel=\"noopener\">South Korean stock market<\/a>'s top 10 dividend stocks to see what to look for.<\/p>\n\n\n<style>.kb-image3680_10ff39-ed .kb-image-has-overlay:after{opacity:0.3;border-top-left-radius:5px;border-top-right-radius:5px;border-bottom-right-radius:5px;border-bottom-left-radius:5px;}.kb-image3680_10ff39-ed img.kb-img, .kb-image3680_10ff39-ed .kb-img img{border-top-left-radius:5px;border-top-right-radius:5px;border-bottom-right-radius:5px;border-bottom-left-radius:5px;box-shadow:0px 0px 14px 0px rgba(0, 0, 0, 0.2);}<\/style>\n<div class=\"wp-block-kadence-image kb-image3680_10ff39-ed\"><figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"600\" height=\"841\" src=\"https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/11\/17324272917986561538402097345858-600x841.jpg\" alt=\"SK\ud154\ub808\ucf64\" class=\"kb-img wp-image-3683\" srcset=\"https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/11\/17324272917986561538402097345858-600x841.jpg 600w, https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/11\/17324272917986561538402097345858-300x421.jpg 300w, https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/11\/17324272917986561538402097345858-768x1076.jpg 768w, https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/11\/17324272917986561538402097345858-1096x1536.jpg 1096w, https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/11\/17324272917986561538402097345858-9x12.jpg 9w, https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/11\/17324272917986561538402097345858.jpg 1200w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><figcaption>( Investing in Dividend Stocks - SK Telecom )<\/figcaption><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Analyzing Dividend Stocks with R Code<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Now it's time to dive into the R code, and if it looks a bit long, don't worry. We'll break it down piece by piece.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Load Prerequisite Libraries\nlibrary(quantmod)\nlibrary(ggplot2)\nlibrary(reshape2)\nlibrary(dplyr)\nlibrary(gridExtra)\nlibrary(scales)\nlibrary(furrr) # Parallel Processing Library\n\nSet up stock information for # to analyze\nstocks_info &lt;- data.frame(\n  symbol = c(&quot;005930.KS&quot;, &quot;017670.KS&quot;, &quot;033780.KS&quot;, &quot;000270.KS&quot;, &quot;051910.KS&quot;,\n             &quot;032640.KS&quot;, &quot;030200.KS&quot;, &quot;000810.KS&quot;, &quot;035250.KS&quot;, &quot;316140.KS&quot;),\n  name = c(&quot;Samsung Electronics&quot;, &quot;SK Telecom&quot;, &quot;KT&quot;, &quot;Kia&quot;, &quot;LG Chem&quot;,\n           &quot;LG Uplus&quot;, &quot;KT&amp;G&quot;, &quot;Samsung Fire&quot;, &quot;POSCO Holdings&quot;, &quot;Woori Financial&quot;)\n)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Code commentary<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li>First, load the necessary R packages, which are used for stock data collection, data processing, visualization, and more.<\/li>\n\n\n\n<li><code>stocks_info<\/code> Create a dataframe to store the symbols and names of the 10 stocks you want to analyze. These companies are known dividend-paying stocks in the Korean stock market.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Now we'll define functions to collect and analyze stock data.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># stock data collection function definition\nget_stock_data &lt;- function(symbol) {\n  tryCatch({\n    Collect # stock data for the last 10 years\n    data &lt;- getSymbols(\n      symbol, src = &quot;yahoo&quot;,\n      from = Sys.Date() - years(10),\n      to = Sys.Date(),\n      auto.assign = FALSE\n    )\n\n    Check # data\n    if (is.null(data)) stop(&quot;No data retrieved.&quot;)\n\n    # Remove data after the current date\n    data &lt;- data[index(data) &lt;= Sys.Date()]\n\n    # Convert to annual data\n    annual_close &lt;- to.yearly(Cl(data))\n    annual_open &lt;- to.yearly(Op(data))\n    annual_high &lt;- to.yearly(Hi(data))\n    annual_low &lt;- to.yearly(Lo(data))\n    annual_volume &lt;- to.yearly(Vo(data))\n\n    Handle # dividends (fill with 0 if none)\n    annual_dividends &lt;- if (&quot;Dividends&quot; %in% colnames(data)) {\n      to.yearly(data$Dividends)\n    } else {\n      xts(rep(0, nrow(annual_close)), order.by = index(annual_close))\n    }\n\n    } cbind(annual_open, annual_high, annual_low, annual_close,\n          annual_volume, annual_dividends)\n  }, error = function(e) {\n    warning(paste(&quot;Data fetch failed for&quot;, symbol, &quot;:&quot;, e$message))\n    return(NULL)\n  })\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Code commentary<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><code>get_stock_data<\/code> function fetches the last 10 years of data from Yahoo Finance for a given stock symbol.<\/li>\n\n\n\n<li>Converts data to an annualized basis and includes open, high, low, close, volume, and dividend information.<\/li>\n\n\n\n<li>Error handling ensures that your program doesn't break if data collection fails.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Let's also create a function to visualize the data we've collected.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># data visualization functions\nplot_stock_data &lt;- function(data, stock_info) {\n  if (is.null(data)) {\n    warning(paste(&quot;No data available for&quot;, stock_info$name))\n    return(NULL)\n  }\n\n  Create the # dataframe and calculate the metric\n  df %\n    mutate(\n      DividendYield = (Dividends \/ Close) * 100, # Dividend Yield\n      AnnualReturn = (Close \/ lag(Close) - 1) * 100, # Annualized Return\n      VolatilityRange = High - Low # Volatility Range\n    )\n\n  Remove # NA values\n  df &lt;- na.omit(df)\n\n  Apply # trending color\n  close_color &lt;- &quot;#1f77b4&quot;\n  dividend_color &lt;- &quot;#2ca02c&quot;\n  return_color &lt;- &quot;#d62728&quot;\n  volatility_color &lt;- &quot;#9467bd&quot;\n  volume_color &lt;- &quot;#8c564b&quot;\n\n  Create a # stock price and volume chart\n  p1 &lt;- ggplot(df, aes(x = Year)) +\n    geom_line(aes(y = Close), color = close_color, size = 1) +\n    geom_point(aes(y = Close), color = close_color) +\n    geom_text(aes(y = Close, label = round(Close, 0)),\n              vjust = -0.6, size = 3) +\n    geom_col(aes(y = Volume\/max(Volume, na.rm = TRUE) * max(Close, na.rm = TRUE)),\n             fill = volume_color, alpha = 0.3) +\n    scale_y_continuous(\n      name = &quot;Price (KRW)&quot;,\n      labels = scales::comma,\n      sec.axis = sec_axis(~.\/max(df$Close, na.rm = TRUE) * max(df$Volume, na.rm = TRUE),\n                          name = &quot;Volume&quot;),\n      expand = expansion(mult = c(0.05, 0.1))\n    )\n    labs(title = paste(stock_info$name, &quot;(&quot;, stock_info$symbol, &quot;)&quot;),\n         subtitle = &quot;Annual Price and Volume&quot;) +\n    theme_minimal()\n    theme(\n      plot.title = element_text(size = 14, face = &quot;bold&quot;),\n      axis.title = element_text(size = 10),\n      legend.position = &quot;bottom&quot;\n    )\n\n  Create a # return chart\n  p2 &lt;- ggplot(df, aes(x = Year)) +\n    geom_line(aes(y = DividendYield, color = &quot;Dividend Yield&quot;), size = 1) +\n    geom_point(aes(y = DividendYield), color = dividend_color) +\n    geom_text(aes(y = DividendYield, label = round(DividendYield, 1)),\n              color = dividend_color, vjust = -0.6, size = 3) +\n    geom_line(aes(y = AnnualReturn, color = &quot;Annual Return&quot;), size = 1) +\n    geom_point(aes(y = AnnualReturn), color = return_color) +\n    geom_text(aes(y = AnnualReturn, label = round(AnnualReturn, 1)),\n              color = return_color, vjust = 1.5, size = 3) +\n    scale_color_manual(values = c(&quot;Dividend Yield&quot; = dividend_color,\n                                  &quot;Annual Return&quot; = return_color)) +\n    labs(y = &quot;Rate (%)&quot;, color = &quot;Metrics&quot;) +\n    scale_y_continuous(expand = expansion(mult = c(0.05, 0.1))) +\n    theme_minimal() +\n    theme(legend.position = &quot;bottom&quot;)\n\n  Create a # volatility chart\n  p3 &lt;- ggplot(df, aes(x = Year, y = VolatilityRange)) +\n    geom_line(color = volatility_color, size = 1) +\n    geom_point(color = volatility_color) +\n    geom_text(aes(label = round(VolatilityRange, 0)),\n              vjust = -0.6, size = 3, color = volatility_color) +\n    labs(y = &quot;Volatility Range (High-Low)&quot;) +\n    scale_y_continuous(labels = scales::comma,\n                       expand = expansion(mult = c(0.05, 0.1))) +\n    theme_minimal()\n\n  Laying out the # chart\n  gridExtra::grid.arrange(p1, p2, p3, ncol = 1,\n                          heights = c(1.2, 1, 1))\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Code commentary<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">1. <code>plot_stock_data<\/code> The function takes stock data and generates three charts:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Stock price and volume charts<\/li>\n\n\n\n<li>Dividend Yield and Annualized Return Charts<\/li>\n\n\n\n<li>Volatility Range Chart<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">2. use ggplot2 to generate each chart, and gridExtra to combine the three charts into one graph.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">3. Each chart is color-coded and labeled to make it easier to read.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now we'll create a function to analyze stock data.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># stock data analysis functions\nanalyze_stocks &lt;- function(stock_data, stocks_info) {\n  results &lt;- lapply(1:nrow(stocks_info), function(i) {\n    if (is.null(stock_data[[i]])) return(NULL)\n\n    symbol &lt;- stocks_info$symbol[i]\n    data &lt;- stock_data[[i]]\n\n    df &lt;- data.frame(\n      Close = as.numeric(data[,4]),\n      Dividends = as.numeric(data[,6])\n    )\n\n    list(\n      StockName = stocks_info$name[i],\n      Symbol = symbol,\n      MeanPrice = mean(df$Close, na.rm = TRUE),\n      PriceStdDev = sd(df$Close, na.rm = TRUE),\n      MeanDividend = mean(df$Dividends, na.rm = TRUE),\n      TotalReturn = (tail(df$Close, 1) \/ df$Close[1] - 1) * 100\n    )\n  })\n\n  results &lt;- results[!sapply(results, is.null)] # remove NULLs\n  do.call(rbind, lapply(results, as.data.frame))\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Code commentary<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Yes, let's continue with the code commentary.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><code>analyze_stocks<\/code> For each stock, the function calculates the average price, standard deviation of the price, average dividend, total return, and more.<\/li>\n\n\n\n<li>Create a list of analytics results for each stock, convert them to a dataframe, and return them.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Now it's time to actually use these functions to collect and analyze data!<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Main Execution\nplan(multisession) # Parallel Session Setup\n\nCollect and visualize # data\nstock_data &lt;- future_map(1:nrow(stocks_info), function(i) {\n  symbol &lt;- stocks_info$symbol[i]\n  data &lt;- get_stock_data(symbol)\n  if (!is.null(data)) {\n    plot_stock_data(data, stocks_info[i,])\n  }\n  data\n})\n\nOutput the results of the # analysis\nanalysis_results &lt;- analyze_stocks(stock_data, stocks_info)\nprint(analysis_results)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Code commentary<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><code>plan(multisession)<\/code>to set up parallel processing. This saves me time by allowing me to collect data for multiple stocks at the same time.<\/li>\n\n\n\n<li><code>future_map<\/code> function to collect and visualize data for each stock.<\/li>\n\n\n\n<li>And finally, the <code>analyze_stocks<\/code> function to get and print the analysis results for all stocks.<\/li>\n<\/ol>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\"><style>.kb-image3680_d8c1db-bb .kb-image-has-overlay:after{opacity:0.3;border-top-left-radius:5px;border-top-right-radius:5px;border-bottom-right-radius:5px;border-bottom-left-radius:5px;}.kb-image3680_d8c1db-bb img.kb-img, .kb-image3680_d8c1db-bb .kb-img img{border-top-left-radius:5px;border-top-right-radius:5px;border-bottom-right-radius:5px;border-bottom-left-radius:5px;box-shadow:0px 0px 14px 0px rgba(0, 0, 0, 0.2);}<\/style>\n<div class=\"wp-block-kadence-image kb-image3680_d8c1db-bb\"><figure class=\"aligncenter size-medium\"><img decoding=\"async\" width=\"300\" height=\"421\" src=\"https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/11\/17324277980361804622926317882743-300x421.jpg\" alt=\"\" class=\"kb-img wp-image-3687\" srcset=\"https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/11\/17324277980361804622926317882743-300x421.jpg 300w, https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/11\/17324277980361804622926317882743-600x841.jpg 600w, https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/11\/17324277980361804622926317882743-768x1076.jpg 768w, https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/11\/17324277980361804622926317882743-1096x1536.jpg 1096w, https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/11\/17324277980361804622926317882743-9x12.jpg 9w, https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/11\/17324277980361804622926317882743.jpg 1200w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/figure><\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\"><style>.kb-image3680_ffaff8-94 .kb-image-has-overlay:after{opacity:0.3;border-top-left-radius:5px;border-top-right-radius:5px;border-bottom-right-radius:5px;border-bottom-left-radius:5px;}.kb-image3680_ffaff8-94 img.kb-img, .kb-image3680_ffaff8-94 .kb-img img{border-top-left-radius:5px;border-top-right-radius:5px;border-bottom-right-radius:5px;border-bottom-left-radius:5px;box-shadow:0px 0px 14px 0px rgba(0, 0, 0, 0.2);}<\/style>\n<div class=\"wp-block-kadence-image kb-image3680_ffaff8-94\"><figure class=\"aligncenter size-medium\"><img decoding=\"async\" width=\"300\" height=\"421\" src=\"https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/11\/17324279045003632581077926061469-300x421.jpg\" alt=\"\" class=\"kb-img wp-image-3688\" srcset=\"https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/11\/17324279045003632581077926061469-300x421.jpg 300w, https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/11\/17324279045003632581077926061469-600x841.jpg 600w, https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/11\/17324279045003632581077926061469-768x1076.jpg 768w, https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/11\/17324279045003632581077926061469-1096x1536.jpg 1096w, https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/11\/17324279045003632581077926061469-9x12.jpg 9w, https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/11\/17324279045003632581077926061469.jpg 1200w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/figure><\/div>\n<\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:100%\">\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\"><style>.kb-image3680_11e242-09 .kb-image-has-overlay:after{opacity:0.3;border-top-left-radius:5px;border-top-right-radius:5px;border-bottom-right-radius:5px;border-bottom-left-radius:5px;}.kb-image3680_11e242-09 img.kb-img, .kb-image3680_11e242-09 .kb-img img{border-top-left-radius:5px;border-top-right-radius:5px;border-bottom-right-radius:5px;border-bottom-left-radius:5px;box-shadow:0px 0px 14px 0px rgba(0, 0, 0, 0.2);}<\/style>\n<div class=\"wp-block-kadence-image kb-image3680_11e242-09\"><figure class=\"aligncenter size-medium\"><img decoding=\"async\" width=\"300\" height=\"421\" src=\"https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/11\/17324280976084115761900304129852-300x421.jpg\" alt=\"\" class=\"kb-img wp-image-3690\" srcset=\"https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/11\/17324280976084115761900304129852-300x421.jpg 300w, https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/11\/17324280976084115761900304129852-600x841.jpg 600w, https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/11\/17324280976084115761900304129852-768x1076.jpg 768w, https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/11\/17324280976084115761900304129852-1096x1536.jpg 1096w, https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/11\/17324280976084115761900304129852-9x12.jpg 9w, https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/11\/17324280976084115761900304129852.jpg 1200w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/figure><\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\"><style>.kb-image3680_c0768f-5b .kb-image-has-overlay:after{opacity:0.3;border-top-left-radius:5px;border-top-right-radius:5px;border-bottom-right-radius:5px;border-bottom-left-radius:5px;}.kb-image3680_c0768f-5b img.kb-img, .kb-image3680_c0768f-5b .kb-img img{border-top-left-radius:5px;border-top-right-radius:5px;border-bottom-right-radius:5px;border-bottom-left-radius:5px;box-shadow:0px 0px 14px 0px rgba(0, 0, 0, 0.2);}<\/style>\n<div class=\"wp-block-kadence-image kb-image3680_c0768f-5b\"><figure class=\"aligncenter size-medium\"><img decoding=\"async\" width=\"300\" height=\"421\" src=\"https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/11\/17324281565548548672021359871426-300x421.jpg\" alt=\"\" class=\"kb-img wp-image-3691\" srcset=\"https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/11\/17324281565548548672021359871426-300x421.jpg 300w, https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/11\/17324281565548548672021359871426-600x841.jpg 600w, https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/11\/17324281565548548672021359871426-768x1076.jpg 768w, https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/11\/17324281565548548672021359871426-1096x1536.jpg 1096w, https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/11\/17324281565548548672021359871426-9x12.jpg 9w, https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/11\/17324281565548548672021359871426.jpg 1200w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/figure><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Investing in dividend stocks, here's how to approach it!<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Now that we've analyzed the top 10 dividend stocks on the Korean stock market with the R code we wrote, here are some tips on how to approach dividend investing.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Check your dividend yield<\/strong>: The <code>DividendYield<\/code>The higher this value is, the more dividends you'll receive for your investment.<\/li>\n\n\n\n<li><strong>Consider stock price volatility<\/strong>: <code>VolatilityRange<\/code>to see how much the stock price has fluctuated. Stocks with low volatility are generally considered stable dividend stocks.<\/li>\n\n\n\n<li><strong>Explore total return<\/strong>: <code>TotalReturn<\/code>is the return that takes into account both stock price appreciation and dividends. Stocks with a high value may be worthy of long-term investment.<\/li>\n\n\n\n<li><strong>Check your company's financial health<\/strong>: While not included in our code, it's important to check a company's financial statements when investing in dividend stocks. A company with stable earnings can consistently pay dividends.<\/li>\n\n\n\n<li><strong>Identify industry trends<\/strong>The future prospects of each company's industry are also important: companies in industries with high growth potential are more likely to increase their dividends.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">Closing thoughts: The appeal of dividend stocks<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Investing in dividend stocks is an attractive strategy for investors looking for steady income, but as with all investments, there are risks. The information we get from our R code helps us make investment decisions, but it's not enough.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Before making an actual investment, consider a combination of in-depth analysis, personal risk appetite, and professional advice. The real beauty of dividend stocks is often in the long term.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Why not use R code to create your own dividend stock portfolio? The world of investing is wide and deep. Let's learn and grow together!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/secondlife.lol\/en\/dividend-stock-recommendations-2024-python-analysis\/\">You can also check out our post on coding dividend stocks with Python<\/a> I've written one, and you can compare it to the post you're looking at now to get a better idea of which stocks to buy. <\/p>\n\n\n\n<h3 class=\"wp-block-heading\"># Full Code<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code># Load Prerequisite Libraries\nlibrary(quantmod)\nlibrary(ggplot2)\nlibrary(reshape2)\nlibrary(dplyr)\nlibrary(gridExtra)\nlibrary(scales)\nlibrary(furrr) # Parallel Processing Library\n\nSet up stock information for # to analyze\nstocks_info &lt;- data.frame(\n  symbol = c(&quot;005930.KS&quot;, &quot;017670.KS&quot;, &quot;033780.KS&quot;, &quot;000270.KS&quot;, &quot;051910.KS&quot;,\n             &quot;032640.KS&quot;, &quot;030200.KS&quot;, &quot;000810.KS&quot;, &quot;035250.KS&quot;, &quot;316140.KS&quot;),\n  name = c(&quot;Samsung Electronics&quot;, &quot;SK Telecom&quot;, &quot;KT&quot;, &quot;Kia&quot;, &quot;LG Chem&quot;,\n           &quot;LG Uplus&quot;, &quot;KT&amp;G&quot;, &quot;Samsung Fire&quot;, &quot;POSCO Holdings&quot;, &quot;Woori Financial&quot;)\n)\n\nDefine the # stock data collection function\nget_stock_data &lt;- function(symbol) {\n  tryCatch({\n    Collect the last 10 years of # data\n    data &lt;- getSymbols(\n      symbol, src = &quot;yahoo&quot;,\n      from = Sys.Date() - years(10),\n      to = Sys.Date(),\n      auto.assign = FALSE\n    )\n    \n    Check # data\n    if (is.null(data)) stop(&quot;No data retrieved.&quot;)\n    \n    # Remove data after the current date\n    data &lt;- data[index(data) &lt;= Sys.Date()]\n    \n    # Convert to annual data\n    annual_close &lt;- to.yearly(Cl(data))\n    annual_open &lt;- to.yearly(Op(data))\n    annual_high &lt;- to.yearly(Hi(data))\n    annual_low &lt;- to.yearly(Lo(data))\n    annual_volume &lt;- to.yearly(Vo(data))\n    \n    Handle # dividends (fill with 0 if none)\n    annual_dividends &lt;- if (&quot;Dividends&quot; %in% colnames(data)) {\n      to.yearly(data$Dividends)\n    } else {\n      xts(rep(0, nrow(annual_close)), order.by = index(annual_close))\n    }\n    \n    } cbind(annual_open, annual_high, annual_low, annual_close,\n          annual_volume, annual_dividends)\n  }, error = function(e) {\n    warning(paste(&quot;Data fetch failed for&quot;, symbol, &quot;:&quot;, e$message))\n    return(NULL)\n  })\n}\n\n# data visualization functions\nplot_stock_data &lt;- function(data, stock_info) {\n  if (is.null(data)) {\n    warning(paste(&quot;No data available for&quot;, stock_info$name))\n    return(NULL)\n  }\n  \n  Create the # dataframe and calculate the metric\n  df %\n    mutate(\n      DividendYield = (Dividends \/ Close) * 100, # Dividend Yield\n      AnnualReturn = (Close \/ lag(Close) - 1) * 100, # Annualized Return\n      VolatilityRange = High - Low # Volatility Range\n    )\n  \n  Remove # NA values\n  df &lt;- na.omit(df)\n  \n  Apply # trending color\n  close_color &lt;- &quot;#1f77b4&quot;\n  dividend_color &lt;- &quot;#2ca02c&quot;\n  return_color &lt;- &quot;#d62728&quot;\n  volatility_color &lt;- &quot;#9467bd&quot;\n  volume_color &lt;- &quot;#8c564b&quot;\n  \n  Create a # stock price and volume chart\n  p1 &lt;- ggplot(df, aes(x = Year)) +\n    geom_line(aes(y = Close), color = close_color, size = 1) +\n    geom_point(aes(y = Close), color = close_color) +\n    geom_text(aes(y = Close, label = round(Close, 0)),\n              vjust = -0.6, size = 3) + # Adjust vjust value\n    geom_col(aes(y = Volume\/max(Volume, na.rm = TRUE) * max(Close, na.rm = TRUE)),\n             fill = volume_color, alpha = 0.3) +\n    scale_y_continuous(\n      name = &quot;Price (KRW)&quot;,\n      labels = scales::comma,\n      sec.axis = sec_axis(~.\/max(df$Close, na.rm = TRUE) * max(df$Volume, na.rm = TRUE),\n                          name = &quot;Volume&quot;),\n      expand = expansion(mult = c(0.05, 0.1)) # add top margin\n    )\n    labs(title = paste(stock_info$name, &quot;(&quot;, stock_info$symbol, &quot;)&quot;),\n         subtitle = &quot;Annual Price and Volume&quot;) +\n    theme_minimal()\n    theme(\n      plot.title = element_text(size = 14, face = &quot;bold&quot;),\n      axis.title = element_text(size = 10),\n      legend.position = &quot;bottom&quot;\n    )\n  \n  Create a # return chart\n  p2 &lt;- ggplot(df, aes(x = Year)) +\n    geom_line(aes(y = DividendYield, color = &quot;Dividend Yield&quot;), size = 1) +\n    geom_point(aes(y = DividendYield), color = dividend_color) +\n    geom_text(aes(y = DividendYield, label = round(DividendYield, 1)),\n              color = dividend_color, vjust = -0.6, size = 3) + # Adjust vjust value\n    geom_line(aes(y = AnnualReturn, color = &quot;Annual Return&quot;), size = 1) +\n    geom_point(aes(y = AnnualReturn), color = return_color) +\n    geom_text(aes(y = AnnualReturn, label = round(AnnualReturn, 1)),\n              color = return_color, vjust = 1.5, size = 3) +\n    scale_color_manual(values = c(&quot;Dividend Yield&quot; = dividend_color,\n                                  &quot;Annual Return&quot; = return_color)) +\n    labs(y = &quot;Rate (%)&quot;, color = &quot;Metrics&quot;) +\n    scale_y_continuous(expand = expansion(mult = c(0.05, 0.1))) + # add top margin\n    theme_minimal() + #\n    theme(legend.position = &quot;bottom&quot;)\n  \n  Create a # volatility chart\n  p3 &lt;- ggplot(df, aes(x = Year, y = VolatilityRange)) +\n    geom_line(color = volatility_color, size = 1) +\n    geom_point(color = volatility_color) +\n    geom_text(aes(label = round(VolatilityRange, 0)),\n              vjust = -0.6, size = 3, color = volatility_color) + # Adjust the vjust value\n    labs(y = &quot;Volatility Range (High-Low)&quot;) +\n    scale_y_continuous(labels = scales::comma,\n                       expand = expansion(mult = c(0.05, 0.1))) + # add top margin\n    theme_minimal()\n  \n  Position the # chart\n  gridExtra::grid.arrange(p1, p2, p3, ncol = 1,\n                          heights = c(1.2, 1, 1))\n}\n\n# stock data analysis functions\nanalyze_stocks &lt;- function(stock_data, stocks_info) {\n  results &lt;- lapply(1:nrow(stocks_info), function(i) {\n    if (is.null(stock_data[[i]])) return(NULL)\n    \n    symbol &lt;- stocks_info$symbol[i]\n    data &lt;- stock_data[[i]]\n    \n    df &lt;- data.frame(\n      Close = as.numeric(data[,4]),\n      Dividends = as.numeric(data[,6])\n    )\n    \n    list(\n      StockName = stocks_info$name[i],\n      Symbol = symbol,\n      MeanPrice = mean(df$Close, na.rm = TRUE),\n      PriceStdDev = sd(df$Close, na.rm = TRUE),\n      MeanDividend = mean(df$Dividends, na.rm = TRUE),\n      TotalReturn = (tail(df$Close, 1) \/ df$Close[1] - 1) * 100\n    )\n  })\n  \n  results &lt;- results[!sapply(results, is.null)] # remove NULLs\n  do.call(rbind, lapply(results, as.data.frame))\n}\n\n# Main execution\nplan(multisession) # Set up parallel sessions\n\nCollect and visualize # data\nstock_data &lt;- future_map(1:nrow(stocks_info), function(i) {\n  symbol &lt;- stocks_info$symbol[i]\n  data &lt;- get_stock_data(symbol)\n  if (!is.null(data)) {\n    plot_stock_data(data, stocks_info[i,])\n  }\n  data\n})\n\nOutput the results of the # analysis\nanalysis_results &lt;- analyze_stocks(stock_data, stocks_info)\nprint(analysis_results)<\/code><\/pre>","protected":false},"excerpt":{"rendered":"<p>Hello, everyone! Today we're here with a really exciting topic: dividend investing...<\/p>","protected":false},"author":3,"featured_media":3706,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_kad_blocks_custom_css":"","_kad_blocks_head_custom_js":"","_kad_blocks_body_custom_js":"","_kad_blocks_footer_custom_js":"","_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","footnotes":""},"categories":[6],"tags":[174,509,517,516,512],"class_list":["post-3680","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-r-coding","tag-r-","tag-509","tag-517","tag-516","tag-512"],"taxonomy_info":{"category":[{"value":6,"label":"\uc54c(R)"}],"post_tag":[{"value":174,"label":"R \ud504\ub85c\uadf8\ub798\ubc0d"},{"value":509,"label":"\ubc30\ub2f9\uc8fc \ud22c\uc790"},{"value":517,"label":"\uc7ac\ud14c\ud06c"},{"value":516,"label":"\uc8fc\uc2dd \ubd84\uc11d"},{"value":512,"label":"\ud55c\uad6d \uc99d\uc2dc"}]},"featured_image_src_large":["https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/11\/\ubc30\ub2f9\uc8fc-\ud22c\uc790-post-thumbnail-600x600.jpg",600,600,true],"author_info":{"display_name":"TERE","author_link":"https:\/\/secondlife.lol\/en\/author\/tere\/"},"comment_info":0,"category_info":[{"term_id":6,"name":"\uc54c(R)","slug":"r-coding","term_group":0,"term_taxonomy_id":6,"taxonomy":"category","description":"","parent":20,"count":61,"filter":"raw","cat_ID":6,"category_count":61,"category_description":"","cat_name":"\uc54c(R)","category_nicename":"r-coding","category_parent":20}],"tag_info":[{"term_id":174,"name":"R \ud504\ub85c\uadf8\ub798\ubc0d","slug":"r-%ed%94%84%eb%a1%9c%ea%b7%b8%eb%9e%98%eb%b0%8d","term_group":0,"term_taxonomy_id":174,"taxonomy":"post_tag","description":"","parent":0,"count":15,"filter":"raw"},{"term_id":509,"name":"\ubc30\ub2f9\uc8fc \ud22c\uc790","slug":"%eb%b0%b0%eb%8b%b9%ec%a3%bc-%ed%88%ac%ec%9e%90","term_group":0,"term_taxonomy_id":509,"taxonomy":"post_tag","description":"","parent":0,"count":2,"filter":"raw"},{"term_id":517,"name":"\uc7ac\ud14c\ud06c","slug":"%ec%9e%ac%ed%85%8c%ed%81%ac","term_group":0,"term_taxonomy_id":517,"taxonomy":"post_tag","description":"","parent":0,"count":1,"filter":"raw"},{"term_id":516,"name":"\uc8fc\uc2dd \ubd84\uc11d","slug":"%ec%a3%bc%ec%8b%9d-%eb%b6%84%ec%84%9d","term_group":0,"term_taxonomy_id":516,"taxonomy":"post_tag","description":"","parent":0,"count":1,"filter":"raw"},{"term_id":512,"name":"\ud55c\uad6d \uc99d\uc2dc","slug":"%ed%95%9c%ea%b5%ad-%ec%a6%9d%ec%8b%9c","term_group":0,"term_taxonomy_id":512,"taxonomy":"post_tag","description":"","parent":0,"count":2,"filter":"raw"}],"_links":{"self":[{"href":"https:\/\/secondlife.lol\/en\/wp-json\/wp\/v2\/posts\/3680","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/secondlife.lol\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/secondlife.lol\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/secondlife.lol\/en\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/secondlife.lol\/en\/wp-json\/wp\/v2\/comments?post=3680"}],"version-history":[{"count":11,"href":"https:\/\/secondlife.lol\/en\/wp-json\/wp\/v2\/posts\/3680\/revisions"}],"predecessor-version":[{"id":3769,"href":"https:\/\/secondlife.lol\/en\/wp-json\/wp\/v2\/posts\/3680\/revisions\/3769"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/secondlife.lol\/en\/wp-json\/wp\/v2\/media\/3706"}],"wp:attachment":[{"href":"https:\/\/secondlife.lol\/en\/wp-json\/wp\/v2\/media?parent=3680"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/secondlife.lol\/en\/wp-json\/wp\/v2\/categories?post=3680"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/secondlife.lol\/en\/wp-json\/wp\/v2\/tags?post=3680"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}