{"id":3918,"date":"2024-12-10T12:44:39","date_gmt":"2024-12-10T03:44:39","guid":{"rendered":"https:\/\/secondlife.lol\/?p=3918"},"modified":"2024-12-13T20:55:41","modified_gmt":"2024-12-13T11:55:41","slug":"krw-usd-exchange-rate-30-years","status":"publish","type":"post","link":"https:\/\/secondlife.lol\/en\/krw-usd-exchange-rate-30-years\/","title":{"rendered":"30 Years of Korean Won Exchange Rate Graphs: The Volatility of the Korean Economy at a Glance!"},"content":{"rendered":"<p class=\"wp-block-paragraph\">The KRW exchange rate is an important indicator of the interaction between the Korean economy and the global economy. <a href=\"https:\/\/secondlife.lol\/en\/martial-law-exchange-rate-r-visualization\/\">Dollar exchange rate graph<\/a> Looking at the 30-year change, you can see that there were dramatic swings at certain times.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this post, we'll use the <a href=\"http:\/\/python.org\" target=\"_blank\" rel=\"noopener\">Python<\/a>and the Yahoo Finance API to get 30 years of data for a graph of the dollar exchange rate and plot the major fluctuations. This will help us visually understand the impact of economic shocks.<\/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<style>.kb-image3918_bafa8f-e3 .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-image3918_bafa8f-e3 img.kb-img, .kb-image3918_bafa8f-e3 .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-image3918_bafa8f-e3\"><figure class=\"aligncenter size-full\"><img decoding=\"async\" width=\"1173\" height=\"630\" src=\"https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/12\/\ub2e4\uc6b4\ub85c\ub4dc.jpg\" alt=\"\uc6d0\ub2ec\ub7ec \ud658\uc728 \uadf8\ub798\ud504 30\ub144 \uadf8\ub9bc\" class=\"kb-img wp-image-3919\" srcset=\"https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/12\/\ub2e4\uc6b4\ub85c\ub4dc.jpg 1173w, https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/12\/\ub2e4\uc6b4\ub85c\ub4dc-300x161.jpg 300w, https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/12\/\ub2e4\uc6b4\ub85c\ub4dc-600x322.jpg 600w, https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/12\/\ub2e4\uc6b4\ub85c\ub4dc-768x412.jpg 768w, https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/12\/\ub2e4\uc6b4\ub85c\ub4dc-18x10.jpg 18w\" sizes=\"(max-width: 1173px) 100vw, 1173px\" \/><figcaption>( 30 Years of Dollar Exchange Rate Graph )<\/figcaption><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">1. Prepare to collect data<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To get Yahoo Finance data in Python, you can use the <code>yfinance<\/code> library. These libraries provide historical data for free, and you can get started with a simple setup. Additionally <code>pandas-datareader<\/code>I <code>FinanceDataReader<\/code> You can also utilize other libraries like<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pip install yfinance matplotlib<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">After installation, use the code below to import exchange rate data from 1994 to 2024 (<kbd>My goal is to get and visualize 30 years of graphs of the USD exchange rate, but unfortunately Yahoo Finance doesn't seem to have data back to 2004 or so.<\/kbd>)<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. collect and visualize exchange rate data (full code)<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>import yfinance as yf\nimport matplotlib.pyplot as plt\nfrom datetime import datetime\n\n# Define currency pair and date range\ncurrency_pair = \"USDKRW=X\"\nstart_date = \"1994-01-01\"\nend_date = \"2024-12-31\"\n\n# Download data from Yahoo Finance\ndata = yf.download(currency_pair, start=start_date, end=end_date)\n\n# Plot exchange rate data\nplt.figure(figsize=(14, 7))\nplt.plot(data.index, data['Close'], label=\"KRW\/USD Exchange Rate\", color=\"steelblue\")\n\n# Highlight major economic events\nevents = {\n    \"1997-12-01\": \"IMF Crisis\",\n    \"2008-09-15\": \"Global Financial Crisis\",\n    \"2020-03-01\": \"COVID-19 Pandemic\",\n    \"2022-02-24\": \"Russia-Ukraine War\"\n}\n\nfor date, label in events.items():\n    plt.axvline(datetime.strptime(date, \"%Y-%m-%d\"), color=\"red\", linestyle=\"--\", alpha=0.7)\n    plt.text(datetime.strptime(date, \"%Y-%m-%d\"), plt.ylim()[1] * 0.9, label, color=\"red\")\n\n# Add moving average line\ndata['MA50'] = data['Close'].rolling(window=50).mean()\nplt.plot(data.index, data['MA50'], label=\"50-Day Moving Average\", color=\"orange\")\n\n# Highlight max and min exchange rates\nmax_rate = data['Close'].max()\nmin_rate = data['Close'].min()\nmax_date = data['Close'].idxmax()\nmin_date = data['Close'].idxmin()\n\nplt.scatter(max_date, max_rate.item(), color='green', label=f'Max Rate: {max_rate.item():.2f}', zorder=5)\nplt.scatter(min_date, min_rate.item(), color='purple', label=f'Min Rate: {min_rate.item():.2f}', zorder=5)\n\n# Customize plot\nplt.title(\"KRW\/USD Exchange Rate Over 30 Years\", fontsize=16)\nplt.xlabel(\"Year\", fontsize=12)\nplt.ylabel(\"Exchange Rate (KRW\/USD)\", fontsize=12)\nplt.legend()\nplt.grid(True)\nplt.show()<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">3. Analyze key times of change<\/h2>\n\n\n<style>.kb-image3918_17f657-35 .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-image3918_17f657-35 img.kb-img, .kb-image3918_17f657-35 .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-image3918_17f657-35\"><figure class=\"aligncenter size-full\"><img decoding=\"async\" width=\"1200\" height=\"760\" src=\"https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/12\/image-1-5.jpg\" alt=\"\uc6d0\ub2ec\ub7ec \ud658\uc728 \uadf8\ub798\ud504 30\ub144\uce58 \uae30\uac04 \uc911 \uc8fc\uc694 \uc0ac\uac74\" class=\"kb-img wp-image-3938\" srcset=\"https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/12\/image-1-5.jpg 1200w, https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/12\/image-1-5-300x190.jpg 300w, https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/12\/image-1-5-600x380.jpg 600w, https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/12\/image-1-5-768x486.jpg 768w, https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/12\/image-1-5-18x12.jpg 18w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><figcaption>(Key Events in 30 Years of Dollar Exchange Rate Graphs)<\/figcaption><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>IMF foreign exchange crisis (1997-1998):<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>At the end of 1997, the IMF foreign exchange crisis caused the exchange rate to skyrocket, with the value of the Korean won plummeting to over 2,000 won.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Global Financial Crisis (2008):<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>In 2008, the bankruptcy of Lehman Brothers and the onset of the global financial crisis caused the value of the Korean Won to fall again.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Coronavirus pandemic (2020):<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>In early 2020, the coronavirus pandemic destabilized financial markets around the world, and the exchange rate of the Korean Won fluctuated dramatically.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Russia-Ukraine War (2022):<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The outbreak of the Russia-Ukraine war in 2022 created uncertainty in the global economy, and the value of the Korean won weakened again.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">4. 30-year visualization results for the USD exchange rate graph<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Running the code above will generate the graph at the beginning of this post, which displays data on the exchange rate of the Korean Won against the US Dollar from 2004 to 2024. The graph shows when major events occurred as red lines to help you visually understand the reasons for the fluctuations. It also shows the maximum and minimum exchange rates as green and purple dots, respectively, so you can see the corresponding numbers.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">5. Organize<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The 30-year data for the Korean won-dollar exchange rate graph provides an important resource for understanding the past and predicting the future of the Korean economy. The main causes of exchange rate fluctuations have been foreign exchange crises, financial crises, pandemics, and geopolitical events.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Python and the Yahoo Finance API make it easy to collect and analyze historical data. We recommend using this code to analyze longer periods of data or other currency data.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"># Code Explained: Collect and visualize exchange rate data<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>import yfinance as yf\nimport matplotlib.pyplot as plt\nfrom datetime import datetime<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>yfinance<\/code> library to the <code>yf<\/code>to import Yahoo Finance data.<\/li>\n\n\n\n<li><code>matplotlib.pyplot<\/code>to <code>plt<\/code>to draw graphs for data visualization.<\/li>\n\n\n\n<li><code>datetime<\/code> module to cover date formats.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>currency_pair = \"USDKRW=X\"\nstart_date = \"1994-01-01\"\nend_date = \"2024-12-31\"<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>currency_pair<\/code> variable to store the symbol for the yuan-dollar exchange rate.<\/li>\n\n\n\n<li><code>start_date<\/code>and <code>end_date<\/code>to set the start and end dates of the data collection period.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>data = yf.download(currency_pair, start=start_date, end=end_date)<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>yfinance<\/code>The <code>download<\/code> function to download exchange rate data for a set period of time.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>plt.figure(figsize=(14, 7))\nplt.plot(data.index, data['Close'], label=\"KRW\/USD Exchange Rate\", color=\"steelblue\")<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Create a new graph and set its size.<\/li>\n\n\n\n<li>The date of the exchange rate data (<code>index<\/code>) and the closing price (<code>Close<\/code>) to draw a line graph.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>events = {\n    \"1997-12-01\": \"IMF Crisis\",\n    \"2008-09-15\": \"Global Financial Crisis\",\n    \"2020-03-01\": \"COVID-19 Pandemic\",\n    \"2022-02-24\": \"Russia-Ukraine War\"\n}<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Define major economic events and their dates as a dictionary.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>for date, label in events.items():\n    plt.axvline(datetime.strptime(date, \"%Y-%m-%d\"), color=\"red\", linestyle=\"--\", alpha=0.7)\n    plt.text(datetime.strptime(date, \"%Y-%m-%d\"), plt.ylim()[1] * 0.9, label, color=\"red\")<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Draw a vertical line to the date of each event to display it on the graph.<\/li>\n\n\n\n<li>Add the case name as text in the appropriate location.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>data['MA50'] = data['Close'].rolling(window=50).mean()\nplt.plot(data.index, data['MA50'], label=\"50-Day Moving Average\", color=\"orange\")<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Calculate a 50-day moving average line and add it to the data.<\/li>\n\n\n\n<li>Add a moving average line to the graph to visualize the trend.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>max_rate = data['Close'].max()\nmin_rate = data['Close'].min()\nmax_date = data['Close'].idxmax()\nmin_date = data['Close'].idxmin()\n\nplt.scatter(max_date, max_rate.item(), color='green', label=f'Max Rate: {max_rate.item():.2f}', zorder=5)\nplt.scatter(min_date, min_rate.item(), color='purple', label=f'Min Rate: {min_rate.item():.2f}', zorder=5)<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Calculate the maximum and minimum exchange rate values and find the corresponding dates.<\/li>\n\n\n\n<li>The maximum value is highlighted with a green dot and the minimum with a purple dot.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>plt.title(\"KRW\/USD Exchange Rate Over 30 Years\", fontsize=16)\nplt.xlabel(\"Year\", fontsize=12)\nplt.ylabel(\"Exchange Rate (KRW\/USD)\", fontsize=12)\nplt.legend()\nplt.grid(True)\nplt.show()<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Set the graph title and axis labels.<\/li>\n\n\n\n<li>Add a legend and enable the grid to make it more readable.<\/li>\n\n\n\n<li>Display the graph on the screen.<\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>The Korean won exchange rate is an important indicator of the interaction between the Korean economy and the global economy...<\/p>","protected":false},"author":3,"featured_media":3977,"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":[3],"tags":[34,589,587,588],"class_list":["post-3918","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python-coding","tag-python","tag-589","tag-587","tag-588"],"taxonomy_info":{"category":[{"value":3,"label":"\ud30c\uc774\uc36c(Python)"}],"post_tag":[{"value":34,"label":"python"},{"value":589,"label":"\uacbd\uc81c\uc704\uae30"},{"value":587,"label":"\uc6d0\ub2ec\ub7ec\ud658\uc728"},{"value":588,"label":"\ud658\uc728\ubd84\uc11d"}]},"featured_image_src_large":["https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/12\/\uc6d0\ub2ec\ub7ec-\ud658\uc728-\uadf8\ub798\ud504-30\ub144-\ud3ec\uc2a4\ud2b8-\uc378\ub124\uc77c-1-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":3,"name":"\ud30c\uc774\uc36c(Python)","slug":"python-coding","term_group":0,"term_taxonomy_id":3,"taxonomy":"category","description":"","parent":20,"count":116,"filter":"raw","cat_ID":3,"category_count":116,"category_description":"","cat_name":"\ud30c\uc774\uc36c(Python)","category_nicename":"python-coding","category_parent":20}],"tag_info":[{"term_id":34,"name":"python","slug":"python","term_group":0,"term_taxonomy_id":34,"taxonomy":"post_tag","description":"","parent":0,"count":21,"filter":"raw"},{"term_id":589,"name":"\uacbd\uc81c\uc704\uae30","slug":"%ea%b2%bd%ec%a0%9c%ec%9c%84%ea%b8%b0","term_group":0,"term_taxonomy_id":588,"taxonomy":"post_tag","description":"","parent":0,"count":1,"filter":"raw"},{"term_id":587,"name":"\uc6d0\ub2ec\ub7ec\ud658\uc728","slug":"%ec%9b%90%eb%8b%ac%eb%9f%ac%ed%99%98%ec%9c%a8","term_group":0,"term_taxonomy_id":587,"taxonomy":"post_tag","description":"","parent":0,"count":1,"filter":"raw"},{"term_id":588,"name":"\ud658\uc728\ubd84\uc11d","slug":"%ed%99%98%ec%9c%a8%eb%b6%84%ec%84%9d","term_group":0,"term_taxonomy_id":589,"taxonomy":"post_tag","description":"","parent":0,"count":1,"filter":"raw"}],"_links":{"self":[{"href":"https:\/\/secondlife.lol\/en\/wp-json\/wp\/v2\/posts\/3918","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=3918"}],"version-history":[{"count":5,"href":"https:\/\/secondlife.lol\/en\/wp-json\/wp\/v2\/posts\/3918\/revisions"}],"predecessor-version":[{"id":3939,"href":"https:\/\/secondlife.lol\/en\/wp-json\/wp\/v2\/posts\/3918\/revisions\/3939"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/secondlife.lol\/en\/wp-json\/wp\/v2\/media\/3977"}],"wp:attachment":[{"href":"https:\/\/secondlife.lol\/en\/wp-json\/wp\/v2\/media?parent=3918"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/secondlife.lol\/en\/wp-json\/wp\/v2\/categories?post=3918"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/secondlife.lol\/en\/wp-json\/wp\/v2\/tags?post=3918"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}