-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
272 additions
and
121 deletions.
There are no files selected for viewing
43 changes: 37 additions & 6 deletions
43
examples/demo-project/backtest/default/default_backtest.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,40 @@ | ||
class DefaultTestmodule(): | ||
#finhack testmodule run | ||
import os | ||
import multiprocessing | ||
from finhack.trader.default.function import load_preds_data | ||
from finhack.library.mydb import mydb | ||
from finhack.trader.default.data import Data | ||
|
||
class DefaultBacktest(): | ||
def __init__(self): | ||
pass | ||
|
||
|
||
def run_command_with_semaphore(self, cmd, semaphore): | ||
with semaphore: | ||
try: | ||
os.system(cmd) | ||
except Exception as e: | ||
print(f'An error occurred: {e}') | ||
|
||
def run(self): | ||
print(backtest) | ||
pass | ||
|
||
Data.init_data(cache=True) | ||
cash_list = self.args.cash.split(',') | ||
model_list = mydb.selectToDf('select * from auto_train order by score desc', 'finhack') | ||
|
||
semaphore = multiprocessing.Semaphore(int(self.args.p)) # 创建一个信号量,最大允许3个进程同时运行 | ||
processes = [] | ||
|
||
for row in model_list.itertuples(): | ||
model_hash = getattr(row, 'hash') | ||
load_preds_data(model_hash, True) | ||
for cash in cash_list: | ||
cmd = 'finhack trader run --strategy=AITopNStrategy --log_level=ERROR --model_id=' + model_hash + ' --cash=' + cash | ||
print(cmd) | ||
# 创建Process对象,传入函数和需要的参数,包括信号量 | ||
p = multiprocessing.Process(target=self.run_command_with_semaphore, args=(cmd, semaphore)) | ||
processes.append(p) | ||
p.start() | ||
|
||
# 等待所有进程完成 | ||
for p in processes: | ||
p.join() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.