def __init__(self): super(CereborAGE, self).__init__() dataframe_AUTD = FinanceDataSource.get_data( FinanceDataSource.str_tonghuashun, FinanceDataSource.tonghuashun_AUTD) dataframe_AGTD = FinanceDataSource.get_data( FinanceDataSource.str_tonghuashun, FinanceDataSource.tonghuashun_AGTD) dataframe_AUTD['openinterest'] = 0 dataframe_AGTD['openinterest'] = 0 data_AUTD = bt.feeds.PandasData(dataname=dataframe_AUTD) data_AGTD = bt.feeds.PandasData(dataname=dataframe_AGTD) self.adddata(data_AUTD, name="AUTD") self.adddata(data_AGTD, name="AGTD") # 如下是佣金 self.cerebro.broker.setcommission( # automargin=0.15, # 保证金比例 commission=0.0008, # 手续费,记得是万分之8 leverage = 100/15, # 这个才是真正的杠杆,15%的保证金相当于100 / 15的杠杆 interest=0.073, # 递延费,记得是万分之8, * 365 = 0.073 # mult = 100, # 这个应该是一手是多少克吧, 但是却不成功。 # automargin = -1, # Use param mult * price if automargin < 0 , 不能实现一手是100克。 )
def init_data(self): """封装上数据""" dataframe = FinanceDataSource.get_data( FinanceDataSource.str_tonghuashun, FinanceDataSource.tonghuashun_AGUSDO) dataframe['openinterest'] = 0 data = bt.feeds.PandasData(dataname=dataframe) self.adddata(data)
def __init__(self): super(CerebroAGTD, self).__init__() dataframe = FinanceDataSource.get_data( FinanceDataSource.str_tonghuashun, FinanceDataSource.tonghuashun_AGTD) dataframe['openinterest'] = 0 data = bt.feeds.PandasData(dataname=dataframe) self.adddata(data) # 如下是佣金 self.cerebro.broker.setcommission( # automargin=0.15, # 保证金比例 commission=0.0008, # 手续费,记得是万分之8 leverage = 100/15, # 这个才是真正的杠杆,15%的保证金相当于100 / 15的杠杆 interest=0.073 # 递延费,记得是万分之8, * 365 = 0.073 )
@Last Change: 2017-12-29 21:27:51 @Description : 看看AUTD的zip转向 """ import sys import os sys.path.append( os.path.join(os.path.dirname(os.path.realpath(__file__)), "../../FinanceDataSource")) import FinanceDataSource from zip import get_zip from zip import get_zip_ratio from zip import get_zip_all _data = FinanceDataSource.get_data(FinanceDataSource.str_tonghuashun, FinanceDataSource.tonghuashun_AUTD) _lst = get_zip_all(_data, FinanceDataSource.str_close, 2) print("get_zip_all(_data, FinanceDataSource.str_close, 2)") print(_lst) print(sum(_lst)) print(sum(_lst) / len(_lst)) _lst = get_zip_all(_data, FinanceDataSource.str_close, 1) print("get_zip_all(_data, FinanceDataSource.str_close, 1)") print(_lst) print(sum(_lst)) print(sum(_lst) / len(_lst)) """ 得到如下结果: get_zip_all(_data, FinanceDataSource.str_close, 2)
"""@File Name: ADX_1.py @Author: [email protected] @Created Time:2018-01-13 15:21:48 @Last Change: 2018-01-13 15:21:48 @Description : """ import sys import os sys.path.append( os.path.join(os.path.dirname(os.path.realpath(__file__)), "../../FinanceDataSource")) sys.path.append("../../FinanceDataSource") import FinanceDataSource sys.path.append( os.path.join(os.path.dirname(os.path.realpath(__file__)), "../../CandlestickOhlc")) sys.path.append("../../CandlestickOhlc") from CandlestickOhlc import candlestickohlc import datetime import talib _book_id = "600469.XSHG" _data = FinanceDataSource.get_data(FinanceDataSource.str_cn_stock, _book_id) _data["ADX"] = talib.ADX(_data["High"].as_matrix(), _data["Low"].as_matrix(), _data['Close'].as_matrix()) candlestickohlc(_data, otherseries=["ADX"])
ax.xaxis_date() ax.autoscale_view() plt.setp(plt.gca().get_xticklabels(), rotation=45, horizontalalignment='right') plt.show() if __name__ == "__main__": # We will look at stock prices over the past year, starting at January 1, 2016 start = datetime.datetime(2016, 1, 1) end = datetime.date.today() # Let's get Apple stock data; Apple's ticker symbol is AAPL # First argument is the series we want, second is the source ("yahoo" for Yahoo! Finance), third is the start date, fourth is the end date # apple = web.DataReader("AAPL", "yahoo", start, end) import sys, os sys.path.append( os.path.join( os.path.dirname( os.path.realpath(__file__)), "../FinanceDataSource")) # sys.path.append("../../FinanceDataSource") import FinanceDataSource # yahoo_s_p_500 = init_data.get_data(init_data.str_pandas_datareader, init_data.yahoo_s_p_500) # pandas_candlestick_ohlc(yahoo_s_p_500) data = FinanceDataSource.get_tonghuashun_data(FinanceDataSource.tonghuashun_AGUSDO) import talib data["20d"] = talib.MA(data["Close"].as_matrix(), 20) data["120d"] = talib.MA(data["Close"].as_matrix(), 120) candlestickohlc(data , shareseries=["20d"], otherseries=["20d", "120d"])
def get_tonghuashun_AGUSDO_data(): """取得同花顺上的白银数据""" return FinanceDataSource.get_tonghuashun_data( FinanceDataSource.tonghuashun_AGUSDO)