예제 #1
0
def get_relative_features(dDataRelative, sym):
    sma = ft.featMA(dDataRelative, lLookback = 20)
    sma1 = ft.featMA(dDataRelative, lLookback = 10)
    sma2 = ft.featMA(dDataRelative, lLookback = 5)
    sma3 = ft.featMA(dDataRelative, lLookback = 80)
    sma4 = ft.featMA(dDataRelative, lLookback = 40)
    rsi = ft.featRSI(dDataRelative, lLookback = 20)
    rsi1 = ft.featRSI(dDataRelative, lLookback = 10)
    rsi2 = ft.featRSI(dDataRelative, lLookback = 5)
    rsi3 = ft.featRSI(dDataRelative, lLookback = 80)
    rsi4 = ft.featRSI(dDataRelative, lLookback = 40)
    #volumeDelta = ft.featVolumeDelta(dDataRelative, lLookback = 20)
    aroon = ft.featAroon(dDataRelative, lLookback = 20)
    aroon1 = ft.featAroon(dDataRelative, lLookback = 10)
    aroon2 = ft.featAroon(dDataRelative, lLookback = 5)
    aroon3 = ft.featAroon(dDataRelative, lLookback = 80)
    aroon4 = ft.featAroon(dDataRelative, lLookback = 40)
    bollinger = ft.featBollinger(dDataRelative, lLookback = 20)
    bollinger1 = ft.featBollinger(dDataRelative, lLookback = 10)
    bollinger2 = ft.featBollinger(dDataRelative, lLookback = 5)
    bollinger3 = ft.featBollinger(dDataRelative, lLookback = 80)
    bollinger4 = ft.featBollinger(dDataRelative, lLookback = 40)
    #stochastics = ft.featStochastic(dDataRelative, lLookback = 20)
    dfX = pd.DataFrame( index=dDataRelative['close'].index, 
                        columns=['SMA', 'RSI', 'AROON', 'BOLL'], 
                        data=np.zeros((len(dDataRelative['close'].index), 4)))
    dfX['SMA'] = sma[sym] 
    dfX['SMA1'] = sma1[sym] 
    dfX['SMA2'] = sma2[sym] 
    dfX['SMA3'] = sma3[sym] 
    dfX['SMA4'] = sma4[sym] 
    dfX['RSI'] = rsi[sym] 
    dfX['RSI1'] = rsi1[sym] 
    dfX['RSI2'] = rsi2[sym] 
    dfX['RSI3'] = rsi3[sym] 
    dfX['RSI4'] = rsi4[sym] 
    dfX['AROON'] = aroon[sym] 
    dfX['AROON1'] = aroon1[sym] 
    dfX['AROON2'] = aroon2[sym] 
    dfX['AROON3'] = aroon3[sym] 
    dfX['AROON4'] = aroon4[sym] 
    dfX['BOLL'] = bollinger[sym]
    dfX['BOLL1'] = bollinger1[sym]
    dfX['BOLL2'] = bollinger2[sym]
    dfX['BOLL3'] = bollinger3[sym]
    dfX['BOLL4'] = bollinger4[sym]
    return dfX
예제 #2
0
def findEvents(symbols, startday,endday, marketSymbol,verbose=False):

	# Reading the Data for the list of Symbols.	
	timeofday=dt.timedelta(hours=16)
	timestamps = du.getNYSEdays(startday,endday,timeofday)
	dataobj = da.DataAccess('Yahoo')
	if verbose:
            print __name__ + " reading data"
	# Reading the Data
	close = dataobj.get_data(timestamps, symbols, closefield)
	
	# Completing the Data - Removing the NaN values from the Matrix
	close = (close.fillna(method='ffill')).fillna(method='backfill')
	
	#CLOSE_UNCHANGED!!!!
	close_unchanged = dataobj.get_data(timestamps, symbols, closefield)
	close_unchanged = (close.fillna(method='ffill')).fillna(method='backfill')
	
	# Calculating Daily Returns for the Market
	tsu.returnize0(close.values)
	SPYValues=close[marketSymbol]

	# Calculating the Returns of the Stock Relative to the Market 
	# So if a Stock went up 5% and the Market rised 3%. The the return relative to market is 2% 
	mktneutDM = close - close[marketSymbol]
	np_eventmat = copy.deepcopy(mktneutDM)
	for sym in symbols:
		for time in timestamps:
			np_eventmat[sym][time]=np.NAN

	if verbose:
            print __name__ + " finding events"

	# Generating the Event Matrix
	# Event described is : Market falls more than 3% plus the stock falls 5% more than the Market
	# Suppose : The market fell 3%, then the stock should fall more than 8% to mark the event.
	# And if the market falls 5%, then the stock should fall more than 10% to mark the event.
	with open (args.orders, "w") as outFile:
		writer  = csv.writer(outFile)
		for symbol in symbols:
		    for i in range(1,len(mktneutDM[symbol])):
			if SPYValues[i]<-0.03 and mktneutDM[symbol][i] < -0.05 :
				ft.featAroon(close_unchanged[symbol][i], bDown=False) 
		     		writer.writerow([timestamps[i].year,timestamps[i].month,timestamps[i].day, symbol, "Buy", 100])
				writer.writerow([timestamps[i+5].year,timestamps[i+5].month,timestamps[i+5].day, symbol, "Sell", 100]) 
예제 #3
0
    def get_features_old(self):
        feats = pd.DataFrame( index=self.relative_data['close'].index)
        periods = self.default_periods
        for x in periods:
            feats['SMA' + str(x)] = ft.featMA(self.relative_data, lLookback = x)[self.stock_period.symbol]
        for x in periods:
            feats['RSI' + str(x)] = ft.featRSI(self.relative_data, lLookback = x)[self.stock_period.symbol]
        for x in periods:
            feats['AROON' + str(x)] = ft.featAroon(self.relative_data, lLookback = x)[self.stock_period.symbol]

        for x in periods:
            feats['BOLL' + str(x)] = ft.featBollinger(self.relative_data, lLookback = x)[self.stock_period.symbol]
        for x in periods:
            feats['MOM' + str(x)] = ft.featMomentum(self.relative_data, lLookback = x)[self.stock_period.symbol]
        for x in periods:
            feats['EMA' + str(x)] = ft.featEMA(self.relative_data, lLookback = x)[self.stock_period.symbol]

        #for x in periods:
        #    feats['STD' + str(x)] = ft.featSTD(self.relative_data, lLookback = x)[self.stock_period.symbol]
        #for x in periods:
        #    feats['VOLD' + str(x)] = ft.featVolumeDelta(self.relative_data, lLookback = x)[self.stock_period.symbol]

        return feats