-
Notifications
You must be signed in to change notification settings - Fork 1
/
rolling.py
57 lines (50 loc) · 1.93 KB
/
rolling.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
'''
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
Author: wlvh [email protected]
Date: 2023-06-20 06:14:07
LastEditors: wlvh [email protected]
LastEditTime: 2024-05-23 04:45:27
FilePath: /trading/rolling.py
Description:
Copyright (c) 2023 by ${[email protected]}, All Rights Reserved.
'''
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Jun 8 16:56:04 2023
@author: lyuhongwang
"""
import os
# 动态设置环境变量,限制numpy和pandas使用单线程
os.environ['OMP_NUM_THREADS'] = '1'
os.environ['OPENBLAS_NUM_THREADS'] = '1'
os.environ['MKL_NUM_THREADS'] = '1'
os.environ['VECLIB_MAXIMUM_THREADS'] = '1'
os.environ['NUMEXPR_NUM_THREADS'] = '1'
import datetime as dt
from DIY_Volume_numpy import optimize_and_run,find_row_by_date,evaluate_opt_results
from rolling_strategy_test import *
import pandas as pd
import json
import argparse
def load_data(filepath):
df = pd.read_csv(filepath, sep=',')
df['datetime'] = pd.to_datetime(df['datetime'], format='%Y-%m-%d %H:%M:%S')
df.set_index('datetime', inplace=True)
return df
def main():
parser = argparse.ArgumentParser()
parser.add_argument("target", help="The target to optimize and run")
parser.add_argument("data_file", help="The data file to load")
parser.add_argument("end_date", help="The end date of the data")
parser.add_argument("data_period", type=int, help="The data period for rolling strategy test")
parser.add_argument("num_evals", type=int, help="How much trials would training for rolling strategy test")
parser.add_argument("strategy_name", type=str, help="Which strategy should be apply")
args = parser.parse_args()
df = load_data(args.data_file)
df.fillna(method='ffill', inplace=True)
target = args.target
rolling_strategy_test(df, data_period=args.data_period, num_evals=args.num_evals, targets=target,end_date=args.end_date, strategy_name=args.strategy_name)
if __name__ == "__main__":
main()