量化交易/量化合約/合約量化/秒合約/永續合約/合約跟單/交易所繫統開發(策略及原始碼)

xiaofufu發表於2023-02-23

  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


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69956839/viewspace-2936756/,如需轉載,請註明出處,否則將追究法律責任。

相關文章