What is a quantitative trading robot?
In essence,the trading robot is a software program that directly interacts with the financial exchange(usually uses API to obtain and interpret relevant information),and issues trading orders according to the interpretation of market data.These robots make these decisions by monitoring the market price trend and responding to a set of preset and programmed rules.Generally,a trading robot will analyze market behavior,such as trading volume,order,price and time.They can usually be programmed according to your own preferences.
自动交易机器人在云服务器上24小时运行。初始化设置参数之后,机器人将按照策略进行自动交易。达到设定条件自动买入或者卖出,无须长时间盯盘。机器人内置多种交易策略,满足不同的类型。I35 system 7O98 development O7I8设置策略后,机器人将智能分配每次进单的条件,严格执行交易策略,交易补单策略,根据当前行情,云大数据实时调整。
import os
import pandas as pd
import tushare as ts
import numpy as np
from pathlib import Path
import matplotlib.pyplot as plt
import mplfinance as mpf
import matplotlib as mpl
from cycler import cycler#用于定制线条颜色
import time
#分红
def dividend(ts_code):
df=pro.dividend(ts_code=ts_code)
df.to_csv('dividend.csv',encoding='utf_8_sig')
#画市柱状图
def draw_finance(ts_codes,begin_count,end_count=-1):
df=load_data(ts_codes)
fig=plt.figure()
ax=fig.add_subplot(111)
opens=df['open'].values[begin_count:end_count]
closes=df['close'].values[begin_count:end_count]
highs=df['high'].values[begin_count:end_count]
lows=df['low'].values[begin_count:end_count]
dates=df['trade_date'].values[begin_count:end_count]
vols=df['vol'].values[begin_count:end_count]
data=[dates,opens,closes,highs,lows,vols]
data=np.transpose(data)#矩阵转置
df=pd.DataFrame(data,columns=['Date','Open','Close','High','Low','Volume'])
df['Date']=pd.to_datetime(df['Date'])
df.set_index(['Date'],inplace=True)
#df.index.name='Date'
#设置基本参数
#type:绘制图形的类型,有candle,renko,ohlc,line等
#此处选择candle,即K线图
#mav(moving average):均线类型,此处设置7,30,60日线
#volume:布尔类型,设置是否显示成交量,默认False
#title:设置标题
#y_label:设置纵轴主标题
#y_label_lower:设置成交量图一栏的标题
#figratio:设置图形纵横比
#figscale:设置图形尺寸(数值越大图像质量越高)
kwargs=dict(
type='candle',
mav=(5,10,20),
volume=True,
title='nA_stock%s candle_line'%(ts_codes),
ylabel='OHLC Candles',
ylabel_lower='SharesnTraded Volume',
figratio=(50,30),
figscale=15)
#设置marketcolors
#up:设置K线线柱颜色,up意为收盘价大于等于开盘价
#down:与up相反,这样设置与国内K线颜色标准相符
#edge:K线线柱边缘颜色(i代表继承自up和down的颜色),下同。详见官方文档)
#wick:灯芯(上下影线)颜色
#volume:成交量直方图的颜色
#inherit:是否继承,选填
mc=mpf.make_marketcolors(
up='red',
down='green',
edge='i',
wick='i',
volume='in',
inherit=True)
#设置图形风格
#gridaxis:设置网格线位置
#gridstyle:设置网格线线型
#y_on_right:设置y轴位置是否在右
s=mpf.make_mpf_style(
gridaxis='both',
gridstyle='-.',
y_on_right=False,
marketcolors=mc)
#设置均线颜色,配色表可见下图
#建议设置较深的颜色且与红色、绿色形成对比
#此处设置七条均线的颜色,也可应用默认设置
mpl.rcParams['axes.prop_cycle']=cycler(
color=['dodgerblue','deeppink',
'navy','teal','maroon','darkorange',
'indigo'])
#设置线宽
mpl.rcParams['lines.linewidth']=.5
#图形绘制
#show_nontrading:是否显示非交易日,默认False
#savefig:导出图片,填写文件名及后缀
mpf.plot(df,
**kwargs,
style=s,
show_nontrading=False,
savefig='%s_begin%d_end%d'
%(ts_codes,begin_count,end_count)+'.png')
#candlestick2_ochl(ax,opens=opens,closes=closes,highs=highs,lows=lows,width=0.75,colorup='red',colordown='green')
#plt.legend(loc='best')
#plt.xticks(range(len(date)),date,rotation=30)
#plt.grid(True)
#plt.title(ts_codes)
#plt.show