Backtest Question

Dustin_LangDustin_Lang Posts: 25
edited March 2017 in FAQs

From a CQ backtest is it possible to write to a file and save all the console output from each day in a batch to a single file?

Tagged:

Comments

  • shayneshayne Posts: 70

    yes, service.write_file() allows you to do this.


    from cloudquant.interfaces import Strategy class ServiceWriteFile(Strategy): @staticmethod def in_symbol_universe(symbol, md, service): return symbol == 'TQQQ' def on_start(self, md, order, service, account): # create file name file_name = 'get_trading_days_{}.csv'.format(service.time_to_string(service.system_time, '%Y-%m-%d') ) # headline line of the file service.write_file(file_name, 'offset,date,month,day_of_week' ) for i in range(0, -100, -1): # service.get_market_hours( date_offset=i ) returns a tuple like (1455633000000000, 1455656400000000) previous_trading_date = service.get_market_hours( date_offset=i )[0] #string formatting http://strftime.org/ date = service.time_to_string(previous_trading_date, '%Y-%m-%d') month = service.time_to_string(previous_trading_date, '%B') day_of_week = service.time_to_string(previous_trading_date, '%A') # data line in file service.write_file(file_name, '{},{},{},{}'.format(i, date, month, day_of_week) ) service.terminate()
Sign In or Register to comment.