## download M06Aimport pandas as pd
import urllib
from datetime import datetime
from urllib.request import urlretrieve
import time
head = "https://tisvcloud.freeway.gov.tw/history/TDCS/M06A/M06A_"
tail = ".tar.gz"
date_list = pd.date_range(start='1/1/2019', end='12/31/2019')
date_list = pd.to_datetime(pd.Series(date_list), format = "%Y%m%d").astype("str")
date_list = [datetime.strptime(date_list[i], '%Y-%m-%d').strftime('%Y%m%d') for i in range(len(date_list))]
url_list = [head + str(date_list[i]) + tail for i in range(len(date_list))]
for i in range(2):
print(urlretrieve(url_list[i], (date_list[i]+'tar.gz')))
time.sleep(10)
%%time
## new parsing measures--better one
import xml.etree.ElementTree as et
import pandas as pd
import itertools
import glob
import re
from xml.etree.ElementTree import parse
def VDparsing(file):
tree = et.parse(file)
root = tree.getroot()
level1 = [data for data in root.iter('Info')]…
%%time
## 5,10,20,60,240 days average price and breakthrough judge!!
import pandas as pd
from datetime import date, datetime, timedelta
import yfinance as yf
import numpy as np
import time
today = datetime.today().strftime('%Y-%m-%d')
path1 = 'D:/00_我在管院研究所的日子/94_TWSE/財山短訊/'
file1 = 'Stock_list(1090922).csv'
path2 = 'D:/00_我在管院研究所的日子/94_TWSE/財山短訊-均線糾結/'
file2 = today + '均線糾結與突破.xlsx'
count = 0
all_list =…
%%time
## find targets -- with for loop -- 更新追蹤清單後以今日日期存檔
import yfinance as yf
import re
import pandas as pd
import matplotlib.pyplot as plt
import talib
from datetime import date, datetime, timedelta
import time
def climb(ticker_list):
today = datetime.today().strftime('%Y-%m-%d')
yesterday = (date.today() - timedelta(days=1)).strftime('%Y-%m-%d')…
## price track and update -- 每日更新後以昨日日期儲存
import yfinance as yf
import re
import pandas as pd
from datetime import datetime, date, timedelta
today = datetime.today().strftime('%Y-%m-%d')
column_today = datetime.today().strftime('%Y%m%d')
yesterday = (date.today() - timedelta(days=1)).strftime('%Y-%m-%d')
path1 = 'D:/00_我在管院研究所的日子/94_TWSE/財山短訊/'
file1 = yesterday + '-財山短訊.csv'
df = pd.read_csv(path1 + file1)
ob_list = df['股票代號']
new_list = []
for idx, ticker in enumerate(ob_list):
day1 = yf.Ticker(ticker).history(period = '1d')
price = (day1.Close).mean()
volume = (day1.Volume).mean()
ROI = (price - df['收盤價'][idx]) / (df['收盤價'][idx])
if df['當日漲跌'][idx] < 0:
ROI = ROI * (-1)
else:
ROI = ROI
ROI = "{:4.2%}".format(ROI)
info = [price, volume, ROI]
new_list.append(info)
print(ticker + ' is processing')
new_list = pd.DataFrame(new_list, columns = [column_today+'收盤價', column_today+'成交量', column_today+'報酬率'])
update_list = pd.concat([df, new_list], axis = 1)
update_list.to_csv(path1+file1, index = False, encoding = 'utf_8_sig')
print('done!!')
import pandas as pd
import re
def Sticker_list(category):
df = pd.read_html(category)
ticker_list = re.findall("\d+", df[5][0][0])
ticker_list = pd.Series([ticker_list[idx] + '.TW' for idx in range(len(ticker_list))])
return ticker_list
all_S_list = pd.concat([Sticker_list(category) for category in Slist], axis = 1)cols_name = ['Cement', 'Food', 'Plastic', 'Textile', 'EE', 'EA_Cable', 'Chemistry', 'Biomedical', 'Glasses'…

TWSE List

Cement = ‘https://tw.stock.yahoo.com/h/kimosel.php?tse=1&cat=%E6%B0%B4%E6%B3%A5&form=menu&form_id=stock_id&form_name=stock_name&domain=0'
Food = ‘https://tw.stock.yahoo.com/h/kimosel.php?tse=1&cat=%E9%A3%9F%E5%93%81&form=menu&form_id=stock_id&form_name=stock_name&domain=0'
Plastic = ‘https://tw.stock.yahoo.com/h/kimosel.php?tse=1&cat=%E5%A1%91%E8%86%A0&form=menu&form_id=stock_id&form_name=stock_name&domain=0'
Textile = ‘https://tw.stock.yahoo.com/h/kimosel.php?tse=1&cat=%E7%B4%A1%E7%B9%94&form=menu&form_id=stock_id&form_name=stock_name&domain=0'
EE = ‘https://tw.stock.yahoo.com/h/kimosel.php?tse=1&cat=%E9%9B%BB%E6%A9%9F&form=menu&form_id=stock_id&form_name=stock_name&domain=0'
EA_Cable = ‘https://tw.stock.yahoo.com/h/kimosel.php?tse=1&cat=%E9%9B%BB%E5%99%A8%E9%9B%BB%E7%BA%9C&form=menu&form_id=stock_id&form_name=stock_name&domain=0'
Chemistry = ‘https://tw.stock.yahoo.com/h/kimosel.php?tse=1&cat=%E5%8C%96%E5%AD%B8&form=menu&form_id=stock_id&form_name=stock_name&domain=0'
Biomedical = ‘https://tw.stock.yahoo.com/h/kimosel.php?tse=1&cat=%E7%94%9F%E6%8A%80%E9%86%AB%E7%99%82&form=menu&form_id=stock_id&form_name=stock_name&domain=0'
Glasses = ‘https://tw.stock.yahoo.com/h/kimosel.php?tse=1&cat=%E7%8E%BB%E7%92%83&form=menu&form_id=stock_id&form_name=stock_name&domain=0'
Paper = ‘https://tw.stock.yahoo.com/h/kimosel.php?tse=1&cat=%E9%80%A0%E7%B4%99&form=menu&form_id=stock_id&form_name=stock_name&domain=0'
Steel = ‘https://tw.stock.yahoo.com/h/kimosel.php?tse=1&cat=%E9%8B%BC%E9%90%B5&form=menu&form_id=stock_id&form_name=stock_name&domain=0'
Rubber = ‘https://tw.stock.yahoo.com/h/kimosel.php?tse=1&cat=%E6%A9%A1%E8%86%A0&form=menu&form_id=stock_id&form_name=stock_name&domain=0'
Cars = ‘https://tw.stock.yahoo.com/h/kimosel.php?tse=1&cat=%E6%B1%BD%E8%BB%8A&form=menu&form_id=stock_id&form_name=stock_name&domain=0'
Semicon = ‘https://tw.stock.yahoo.com/h/kimosel.php?tse=1&cat=%E5%8D%8A%E5%B0%8E%E9%AB%94&form=menu&form_id=stock_id&form_name=stock_name&domain=0'
Computer = ‘https://tw.stock.yahoo.com/h/kimosel.php?tse=1&cat=%E9%9B%BB%E8%85%A6%E9%80%B1%E9%82%8A&form=menu&form_id=stock_id&form_name=stock_name&domain=0'
Photoelectric = ‘https://tw.stock.yahoo.com/h/kimosel.php?tse=1&cat=%E5%85%89%E9%9B%BB&form=menu&form_id=stock_id&form_name=stock_name&domain=0'
Communicate = ‘https://tw.stock.yahoo.com/h/kimosel.php?tse=1&cat=%E9%80%9A%E4%BF%A1%E7%B6%B2%E8%B7%AF&form=menu&form_id=stock_id&form_name=stock_name&domain=0'
Eparts = ‘https://tw.stock.yahoo.com/h/kimosel.php?tse=1&cat=%E9%9B%BB%E5%AD%90%E9%9B%B6%E7%B5%84%E4%BB%B6&form=menu&form_id=stock_id&form_name=stock_name&domain=0'
Evendors = ‘https://tw.stock.yahoo.com/h/kimosel.php?tse=1&cat=%E9%9B%BB%E5%AD%90%E9%80%9A%E8%B7%AF&form=menu&form_id=stock_id&form_name=stock_name&domain=0'
Itservice = ‘https://tw.stock.yahoo.com/h/kimosel.php?tse=1&cat=%E8%B3%87%E8%A8%8A%E6%9C%8D%E5%8B%99&form=menu&form_id=stock_id&form_name=stock_name&domain=0'
Eothers = ‘https://tw.stock.yahoo.com/h/kimosel.php?tse=1&cat=%E5%85%B6%E5%AE%83%E9%9B%BB%E5%AD%90&form=menu&form_id=stock_id&form_name=stock_name&domain=0'
Construction = ‘https://tw.stock.yahoo.com/h/kimosel.php?tse=1&cat=%E7%87%9F%E5%BB%BA&form=menu&form_id=stock_id&form_name=stock_name&domain=0'
Shipping = ‘https://tw.stock.yahoo.com/h/kimosel.php?tse=1&cat=%E8%88%AA%E9%81%8B&form=menu&form_id=stock_id&form_name=stock_name&domain=0'
Sightseeing =…

%%time
## statick informaiton of VD
import xml.etree.ElementTree as et
import pandas as pd
import itertools
from xml.etree.ElementTree import parse
path = 'D:/00_我在管院研究所的日子/97_ETC資料區/2019VD/'
file = 'vd_info_0000.xml'
tree = et.parse(path + file)
root = tree.getroot()
level1 = [data for data in root.iter('Info')]
key_list = level1[0].keys()
def attrib(key):
temp = pd.DataFrame([level1[i].attrib[key] for i in range(len(level1))], columns = [key])
return temp
df = pd.concat([attrib(key) for key in key_list], axis = 1)
df.to_csv('vdInfo.csv', encoding = 'utf_8_sig', index = False)
df

Ed Chao

Playground for a old student. Records about learning, life and interesting stuff

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store