-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbase.py
33 lines (26 loc) · 931 Bytes
/
base.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
# !/usr/bin/env python
# -*-coding:utf-8 -*-
from abc import ABCMeta, abstractmethod
from typing import List, Dict, Tuple, Union, Optional
class FactorBase(metaclass=ABCMeta):
'''因子基础类
'''
def __init__(self, name: Union[List, str], desc: Union[List, str]):
self.name = name
self.desc = desc
self.factor_data = {}
@abstractmethod
def cal(self, input_data=None, **kwargs):
'''计算因子值
'''
pass
def check_output(self):
'''检查输出
'''
factors_names = self.factor_data.keys()
if len(factors_names) == 0 or len(factors_names) != len(self.name):
raise ValueError(f'因子计算结果为空或者因子名称与输出不一致, {self.name} != {factors_names}')
def run(self, input_data=None) -> Dict:
self.cal(input_data)
self.check_output()
return self.factor_data