usa 종목 ㅊ추가
This commit is contained in:
@@ -581,9 +581,10 @@ class AnalyzerSqlite:
|
|||||||
self.writeFile(type, CODE, NAME, top, stock, state)
|
self.writeFile(type, CODE, NAME, top, stock, state)
|
||||||
|
|
||||||
# 0_bolingerband 하단
|
# 0_bolingerband 하단
|
||||||
if len(close) > 60 and bolingerband_lower[0] is not None and close[0] < bolingerband_lower[0]:
|
if len(close) > 60:
|
||||||
type = "참고_0_bolingerband 하단"
|
if bolingerband_lower[0] is not None and close[0] < bolingerband_lower[0]:
|
||||||
self.writeFile(type, CODE, NAME, top, stock, state)
|
type = "참고_0_bolingerband 하단"
|
||||||
|
self.writeFile(type, CODE, NAME, top, stock, state)
|
||||||
|
|
||||||
# 0_260일 위치 에너지가 10% 미만
|
# 0_260일 위치 에너지가 10% 미만
|
||||||
if len(close) > 5 and positionalEnergy1 is not None and positionalEnergy1 < 0.1:
|
if len(close) > 5 and positionalEnergy1 is not None and positionalEnergy1 < 0.1:
|
||||||
@@ -735,10 +736,11 @@ class AnalyzerSqlite:
|
|||||||
type = "6_거래량 7배 이상_20일선_위_기준선"
|
type = "6_거래량 7배 이상_20일선_위_기준선"
|
||||||
self.writeFile(type, CODE, NAME, top, stock, state)
|
self.writeFile(type, CODE, NAME, top, stock, state)
|
||||||
|
|
||||||
if (len(close) > 60 and (bolingerband_lower[0] is not None and bolingerband_lower[1] is not None) and
|
if len(close) > 60:
|
||||||
|
if ((bolingerband_lower[0] is not None and bolingerband_lower[1] is not None) and
|
||||||
close[0] > bolingerband_lower[0] and close[1] < bolingerband_lower[1]):
|
close[0] > bolingerband_lower[0] and close[1] < bolingerband_lower[1]):
|
||||||
type = "7_bolingerband 하단 돌파 상승"
|
type = "7_bolingerband 하단 돌파 상승"
|
||||||
self.writeFile(type, CODE, NAME, top, stock, state)
|
self.writeFile(type, CODE, NAME, top, stock, state)
|
||||||
|
|
||||||
if len(close) > 50:
|
if len(close) > 50:
|
||||||
if avg5[0]<avg20[0]<avg60[0]:
|
if avg5[0]<avg20[0]<avg60[0]:
|
||||||
|
|||||||
@@ -38,11 +38,11 @@ metaCrawler.crawl_exchange(stockFileName)
|
|||||||
print("\n[원유 (WTI), 국제금, COPPER, NATURALGAS, CORN, SOYBEAN]")
|
print("\n[원유 (WTI), 국제금, COPPER, NATURALGAS, CORN, SOYBEAN]")
|
||||||
metaCrawler.crawl_meterials(stockFileName)
|
metaCrawler.crawl_meterials(stockFileName)
|
||||||
|
|
||||||
|
|
||||||
print("\n[종목 다운로드]")
|
print("\n[종목 다운로드]")
|
||||||
stockCrawler = StockCrawler()
|
stockCrawler = StockCrawler()
|
||||||
stockCrawler.crawl_etf_stocks(stockFileName)
|
stockCrawler.crawl_etf_stocks(stockFileName)
|
||||||
stockCrawler.crawl_stocks(stockFileName)
|
stockCrawler.crawl_stocks(stockFileName)
|
||||||
|
stockCrawler.crawl_usa_stocks(stockFileName)
|
||||||
|
|
||||||
print("\n[종목 분석]")
|
print("\n[종목 분석]")
|
||||||
# S: 분석까지 진행
|
# S: 분석까지 진행
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
# https://bigdata-sk.tistory.com/10
|
# https://bigdata-sk.tistory.com/10
|
||||||
|
|
||||||
|
import os
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
import re
|
import re
|
||||||
import json
|
import json
|
||||||
@@ -7,6 +8,7 @@ import sqlite3
|
|||||||
import requests
|
import requests
|
||||||
from time import sleep
|
from time import sleep
|
||||||
import time
|
import time
|
||||||
|
from pandas_datareader import data as pdr
|
||||||
|
|
||||||
# 닐짜 형식으로 바뀐 this_date값을 확인 가능
|
# 닐짜 형식으로 바뀐 this_date값을 확인 가능
|
||||||
# 읽어온 날짜 정보를 date형식으로 바꿀 일이 계속 생기므로 이 기능을 함수로 정의해줌.
|
# 읽어온 날짜 정보를 date형식으로 바꿀 일이 계속 생기므로 이 기능을 함수로 정의해줌.
|
||||||
@@ -203,6 +205,78 @@ class StockCrawler:
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def crawl_usa_stocks(self, inFileName):
|
||||||
|
tableName = 'stock'
|
||||||
|
conn = sqlite3.connect(inFileName)
|
||||||
|
cursor = conn.cursor()
|
||||||
|
|
||||||
|
# 테이블 생성
|
||||||
|
cursor.execute("CREATE TABLE IF NOT EXISTS " + tableName + " (CODE text, NAME text, ymd text, close REAL, diff REAL, open REAL, high REAL, low REAL, volume REAL)")
|
||||||
|
|
||||||
|
# 키 생성
|
||||||
|
create_key = "CREATE INDEX IF NOT EXISTS " + tableName + "_idx on " + tableName + " (CODE, ymd) "
|
||||||
|
cursor.execute(create_key)
|
||||||
|
|
||||||
|
conn.commit()
|
||||||
|
cursor.close()
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
start_time = time.time()
|
||||||
|
|
||||||
|
|
||||||
|
pd.options.display.float_format = '{:.4f}'.format
|
||||||
|
pd.set_option('display.max_columns', None)
|
||||||
|
|
||||||
|
usa_stock_code = ['SQQQ','TQQQ','SCO','UCO','GLL','UGL','DQ','EBAY','NTAP','VZ','AAPL','MSFT','GOOG','NVDA',
|
||||||
|
'FB','ASML','AVGO','COST','INTC','AMD','QCOM','HON','VZ','EBAY','TSM','V','WMT','BABA','KO',
|
||||||
|
'DIS','T']
|
||||||
|
item_name = {'SQQQ': 'ProShares UltraPro Short QQQ','TQQQ': 'ProShares UltraPro QQQ','SCO': 'ProShares UltraShort Bloomberg Crude Oil',
|
||||||
|
'UCO': 'ProShares Ultra Bloomberg Crude Oil','GLL': 'ProShares UltraShort Gold','UGL': 'ProShares Ultra Gold',
|
||||||
|
'DQ': 'DAQO New Energy Corp.','EBAY': 'eBay Inc.','NTAP': 'NetApp, Inc.','VZ': 'Verizon Communications Inc.',
|
||||||
|
'AAPL': 'Apple Inc.','MSFT': 'Microsoft Corporation','GOOG': 'Alphabet Inc.','NVDA': 'NVIDIA Corporation',
|
||||||
|
'FB': 'Meta Platforms, Inc.', 'ASML': 'ASML Holding','AVGO': 'Broadcom Inc.','COST': 'Costco Wholesale Corporation',
|
||||||
|
'INTC': 'Intel Corporation','AMD': 'Advanced Micro Devices, Inc.','QCOM': 'QUALCOMM Incorporated',
|
||||||
|
'HON': 'Honeywell International Inc.','VZ': 'Verizon Communications Inc.','EBAY': 'eBay Inc.',
|
||||||
|
'TSM': 'Taiwan Semiconductor Manufacturing','V': 'Visa Inc.','WMT': 'Walmart Inc.','BABA': 'Alibaba Group Holding',
|
||||||
|
'KO': 'Coca-Cola','DIS': 'Walt Disney','T': 'AT&T Inc.'}
|
||||||
|
df_price = pd.DataFrame(columns=usa_stock_code)
|
||||||
|
for ticker in usa_stock_code:
|
||||||
|
df_price[ticker] = pdr.get_data_yahoo(ticker)['Adj Close']
|
||||||
|
df_usa_stock = df_price.dropna(axis=0)
|
||||||
|
|
||||||
|
for idx, item_code in enumerate(df_usa_stock):
|
||||||
|
stock_data = []
|
||||||
|
stock = df_usa_stock[item_code]
|
||||||
|
stockDict = stock.to_dict()
|
||||||
|
stockList = list(stock.to_dict())
|
||||||
|
for i, ymd in enumerate(stockDict):
|
||||||
|
if i > 0:
|
||||||
|
diff = stockDict[ymd] - stockDict[stockList[i-1]]
|
||||||
|
else:
|
||||||
|
diff = stockDict[ymd]
|
||||||
|
stock_data.append({'CODE':item_code, 'NAME':item_name[item_code], 'ymd': ymd.strftime('%Y.%m.%d'), 'close': round(stockDict[ymd], 2), 'diff': round(diff, 2), 'open': round(stockDict[ymd], 2), 'high': round(stockDict[ymd], 2), 'low': round(stockDict[ymd], 2), 'volume': 0})
|
||||||
|
|
||||||
|
stock_data = reversed(stock_data)
|
||||||
|
|
||||||
|
conn = sqlite3.connect(inFileName)
|
||||||
|
cursor = conn.cursor()
|
||||||
|
for item in stock_data:
|
||||||
|
cursor.execute('SELECT * FROM ' + tableName + ' WHERE CODE=? and ymd=?', (item["CODE"],item['ymd'],))
|
||||||
|
result = cursor.fetchone()
|
||||||
|
if result == None:
|
||||||
|
cursor.execute("INSERT INTO " + tableName + "(CODE, NAME, ymd, close, diff, open, high, low, volume) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)", (item["CODE"], item["NAME"], item['ymd'], item['close'], item['diff'], item['open'], item['high'], item['low'], item['volume']))
|
||||||
|
#else:
|
||||||
|
# cursor.execute("UPDATE " + tableName + " SET close=?, diff=?, open=?, high=?, low=?, volume=? WHERE CODE=? and ymd=?", (item['close'], item['diff'], item['open'], item['high'], item['low'], item['volume'], stock["CODE"], item['ymd']))
|
||||||
|
|
||||||
|
conn.commit()
|
||||||
|
cursor.close()
|
||||||
|
conn.close()
|
||||||
|
print(idx, item_code, item_name[item_code], (time.time() - start_time), "s")
|
||||||
|
|
||||||
|
start_time = time.time()
|
||||||
|
sleep(0.05)
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
def get_data(self, code, lastDay):
|
def get_data(self, code, lastDay):
|
||||||
url = 'http://finance.naver.com/item/sise_day.nhn?code={code}'.format(code=code.strip())
|
url = 'http://finance.naver.com/item/sise_day.nhn?code={code}'.format(code=code.strip())
|
||||||
@@ -369,4 +443,11 @@ class StockCrawler:
|
|||||||
conn.commit()
|
conn.commit()
|
||||||
cursor.close()
|
cursor.close()
|
||||||
conn.close()
|
conn.close()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
stockCrawler = StockCrawler()
|
||||||
|
|
||||||
|
PROJECT_HOME = os.path.join(os.path.dirname(os.path.join(os.path.dirname(os.path.join(os.path.dirname(os.path.join(os.path.dirname(__file__))))))))
|
||||||
|
stockFileName = PROJECT_HOME + '/resources/stock.db'
|
||||||
|
stockCrawler.crawl_usa_stocks(stockFileName)
|
||||||
|
|||||||
Reference in New Issue
Block a user