1

我对 python 非常陌生,我正在尝试从从 tradestation 下载的 CSV 文件生成烛台图。csv中的数据是Symbol, Date, O, H, L, C, Volume

我正在使用 matplot lib,并且我创建了一个数据框来读取下面链接中显示的 CSV,其中 csv 路径位于我的 C 驱动器中的一个文件夹中。

import datetime as dt
import matplotlib.pyplot as plt
from matplotlib import style
import pandas as pd
#from sentdex matplot lib candle tutorial
import matplotlib.dates as mdates
import matplotlib.ticker as mticker
from matplotlib.finance import candlestick_ohlc

start = dt.datetime(2000,1,1)
end = dt.datetime(2017,12,31)

df = pd.read_csv('C:\TS\spy.CSV', parse_dates=True, index_col=1)

以下代码仅适用于在十个数据周期内从收盘数据生成烛台,但我需要一个每日烛台并且无法弄清楚。

#Candle Code Here
df_ohlc = df['Close'].resample('10D').ohlc()
print(df_ohlc.head())
df_ohlc = df_ohlc.reset_index()
#MDATES: mdates type that...is mostly just a pain in the butt, but that's the date type for matplotlib graphs
df_ohlc['Date'] = df_ohlc['Date'].map(mdates.date2num)
#df_ohlc['Open'] = df_ohlc['Open']
#ax1.xaxis_date: What this does for us is converts the axis from the raw mdate numbers to dates.
ax1.xaxis_date()
candlestick_ohlc(ax1, df_ohlc.values, width=3, colorup='g')

任何帮助是极大的赞赏。非常感谢。

4

0 回答 0