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

added strategy

parent 69504bfe
......@@ -20,6 +20,7 @@ from alphamind.data.winsorize import winsorize_normal
from alphamind.data.rank import rank
from alphamind.data.standardize import standardize
from alphamind.model.loader import load_model
from alphamind.model.linearmodel import ConstLinearModel
PROCESS_MAPPING = {
'winsorize_normal': winsorize_normal,
......@@ -144,11 +145,13 @@ def train_model(ref_date: str,
x_values: pd.DataFrame = None,
y_values: pd.DataFrame = None):
base_model = copy.deepcopy(alpha_model)
if x_values is None:
train_data = data_meta.fetch_train_data(ref_date, alpha_model)
x_values = train_data['train']['x']
y_values = train_data['train']['y']
base_model.fit(x_values, y_values)
if not isinstance(alpha_model, ConstLinearModel):
if x_values is None:
train_data = data_meta.fetch_train_data(ref_date, alpha_model)
x_values = train_data['train']['x']
y_values = train_data['train']['y']
base_model.fit(x_values, y_values)
return base_model
......
......@@ -22,7 +22,7 @@ class ConstLinearModelImpl(object):
self.weights = weights.flatten()
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):
return x @ self.weights
......
......@@ -108,7 +108,7 @@ class LinearConstraints(object):
backbone: np.ndarray=None):
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.cons_mat = cons_mat
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