day):'''Returns the next trading day (datetime/date instance) after ``day``(datetime/date instance) and the isocalendar componentsThe return value is a tuple with 2 components: (nextday, (y, w, d))where (y, w, d
end=end,freq='B')forholidayinholidays:market_date_range=market_date_range[market_date_range!=holiday]returnmarket_date_range# 示例:创建一个美国市场的交易日历us_holidays=['2023-01-01','2023-07-04','2023-12-25']us_trading_days=create_market_calendar('2023...
buy_stocks) #交易函数 def trade(context, buy_stocks): #卖出 for stock in cont...
tdays = list(set(eval(tradingdays['tradingdays']['days']))) tdays.sort(reverse=False) # 升序 print(tdays[-5:]) currenttime = int(time.strftime('%H%M%S', time.localtime())) # 当前时间 判断是夜盘交易还是白天交易 决定Finaltime everydaylist = [x.strftime('%Y%m%d') for x in list(...
# 图形绘制# show_nontrading:是否显示非交易日,默认False# savefig:导出图片,填写文件名及后缀mpf.plot(df, **绘图参数,style=s, show_nontrading=False)mpf.show()代码运行效果:源码格式如下:stock.py数据接口源码:import pandas as pdcode="002191" #股票代码dayss=100 #截止日期之前天数dayend=...
Also append the last dayifindex==len(date)-1:last_trading_days.append(day)print(last_trading_...
#下面是主程序 ### 登陆系统 ### rootPath='DataSetText' lg = bs.login() # 显示登陆返回信息 print('login respond error_code:'+lg.error_code) print('login respond error_msg:'+lg.error_msg) #获取股票的代码,你可以加入多个股票序列 StockCodes=['000001','600017','000015'] for code in S...
返回Truetoday (datetime.datetime): 默认当日datetime.today()'''iftoday==None:today=datetime.today()#今日是否是days天长假前最后一个交易日is_rest_days=all([(today+timedelta(i)).weekday()>4or(today+timedelta(i)).date()inREST_DAYSforiinrange(1,days+1)])#自明日连续days天是周末或者是假日...
Python Backtesting library for trading strategies. Contribute to luyajie/OnePy development by creating an account on GitHub.
save the data into MongoDB:param code:stock's code:param df_daily:the DataFrame including k line:param collection:saving collection:param extra_fields:the other fields that will be used one day""" update_requests=[]fordf_indexindf_daily.index:daily_obj=df_daily.loc[df_index]doc=self.dail...