本篇記錄一下,製作KD線踩到的雷。
可參考github:Day26_createLine.ipynb
在製作的過程中,發現無法順利地轉換,於是參考:Python-簡單158種技術指標計算和Python-時間序列實作!,才發現我的Dataframe資料太過於奇怪。
於是重新整理一下我的資料。
首先把每個價格都單獨拉出:
for k, d in df.items():
    if k == "ClosePrice":
        close = d
        close.index = pandas.to_datetime(close.index)
    elif k == "OpenPrice":
        open = d
        open.index = pandas.to_datetime(open.index)
    elif k == "HighPrice":
        high = d
        high.index = pandas.to_datetime(high.index)
    elif k == "LowPrice":
        low = d
        low.index = pandas.to_datetime(low.index)
為什麼要拉出來呢?
這是因為如果使用abstract.STOCH需要開高低收等資料,而且是接受series格式,並非Dataframe,因此還要把d直接儲存起來,不能帶日期。其實我們日期去當index,也不應該放進去。
這樣就可以取得乾淨的tsmc的dict囉!