示例#1
0
 def LoadData(self):
     
     ds = YahooStockDataSource(cachedFolderName=cachedFolderName,
                         dataSetId=dataSetId,
                         instrumentIds=self.instrumentIds,
                         startDateStr=startDateStr,
                         endDateStr=endDateStr,
                         event='history')
    
     self.stkData = [ds.getBookDataByFeature()['open'],
             ds.getBookDataByFeature()['high'],
             ds.getBookDataByFeature()['low'],
             ds.getBookDataByFeature()['close'],
             ds.getBookDataByFeature()['adjClose'],
             ds.getBookDataByFeature()['volume']]
     tbRSI = tb.RSI(self.stkData[4][self.instrumentIds[0]],14)
     
     tbChaikin = tb.ADOSC(self.stkData[1][self.instrumentIds[0]],
                         self.stkData[2][self.instrumentIds[0]],
                         self.stkData[3][self.instrumentIds[0]],
                         self.stkData[5][self.instrumentIds[0]])
     
 
     '''
     Task1
     Create new dataframe here with 5 columns 
     column  1 : Date of stock price 
     column  2 : Day of the week (Monday Tuesday etc)
     Columnn 3 :  tbRSI
     Column 4 : tbChaikin
     column 5 :  Stock's adjusted price.
     Index : column1 
     '''
     dfdata = {'Adj_Close':self.stkData[4][self.instrumentIds[0]],
              'RSI':tbRSI,
              'Chaikin':tbChaikin}
     df = pd.DataFrame(dfdata)
     df['Trade_Date'] = pd.to_datetime(df.index)
     df['day_of_week'] = df['Trade_Date'].dt.day_name()
     
     dfFinal = df[["Trade_Date", "day_of_week", "RSI", "Chaikin", "Adj_Close"]]
     # dfFinal2 = df[["Trade_Date", "day_of_week", "RSI", "Chaikin", "Adj_Close"]]
     #df_rsi = pd.DataFrame(dfFinal['RSI'])
     #print(df_rsi)
     #df_rsi.to_csv('yahooData/weeklyTradeTest/RSI_Value.csv')
     
     
     
     '''
     Task 2
     filter above dataframe using column  2 value (e.g. 'Wednesday') and store in other dataframe 
     '''
     # dfFinal2 = dfFinal.loc[df['day_of_week'] == 'Wednesday']
     # dfFinal.to_csv(dir_path)    
     # print(dfFinal.head(50)
     # dfFinal = dfFinal.loc[df['day_of_week'] == 'Friday']
     dfFinal.to_csv(dir_path)    
     print(dfFinal.head(50))
示例#2
0
 def getDataParser(self):
     return YahooStockDataSource(cachedFolderName='yahooData/',
                                 dataSetId='AuquanTrainingTest',
                                 instrumentIds=self.instrumentIds,
                                 startDateStr=self.start,
                                 endDateStr=self.end,
                                 event='history')
示例#3
0
 def getDataParser(self):
     startDateStr = '2007/12/31'
     endDateStr = '2017/12/31'
     return YahooStockDataSource(cachedFolderName='yahooData/',
                                 dataSetId='testPairsTrading',
                                 instrumentIds=instrumentIds,
                                 startDateStr=startDateStr,
                                 endDateStr=endDateStr)
示例#4
0
 def getDataParser(self):
     """
     Returns an instance of class DataParser. Source of data for instruments
     """
     return YahooStockDataSource(
         cachedFolderName='historicalData/',
         dataSetId=self.__dataSetId,
         instrumentIds=self.__instrumentIds,
         startDateStr=self.__startDate,
         endDateStr=self.__endDate,
     )
示例#5
0
 def getDataParser(self):
     '''
     Returns an instance of class DataParser. Source of data for instruments
     '''
     instrumentIds = self.__tradingFunctions.getSymbolsToTrade()
     return YahooStockDataSource(
         cachedFolderName='historicalData/',
         dataSetId=self.__dataSetId,
         instrumentIds=instrumentIds,
         startDateStr=self.__startDate,
         endDateStr=self.__endDate,
     )
  def getDataParser(self):
    instrumentIds = assets
    startDateStr = start
    endDateStr = end
    return YahooStockDataSource(cachedFolderName='yahooData',
                              dataSetId='',
                              instrumentIds=instrumentIds,
                              startDateStr=startDateStr,
                              endDateStr=endDateStr)


    def getBenchmark(self):
        return 'SPY'

from backtester.dataSource.yahoo_data_source import YahooStockDataSource
from datetime import datetime

startDateStr = '2007/12/01'
endDateStr = '2017/12/01'
cachedFolderName = 'yahooData/'
dataSetId = 'testPairsTrading'
instrumentIds = [
    'SPY', 'AAPL', 'ADBE', 'T', 'EBAY', 'MSFT', 'QCOM', 'HPQ', 'JNPR', 'AMD',
    'IBM'
]
ds = YahooStockDataSource(cachedFolderName=cachedFolderName,
                          dataSetId=dataSetId,
                          instrumentIds=instrumentIds,
                          startDateStr=startDateStr,
                          endDateStr=endDateStr,
                          event='history')
data = ds.getBookDataByFeature()['adjClose']

# Heatmap to show the p-values of the cointegration test
# between each pair of stocks

scores, pvalues, pairs = find_cointegrated_pairs(data)
import seaborn

m = [0, 0.2, 0.4, 0.6, 0.8, 1]
seaborn.heatmap(pvalues,
                xticklabels=instrumentIds,
                yticklabels=instrumentIds,
                cmap='RdYlGn_r',
示例#8
0
    def getFeatureSet(self):
        pass

    def computeFeatures(self):
        pass

    def findBestModel(self):
        pass

    def getFinalMetrics(self):
        pass


if __name__ == '__main__':
    instrumentIds = ['IBM', 'AAPL']
    startDateStr = '2013/05/10'
    endDateStr = '2017/06/09'
    mlsParams = ModelLearningSystemParamters(instrumentIds, 'XYZ')
    mlsParams.trainingDataSource = YahooStockDataSource(
        cachedFolderName='yahooData/',
        dataSetId="testTrading",
        instrumentIds=instrumentIds,
        startDateStr=startDateStr,
        endDateStr=endDateStr,
        event='history',
        liveUpdates=False)

    system1 = ModelLearningSystem(mlsParams, chunkSize=1000)
    system1.generateFeatures()
示例#9
0
 def getDataParser(self):
     return YahooStockDataSource(cachedFolderName='yahooData/',
                                 dataSetId='testPairsTrading',
                                 instrumentIds=self.__instrumentIds,
                                 startDateStr=self.__startDate,
                                 endDateStr=self.__endDate)