如何为股票交易添加3个在MA(100,10)中为vol的参数。利润亏损和亏损百分比的元组。交易

时间:2019-08-08 02:48:29

标签: python moving-average back-testing

  1. 标准做法是仅在短期MA>长期MA + 10%时对上行(买入)采取行动,而在短期MA比长期MA下降5%以上时才卖出
  2. 使用一系列MA来测试策略。尝试短期和长期的组合-例如:短期(测试3天到25天)与长期(25到200)。您将不需要测试每个值。例如,对于3到25,您可以尝试3、4、5、10、15、20、25 3.如果短期MA超过长期MA,则只有在交易量接近每日交易量平均值或高于交易量平均值时才起作用。

我使用了VMA策略。

signals = pd.DataFrame(index=dt.index)
    signals['Close']=dt['Close']
    signals['percent change']=dt['Percent_Change']
    signals['vol'] = dt['Volume']
    signals['100 MA'] = 
    dt['Close'].rolling(window=100,center=False).mean()
    signals['10 MA'] = dt['Close'].rolling(window=10, 
    center=False).mean()
    signals['vol avg']=dt['Volume'].mean()
    signals['Criteria1'] = (signals['10 MA']< signals['100 MA'])
    signals['Criteria2'] = signals['vol'] <= signals['vol avg']
    signals['BUY OR SELL'] = signals['Criteria1'] & signals['Criteria2']
    signals.tail()
    signals['Criteria 3'] = signals['10 MA']> signals['100 MA'] * 0.1
    signals['buy']=signals['Criteria 3'] 
    signals.tail()
    signals['buy'].value_counts() 
    def tradebuy():
    signals['value'] = signals['BUY OR SELL']
    if signals['BUY OR SELL'] == True:
    if signals['Criteria 3'] == True:
    print("BUY")

输出:具有(利润/亏损百分比,亏损百分比,交易数量,参数值..)的元组

0 个答案:

没有答案