Download backtest_framework(4)/backtest_framework/strategy_base.py from 2090741942justin/quant: direct link, hf CLI and curl.
- Browser
- Download file 2.11 kB
-
https://huggingface.co/datasets/2090741942justin/quant/resolve/main/backtest_framework(4)/backtest_framework/strategy_base.py
- Command line
-
hf download 'hf://datasets/2090741942justin/quant/backtest_framework(4)/backtest_framework/strategy_base.py'
-
curl -L -o strategy_base.py 'https://huggingface.co/datasets/2090741942justin/quant/resolve/main/backtest_framework(4)/backtest_framework/strategy_base.py'
2.11 kB
| # coding: UTF-8 | |
| import os | |
| import time | |
| import copy | |
| from abc import ABCMeta, abstractmethod | |
| from backtest_framework.factor_generator import FactorGenerator | |
| from backtest_framework.print_type import PrintType as p | |
| import sys | |
| from wby_utils.config.Config import Config | |
| class StrategyBase(metaclass=ABCMeta): | |
| def __init__(self, factorName, config_path): | |
| config = Config(config_path) | |
| self.dataApi = FactorGenerator(factorName, config) | |
| def run(self): | |
| tic_time = time.time() | |
| if self.dataApi.multiSave == False: | |
| self.dataApi.loadDerivativeFactorToGlobal(self.dataApi.factorName) | |
| self.dataApi.getStartTradeDate() | |
| self.dataApi.getEndTradeDate() | |
| trade_date = self.dataApi.getAllData("trade_date_int") | |
| for i in range(self.dataApi.startDateFlag, | |
| self.dataApi.endDateFlag + 1): | |
| start_time = time.time() | |
| self.dataApi.setLpp(i) | |
| self.strategy() | |
| self.dataApi.barCount += 1 | |
| end_time = time.time() | |
| p.timer_print( | |
| sys._getframe().f_code.co_filename, | |
| sys._getframe().f_code.co_name, | |
| " " + self.dataApi.factorName + " 因子运行至" + str(trade_date[i][0]) + ",单日截面计算耗时" + str( | |
| end_time - start_time) + '秒!') | |
| if self.dataApi.multiSave == False: | |
| self.dataApi.saveGlobal(self.dataApi.factorName) | |
| toc_time = time.time() | |
| p.timer_print( | |
| sys._getframe().f_code.co_filename, | |
| sys._getframe().f_code.co_name, | |
| self.dataApi.factorName + "因子生成程序运行完毕,计算总计耗时" + str(toc_time - tic_time) + '秒!') | |
| def strategy(self): | |
| """ | |
| 策略的具体实现, 需要重载 | |
| """ | |
| pass | |
| def get_factor_name(file_name): | |
| return os.path.basename(file_name).split('.')[0] | |
| def get_pre_factor_name() -> list: | |
| pass | |