def do_your_job(self): url = "http://download.finance.yahoo.com/d/quotes.csv?s=PETR4.SA&f=sd1o0h0g0l1v0&e=.csv" request = urllib2.Request(url) response = urllib2.urlopen(request) row = response.readlines()[0] #print row # DEBUG data = row.split(',') # "PETR4.SA","4/19/2013",18.15,18.48,17.95,18.48,38077200 symbol = data[0] date = datetime.strptime(data[1], '"%m/%d/%Y"').strftime('"%Y-%m-%d"') open_p = float(data[2]) high = float(data[3]) low = float(data[4]) close = float(data[5]) volume = float(data[6].rstrip()) dbw = DbWriter(self.model) dbw.write(symbol, date, open_p, high, low, close, volume, table='ticker')
def reckon(self): qs = self.not_measured_yet() dbw = DbWriter(self.model) for pk, future, price in qs: splited_date = [int(d) for d in future.split('-')] date = datetime(*splited_date) rs = self.extractor.benchmark(date) value = rs[0][5] #TODO extractor could retrun a list of dict dbw.write(pk, value, value-price, table='truth')
def reckon(self): qs = self.not_measured_yet() dbw = DbWriter(self.model) for pk, future, price in qs: splited_date = [int(d) for d in future.split('-')] date = datetime(*splited_date) rs = self.extractor.benchmark(date) value = rs[0][5] #TODO extractor could retrun a list of dict dbw.write(pk, value, value - price, table='truth')
def make_your_magic(self): dbw = DbWriter(self.model) best_prices = self.extractor.last5days_high() worse_prices = self.extractor.last5days_low() lower = min([wp.low for wp in worse_prices]) upper = max([bp.high for bp in best_prices]) future_price = random.uniform(lower, upper) future_date = datetime.now() + timedelta(days=1) str_future = future_date.strftime("'%Y-%m-%d'") dbw.write(str_future, "'PETR4'", future_price, table='prediction')
def make_your_magic(self): dbw = DbWriter(self.model) best_prices = self.extractor.last5days_high() worse_prices = self.extractor.last5days_low() lower = min([wp.low for wp in worse_prices]) upper = max([bp.high for bp in best_prices]) future_price = random.uniform(lower, upper) future_date = datetime.now() + timedelta(days=1) str_future = future_date.strftime("'%Y-%m-%d'") dbw.write(str_future, "'PETR4'", future_price, table="prediction")