diff --git a/problem1/problem1_template.py b/problem1/problem1_template.py index aa03626..2bebb0a 100644 --- a/problem1/problem1_template.py +++ b/problem1/problem1_template.py @@ -10,12 +10,18 @@ from backtester.constants import * from backtester.features.feature import Feature from backtester.logger import * +from backtester.versions import versions import pandas as pd import numpy as np import sys from sklearn import linear_model from sklearn import metrics as sm from problem1_trading_params import MyTradingParams +try: + from urllib2 import urlopen +except ImportError: + from urllib.request import urlopen +import collections ## Make your changes to the functions below. ## SPECIFY the symbols you are modeling for in getSymbolsToTrade() below @@ -25,16 +31,13 @@ ## Don't change any other function ## The toolbox does the rest for you, from downloading and loading data to running backtest - class MyTradingFunctions(): + def __init__(self): #Put any global variables here self.lookback = 1200 ## max number of historical datapoints you want at any given time self.targetVariable = 'Y' - if datetime.today() < datetime(2018, 7, 3): - self.dataSetId = 'QQ3DataSample' - else: - self.dataSetId = 'QQ3DataDownSampled' + self.dataSetId = '' self.params = {} # for example you can import and store an ML model from scikit learn in this dict @@ -74,7 +77,6 @@ def getSymbolsToTrade(self): ''' def getInstrumentFeatureConfigDicts(self): - ############################################################################## ### TODO 2a: FILL THIS FUNCTION TO CREATE DESIRED FEATURES for each symbol. ### ### USE TEMPLATE BELOW AS EXAMPLE ### @@ -104,7 +106,6 @@ def getMarketFeatureConfigDicts(self): ### TODO 2b: FILL THIS FUNCTION TO CREATE features that use multiple symbols ### ### USE TEMPLATE BELOW AS EXAMPLE ### ############################################################################### - # customFeatureDict = {'featureKey': 'custom_mrkt_feature', # 'featureId': 'my_custom_mrkt_feature', # 'params': {'param1': 'value1'}} @@ -155,7 +156,6 @@ def getPrediction(self, time, updateNum, instrumentManager,predictions): ma1 = lookbackInstrumentFeatures.getFeatureDf('ma_5') #DF with rows=timestamp and columns=stockIDS ma2 = lookbackInstrumentFeatures.getFeatureDf('ma_10') #DF with rows=timestamp and columns=stockIDS factor2Values = (ma1/ma2) #DF with rows=timestamp and columns=stockIDS - # Now looping over all stocks: for s in self.getSymbolsToTrade(): #Creating a dataframe to hold features for this stock @@ -194,7 +194,6 @@ def getPrediction(self, time, updateNum, instrumentManager,predictions): threshold = 0.8 predictions[s] = 1 if y_predict>threshold else 0.5 predictions[s] = 0 if y_predict<(1-threshold) else 0.5 - return predictions ########################################### @@ -243,7 +242,6 @@ def getCustomFeatures(self): def computeForInstrument(cls, updateNum, time, featureParams, featureKey, instrumentManager): # Custom parameter which can be used as input to computation of this feature param1Value = featureParams['param1'] - # A holder for the all the instrument features lookbackInstrumentFeatures = instrumentManager.getLookbackInstrumentFeatures() @@ -254,14 +252,13 @@ def computeForInstrument(cls, updateNum, time, featureParams, featureKey, instru # 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__": + versions() 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') diff --git a/problem1/problem1_trading_params.py b/problem1/problem1_trading_params.py index 00377f7..e379dbf 100644 --- a/problem1/problem1_trading_params.py +++ b/problem1/problem1_trading_params.py @@ -15,6 +15,10 @@ import sys from sklearn import linear_model from sklearn import metrics as sm +try: + from urllib2 import urlopen +except ImportError: + from urllib.request import urlopen ## Make your changes to the functions below. ## SPECIFY the symbols you are modeling for in getSymbolsToTrade() below @@ -32,7 +36,11 @@ class MyTradingParams(TradingSystemParameters): ''' def __init__(self, tradingFunctions): self.__tradingFunctions = tradingFunctions - self.__dataSetId = self.__tradingFunctions.getDataSetId() + + url = "https://raw.githubusercontent.com/Auquan/data_set_id/master/DataSetId.txt" + response = urlopen(url) + self.__dataSetId = response.read().decode('utf8').rstrip() + self.__tradingFunctions.getDataSetId() + self.__instrumentIds = self.__tradingFunctions.getSymbolsToTrade() self.__priceKey = 'F5' self.__additionalInstrumentFeatureConfigDicts = []