def __init__(self, config_file=None, *args, **kwargs): """ Init the paramter. :param config_file: :param args: :param kwargs: :return: """ self.logger = kwargs.get('log') self._buy_record_list = [] self._sell_record_list = [] with codecs.open(config_file, encoding='utf-8') as f: config = yaml.load(f) if config is None: raise ValueError("Need config file") with codecs.open(config_file, encoding='utf-8') as f: config = yaml.load(f) self._cash = config['cash'] self._base_cash = self._cash self._begin_date = config['begin'] self._end_date = config['end'] #Trade period config if "trade_period" in config: self._trade_peroid_set = True self._trade_peroid_begin = config["trade_period"]["begin"] self._trade_peroid_end = config["trade_period"]["end"] else: self._trade_peroid_set = False # Compare with self._benchmark_name = config['benchmark'] self._benchmark_data = None # Use database to store data. database_config = config['database'] if database_config['name'] == 'mysql': self._database = MySQLUtils(database_config['user'], str(database_config['passwd']), database_config['database'], database_config['source']) elif database_config['name'] == 'rds': self._database = RDSDB(self.logger) else: raise ValueError("Do not support data source") if isinstance(config['test_list'], list): self._backtest_list = config['test_list'] else: self._backtest_list = self._database.get_all_stock() self._qury_type = config['query_type'] self._need_data_length = config['need_data_length'] self._summary = {} self._strategy = None # Use to save the everydays return and loss self.asset_dict = {} self.asset_daliy = [] self._analysis = None self._trade_strategy = None self._date_type = config['date_type'] self._tax = config["tax"] self._market = Market() self._account = Account(self._cash, self._database) self._tax_processor = TaxProcessor() self._tax_processor.init_from_config(config)
# coding=utf-8 from backtest.account import Account class Context(object): """ This class is used to save the result. """ def __init__(self): self.account = None self.db = None self.date = None self.asset_code = None if __name__ == "__main__": context = Context() context.account = Account(1000)