写了一个简单的期货双均线策略,如有错误地方,请指正(^__^)
import datetime import matplotlib.pyplot as plt
# 获取主力合约代码 future_code = get_dominant_future('RB')
# 当前日期和上一个日期 dt = datetime.datetime.now().date() last_day = dt - datetime.timedelta(days=1)
start_day = dt - datetime.timedelta(days=365*2) ma5_list = [] ma60_list = [] day_list = [] count = 0 for i in range(365*2): count += 1 today = start_day + datetime.timedelta(days=i) # 获取期货对应的历史价格 price = get_price(security=future_code, end_date=today, frequency='daily', fields=['close'], skip_paused=False, fq='pre', count=100) # 求出上一个交易日的m5均线值与ma60值 last_ma5 = price.iloc[-5:]['close'].mean() last_ma60 = price.iloc[-60:]['close'].mean() ma5_list.append(last_ma5) ma60_list.append(last_ma60) day_list.append(count) # 求出三个交易日之前的ma5与ma60值 # old_ma5 = price.iloc[-5-2:-2]['close'].mean() # old_ma60 = price.iloc[-60-2:-2]['close'].mean() plt.plot(day_list,ma5_list,'r') plt.plot(day_list,ma60_list,'g') plt.legend(['ma5', 'ma60'], loc=0) plt.show()
本社区仅针对特定人员开放
查看需注册登录并通过风险意识测评
5秒后跳转登录页面...
借花(感恩节)献佛 感恩回顾
美股再次暴跌,但黄金却无动于衷
移动端课程