def update_wsb_table(): current_date = datetime.datetime.now().strftime("%Y-%m-%d") if utils.is_trading_day(current_date) is False: print( 'Today is not a trading day. WSB Sentiment from yesterday not updated.' ) return date_nine_wsb_entries_ago = utils.get_wsb_date_n_entries_ago(9) print('Nine entries ago was on: ' + date_nine_wsb_entries_ago) #wsb_data = get_wsb_data(start_date=date_nine_wsb_entries_ago) wsb_data = get_wsb_data() print('Retrieved Historical WSB data.') print('Analyzing Sentiment figures...') sentiment_dict = utils.get_yesterday_wsb_sentiment() print(sentiment_dict) print('Retrieved Sentiment from yesterday.') # Now calculate the recent 10d moving average. bull_bear_series = wsb_data['Bull/Bear Ratio'] bull_bear_series = bull_bear_series.append( pd.Series([sentiment_dict['Bull/Bear Ratio']], index=[sentiment_dict['Date']])) print(bull_bear_series) ema_10 = pd.Series.ewm(bull_bear_series, span=10).mean() ema_10_value = Decimal(str(ema_10.get(key=sentiment_dict['Date']))) # Now, add the entry to the AWS database. date = sentiment_dict['Date'] bull_comments = Decimal(str(sentiment_dict['Bull Comments'])) bear_comments = Decimal(str(sentiment_dict['Bear Comments'])) bull_bear_ratio = Decimal(str(sentiment_dict['Bull/Bear Ratio'])) add_to_wsb_table(date, bull_comments, bear_comments, bull_bear_ratio, ema_10_value)
def validate(data_list, data_dict, open_time, close_time): time_step = datetime.timedelta(minutes=1) # stamp = open_time + time_step if not utils.is_trading_day(open_time): return if len(data_list) <= 0: print 'invalid day: %s' % open_time return tmp_time = open_time + time_step while tmp_time <= close_time: str_date = tmp_time.strftime('%H%M') if str_date == '1016' or str_date == '1020': tmp_time += 15 * time_step # 休息15分钟 elif str_date == '1131': tmp_time += 120 * time_step # 午休 #if tmp_time not in data_dict: # print 'invalid timestamp: %s' % tmp_time tmp_time += time_step
def update_spy_table(): yesterday = utils.yesterday_date() if utils.is_trading_day(yesterday) is False: print('Yesterday was not a trading day. No SPY data to update.') return print('Getting SPY Data from yesterday...') info = utils.get_yesterday_spy_data() print(info) print('Retrieved SPY data from yesterday.') date = info['Date'] open = Decimal(str(info['Open'])) close = Decimal(str(info['Close'])) add_to_spy_table(date, open, close)
# time.sleep(1) # # calc.calc_sub_price(open_time, close_time) # merge.merge(open_time, close_time) # begin = datetime.datetime(year=2017, month=1,day=1,hour=9,minute=0,second=0,microsecond=0) end = datetime.datetime(year=2017, month=10,day=10,hour=1,minute=0,second=0,microsecond=0) # begin = read_date("开盘") # end = read_date("收盘") delta = datetime.timedelta(hours=12) delta1 = datetime.timedelta(days=4) while begin < end: time.sleep(1) open_time, close_time = utils.get_open_close_time(begin) if not utils.is_trading_day(open_time): begin += delta continue res = recv_data.check_data(open_time, close_time, config.ACTUAL_GOODS) if not res: print "there is no data between %s - %s" %(open_time, close_time) begin += delta continue time.sleep(1) res = recv_data.check_data(open_time, close_time, config.FUTURES) if not res: cur = dbutil.get_cursor() cur.execute("delete from lme_cu_1min where date >= '%s' and date <= '%s'" % (open_time, close_time))
minute=0, second=0, microsecond=0) end = datetime.datetime(year=2016, month=11, day=17, hour=1, minute=0, second=0, microsecond=0) delta = datetime.timedelta(hours=12) while begin < end: open_time, close_time = utils.get_open_close_time(begin) seq = gen_time_sequence(open_time, close_time, 60) sub_price_data_list, high, low, data_dict = get_price_sub_data( open_time, close_time) lens = len(sub_price_data_list) if lens <= 0 and utils.is_trading_day(open_time): print seq for i in range(0, lens, 1): expect = seq[i] if expect not in data_dict: print "缺少数据: %s " % expect begin += delta