Quantitative trading refers to the use of advanced mathematical models instead of artificial subjective judgments,and the use of computer technology to select multiple"high probability"events that can bring excess returns from huge historical data to formulate strategies,greatly reducing the impact of investor sentiment fluctuations,and avoiding irrational investment decisions under extreme fanaticism or pessimism in the market.
量化交易就是运用非常复杂统计学方法和数学模型,从庞大的历史数据中海选能带来超额收益的多种“大概率”事件以制定策略,用数量模型验证及固化这些规律和策略,然后用计算机来严格,高效地执行已固化的策略
pandas.DataFrame(ts).ewm(span=12).mean()
1.移动平均
def MA(df,n):
MA=Series(rolling_mean(df['Close'],n),name='MA_'+str(n))
df=df.join(MA)
return df
2.指数移动平均
def EMA(df,n):
EMA=Series(ewma(df['Close'],span=n,min_periods=n-1),name='EMA_'+str(n))
df=df.join(EMA)
return df
3.动量
def MOM(df,n):
M=Series(df['Close'].diff(n),name='Momentum_'+str(n))
df=df.join(M)
return df
4.变化率
def ROC(df,n):
M=df['Close'].diff(n-1)
N=df['Close'].shift(n-1)
ROC=Series(M/N,name='ROC_'+str(n))
df=df.join(ROC)
return df
5.均幅指标
def ATR(df,n):
i=0
TR_l=[0]
while i<df.index[-1]:
TR=max(df.get_value(i+1,'High'),df.get_value(i,'Close'))-min(df.get_value(i+1,'Low'),df.get_value(i,'Close'))
TR_l.append(TR)
i=i+1
TR_s=Series(TR_l)
ATR=Series(ewma(TR_s,span=n,min_periods=n),name='ATR_'+str(n))
df=df.join(ATR)
return df
6.布林线
def BBANDS(df,n):
MA=Series(rolling_mean(df['Close'],n))
MSD=Series(rolling_std(df['Close'],n))
b1=4*MSD/MA
B1=Series(b1,name='BollingerB_'+str(n))
df=df.join(B1)
b2=(df['Close']-MA+2MSD)/(4MSD)
B2=Series(b2,name='Bollinger%b_'+str(n))
df=df.join(B2)
return df