def _generate_hitorical_min(self, symbol, window, current_date_time): datetimes = TradeTime.generate_trade_datetimes_by_window(window, current_date_time) start = datetimes[0] end = datetimes[-1] all_datetimes = TradeTime.generate_datetimes(start.date(), end.date()) prices = MontCarloSimulator.simulate_min(symbol, start, end, len(all_datetimes), 1) rows = map(lambda x, y: [x, y], datetimes, prices[0]) return rows
def load_log(self, symbol, date): file_name = '%s%s.log' % (symbol, date.strftime('%Y%m%d')) path = PathMgr.get_data_path('quantopian_daily_min/%s' % file_name) content = read_file_to_string(path) lines = content.split('\n') filtered_lines = filter(lambda x: len(x) > 100, lines) lines = map(lambda x: string_fetch(x, 'PRINT ', ''), filtered_lines) close_list_str = ','.join(lines) prices_list = map(float, close_list_str.split(',')) datetimes = TradeTime.generate_datetimes(date, date) equities = map(lambda x, y: Equity(symbol, x, y, y, y, y), datetimes, prices_list) EquityMinDAO().insert(equities)
def to_csv(self, symbol, date): file_name = '%s%s.log' % (symbol, date.strftime('%Y%m%d')) path = PathMgr.get_data_path('quantopian_daily_min/%s' % file_name) content = read_file_to_string(path) lines = content.split('\n') filtered_lines = filter(lambda x: len(x) > 100, lines) lines = map(lambda x: string_fetch(x, 'PRINT ', ''), filtered_lines) close_list_str = ','.join(lines) # print close_list_str prices_list = map(float, close_list_str.split(',')) datetimes = TradeTime.generate_datetimes(date, date) new_lines = map(lambda x, y: '%s,%s' % (x, y), datetimes, prices_list) new_content = '\n'.join(new_lines) write_path = PathMgr.get_data_path('quantopian_daily_min/%s%s.csv' % (symbol, date.strftime('%Y%m%d'))) write_to_file(write_path, new_content)
def run_schedule_and_handle_function(schedule_functions, handle_function, start_date, end_date, logger): for dt in TradeTime.generate_datetimes(start_date, end_date): if Container.context.terminate_p: return Container.data.set_datetime(dt) logger.set_dt(dt) for schedule_function in schedule_functions: try: schedule_function.run(dt) except Exception as e: logger.error('Trace: ' + traceback.format_exc(), False) logger.error('Error: get action arguments failed:' + str(e)) try: handle_function() except Exception as e: logger.error('Trace: ' + traceback.format_exc(), False) logger.error('Error: get action arguments failed:' + str(e)) if dt.minute == 0: if (TradeTime.is_half_trade_day(dt.date()) and dt.hour == 13) or dt.hour == 16: Container.analysis.add_portfolio_trace(dt.date(), Container.api.portfolio)