Example #1
0
def run_plain_momentum():
    tsParams = PlainMomParams()
    tradingSystem = TradingSystem(tsParams)
    results = tradingSystem.startTrading()
    return results
        # dataframe for a historical instrument feature (basis in this case). The index is the timestamps
        # atmost upto lookback data points. The columns of this dataframe are the stocks/instrumentIds.
        lookbackInstrumentValue = lookbackInstrumentFeatures.getFeatureDf('F5')

        # The last row of the previous dataframe gives the last calculated value for that feature (basis in this case)
        # This returns a series with stocks/instrumentIds as the index.
        currentValue = lookbackInstrumentValue.iloc[-1]

        if param1Value == 'value1':
            return currentValue * 0.1
        else:
            return currentValue * 0.5


if __name__ == "__main__":
    if updateCheck():
        print(
            'Your version of the auquan toolbox package is old. Please update by running the following command:'
        )
        print('pip install -U auquan_toolbox')
    else:
        tf = MyTradingFunctions()
        tsParams = MyTradingParams(tf)
        tradingSystem = TradingSystem(tsParams)
        # Set onlyAnalyze to True to quickly generate csv files with all the features
        # Set onlyAnalyze to False to run a full backtest
        # Set makeInstrumentCsvs to False to not make instrument specific csvs in runLogs. This improves the performance BY A LOT
        tradingSystem.startTrading(onlyAnalyze=False,
                                   shouldPlot=True,
                                   makeInstrumentCsvs=True)
Example #3
0
                                  currentMarketFeatures['ma_r%s_90' % i]
                                  ) / currentMarketFeatures['sdev_r%s_90' % i]
                else:
                    z_score[i] = 0
                instrument = instrumentManager.getInstrument(instrumentIds[0])
                #z_score = z_score + instrument.getDataDf()['position']/20000

                if currentMarketFeatures['correl_r%s_90' % i] < 0.5:
                    z_score[i] = 0

                if z_score[i] > 1:
                    prediction[PAIRIDS[i][0]] = 0
                    prediction[PAIRIDS[i][1]] = 1
                elif z_score[i] < -1:
                    prediction[PAIRIDS[i][0]] = 1
                    prediction[PAIRIDS[i][1]] = 0
                elif (z_score[i] > 0.5) or (z_score[i] < -0.5):
                    prediction[PAIRIDS[i][0]] = 0.75
                    prediction[PAIRIDS[i][1]] = 0.25
                else:
                    prediction[PAIRIDS[i][0]] = 0.5
                    prediction[PAIRIDS[i][1]] = 0.5

        return prediction


if __name__ == "__main__":
    tsParams = MyTradingParams()
    tradingSystem = TradingSystem(tsParams)
    tradingSystem.startTrading(onlyAnalyze=False)
Example #4
0
            mom10 = mom10Data.iloc[-1]
            ma90 = ma90Data.iloc[-1]

            # Calculate Hurst Exponent
            hurst = ma90Data.apply(hurst_f, axis=0)
            # Go long if Hurst > 0.5 and both long term and short term momentum are positive
            predictions[(hurst > 0.5) & (mom30 > 0) & (mom10 > 0)] = 1
            # Go short if Hurst > 0.5 and both long term and short term momentum are negative
            predictions[(hurst > 0.5) & (mom30 <= 0) & (mom10 <= 0)] = 0

            # Get out of position if Hurst > 0.5 and long term momentum is positive while short term is negative
            predictions[(hurst > 0.5) & (mom30 > 0) & (mom10 <= 0)] = 0.5
            # Get out of position if Hurst > 0.5 and long term momentum is negative while short term is positive
            predictions[(hurst > 0.5) & (mom30 <= 0) & (mom10 > 0)] = 0.5

            # Get out of position if Hurst < 0.5
            predictions[hurst <= 0.5] = 0.5
        else:
            # If no sufficient data then don't take any positions
            predictions.values[:] = 0.5
        return predictions

    def updateCount(self):
        self.count = self.count + 1


tf = MyTradingFunctions()
tsParams = MomentumTradingParams(tf)
tradingSystem = TradingSystem(tsParams)

results = tradingSystem.startTrading()
Example #5
0
		# dataframe for a historical instrument feature (basis in this case). The index is the timestamps
		# atmost upto lookback data points. The columns of this dataframe are the symbols/instrumentIds.
		lookbackInstrumentValue = lookbackInstrumentFeatures.getFeatureDf('symbolVWAP')

		# The last row of the previous dataframe gives the last calculated value for that feature (basis in this case)
		# This returns a series with symbols/instrumentIds as the index.
		currentValue = lookbackInstrumentValue.iloc[-1]

		if param1Value == 'value1':
			return currentValue * 0.1
		else:
			return currentValue * 0.5


if __name__ == "__main__":
	if updateCheck():
		print('Your version of the auquan toolbox package is old. Please update by running the following command:')
		print('pip install -U auquan_toolbox')
	else:
		print('Loading your config dicts and prediction function')
		tf = MyTradingFunctions()
		print('Loaded config dicts and prediction function, Loading Problem Params')
		tsParams1 = MyTradingParams(tf, 'Revenue(Y)')
		tradingSystem = TradingSystem(tsParams1)
#		s=MyTradingFunctions()
#		s.getInstrumentIds()
		results1 = tradingSystem.startTrading(onlyAnalyze=False, shouldPlot=False, makeInstrumentCsvs=False)
#		tsParams2 = MyTradingParams(tf, 'Income(Y)')
#		tradingSystem = TradingSystem(tsParams2)
#		results2 = tradingSystem.startTrading(onlyAnalyze=False, shouldPlot=False, makeInstrumentCsvs=False)
	print('Score: %0.3f'%((results1['score'])))#+results2['score'])/2))
Example #6
0
def run_hurst_momentum():
    tsParams = HurstMomParams()
    tradingSystem = TradingSystem(tsParams)
    results = tradingSystem.startTrading()
    return results
                                     shortLimit=shortLimit,
                                     capitalUsageLimit=0.10 *
                                     self.getStartingCapital(),
                                     lotSize=lotSize,
                                     limitType='D',
                                     price=self.getPriceFeatureKey())

    '''
    Returns the type of order placer we want to use. its an implementation of the class OrderPlacer.
    It helps place an order, and also read confirmations of orders being placed.
    For Backtesting, you can just use the BacktestingOrderPlacer, which places the order which you want, and automatically confirms it too.
    '''

    def getOrderPlacer(self):
        return BacktestingOrderPlacer()

    '''
    Returns the amount of lookback data you want for your calculations. The historical market features and instrument features are only
    stored upto this amount.
    This number is the number of times we have updated our features.
    '''

    def getLookbackSize(self):
        return 35


if __name__ == "__main__":
    tsParams = MyTradingParams()
    tradingSystem = TradingSystem(tsParams)
    tradingSystem.startTrading(onlyAnalyze=False, shouldPlot=True)
Example #8
0
def run_hurst_pairs():
    tsParams = HurstPairParams()
    tradingSystem = TradingSystem(tsParams)
    result = tradingSystem.startTrading()
    return result
Example #9
0
def run_plain_pairs():
    tsParams = PlainPairParams()
    tradingSystem = TradingSystem(tsParams)
    result = tradingSystem.startTrading()
    return result