yahooニュース 産経新聞、首相「腹を割って意見交換」 7、8日に訪韓し尹大統領と会談 岸田文雄首相は1日(日本時間2日)、7~8日の日程で韓国を訪問し、尹錫悦(ユン・ソンニョル)大統領と会談する方向で調整(ちょうせい)していると明らかにした。訪問先(ほうもんさき)のガーナで記者団の取材に答えた。首相は尹氏が3月に来日(らいにち)した際(さい)、首脳同士が相互(そうご)に訪問する「シャトル外交」の再開(さいかい)で合意(ごうい)しており、その第1弾(いちだん)となる。 続いて、日本政府は4月28日に韓国を輸出手続き簡略化などの優遇措置の対象国となる「グループA(旧ホワイト国)」に再指定(さいしてい)する方針を発表したが、首相の訪韓(ほうかん)で成果(せいか)を示(しめ)せるかが焦点(しょうてん)になると書いていました。 日韓関係が改善されているようでうれしい記事でした。
In statistics, a moving average is a calculation used to analyze data points by creating a series of averages of different subsets of the full data set. In finance, a moving average (MA) is a stock indicator that is commonly used in technical analysis.
Let find Moving Average Line followed by previous market stock prices.
Module Import
from urllib.request import * from bs4 import * import requests import re import pandas as pd import matplotlib.pyplot as plt import numpy as np
in previous analysis (ref. https://tomtomplace.blogspot.com/2022/05/web-crawling.html), we've already get object variable 'pList', which is closing market stock price of Samsung electronic, and now we used to its data, we are going to make moving average price using Queue ADT.
Queue ADT
Queue is a linear data structure in which the insertion and deletion operations are performed at two different ends. In a queue data structure, adding and removing elements are performed at two different positions. The insertion is performed at one end and deletion is performed at another end. (ref. btechsmartclass) We can find 5 days moving average price using following method :
numMA_5 = 5 mList_5 = [] Q_5 = [] mSum_5 = pList[0] * numMA_5
for i in range(numMA_5) :
Q_5.append(pList[0])
for M in pList :
mSum_5 = mSum_5 - Q_5.pop(0)
mSum_5 += M
mList_5.append(mSum_5/numMA_5)
Q_5.append(M)
numMA_5 is a number how much interval days we want to set, mList_5 is such container saving average price analyzed, and Q_5 is temporary container to make average price. As using similar method, we can make 20 days moving average price and its of 60 days to use following codes :
def makeMA(pList): numMA_5 = 5 mList_5 = [] Q_5 = [] mSum_5 = pList[0] * numMA_5 numMA_20 = 20 mList_20 = [] Q_20 = [] mSum_20 = pList[0] * numMA_20 numMA_60 = 60 mList_60 = [] Q_60 = [] mSum_60 = pList[0] * numMA_60 for i in range(numMA_5) : Q_5.append(pList[0]) for i in range(numMA_20) : Q_20.append(pList[0]) for i in range(numMA_60) : Q_60.append(pList[0]) for M in pList : mSum_5 = mSum_5 - Q_5.pop(0) mSum_5 += M mList_5.append(mSum_5/numMA_5) Q_5.append(M) mSum_20 = mSum_20 - Q_20.pop(0) mSum_20 += M mList_20.append(mSum_20/numMA_20) Q_20.append(M) mSum_60 = mSum_60 - Q_60.pop(0) mSum_60 += M mList_60.append(mSum_60/numMA_60) Q_60.append(M) drawGraph(pList,mList_5,mList_20,mList_60) return mList_5, mList_20, mList_60
makeMA() is the function which makes moving average price whose interval is 5, 20, 60 days.
Visualization
To visualize our analyzed data, we need to make the function who draw a graph. From the above code, the function named drawGraph is chain-function which is make MA price graph.
def drawGraph(pList,mList_5,mList_20,mList_60):
graph = pd.Series(pList, index=range(len(pList)))
graph_m5 = pd.Series(mList_5, index=range(len(pList)))
graph_m20 = pd.Series(mList_20, index=range(len(pList)))
graph_m60 = pd.Series(mList_60, index=range(len(pList)))
plt.style.use('seaborn')
plt.plot(graph, label = 'stock price')
plt.plot(graph_m5, label = '5MA')
plt.plot(graph_m20, label = '20MA')
plt.plot(graph_m60, label = '60MA')
plt.legend(loc = 'upper left')
plt.xlabel('Days') plt.ylabel('Price') plt.grid(True) plt.show()
잘 보고 갑니다. 꺼어어어억
답글삭제