Commit 8c79003a authored by Dr.李's avatar Dr.李

added strategy

parent 69504bfe
...@@ -20,6 +20,7 @@ from alphamind.data.winsorize import winsorize_normal ...@@ -20,6 +20,7 @@ from alphamind.data.winsorize import winsorize_normal
from alphamind.data.rank import rank from alphamind.data.rank import rank
from alphamind.data.standardize import standardize from alphamind.data.standardize import standardize
from alphamind.model.loader import load_model from alphamind.model.loader import load_model
from alphamind.model.linearmodel import ConstLinearModel
PROCESS_MAPPING = { PROCESS_MAPPING = {
'winsorize_normal': winsorize_normal, 'winsorize_normal': winsorize_normal,
...@@ -144,11 +145,13 @@ def train_model(ref_date: str, ...@@ -144,11 +145,13 @@ def train_model(ref_date: str,
x_values: pd.DataFrame = None, x_values: pd.DataFrame = None,
y_values: pd.DataFrame = None): y_values: pd.DataFrame = None):
base_model = copy.deepcopy(alpha_model) base_model = copy.deepcopy(alpha_model)
if x_values is None:
train_data = data_meta.fetch_train_data(ref_date, alpha_model) if not isinstance(alpha_model, ConstLinearModel):
x_values = train_data['train']['x'] if x_values is None:
y_values = train_data['train']['y'] train_data = data_meta.fetch_train_data(ref_date, alpha_model)
base_model.fit(x_values, y_values) x_values = train_data['train']['x']
y_values = train_data['train']['y']
base_model.fit(x_values, y_values)
return base_model return base_model
......
...@@ -22,7 +22,7 @@ class ConstLinearModelImpl(object): ...@@ -22,7 +22,7 @@ class ConstLinearModelImpl(object):
self.weights = weights.flatten() self.weights = weights.flatten()
def fit(self, x: np.ndarray, y: np.ndarray): def fit(self, x: np.ndarray, y: np.ndarray):
pass raise NotImplementedError("Const linear model doesn't offer fit methodology")
def predict(self, x: np.ndarray): def predict(self, x: np.ndarray):
return x @ self.weights return x @ self.weights
......
...@@ -108,7 +108,7 @@ class LinearConstraints(object): ...@@ -108,7 +108,7 @@ class LinearConstraints(object):
backbone: np.ndarray=None): backbone: np.ndarray=None):
pyFinAssert(len(bounds) == cons_mat.shape[1], "Number of bounds should be same as number of col of cons_mat") pyFinAssert(len(bounds) == cons_mat.shape[1], "Number of bounds should be same as number of col of cons_mat")
self.names = list(bounds.keys()) self.names = list(set(bounds.keys()).intersection(set(cons_mat.columns)))
self.bounds = bounds self.bounds = bounds
self.cons_mat = cons_mat self.cons_mat = cons_mat
self.backbone = backbone self.backbone = backbone
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment