Commit 3a75d3cf authored by Dr.李's avatar Dr.李

fixed error

parent 4b1287b6
......@@ -7,11 +7,13 @@ Created on 2017-5-25
from typing import Optional
from typing import Tuple
from typing import Union
import numpy as np
import pandas as pd
from alphamind.data.standardize import standardize
from alphamind.data.winsorize import winsorize_normal
from alphamind.portfolio.constraints import Constraints
from alphamind.portfolio.constraints import LinearConstraints
from alphamind.portfolio.longshortbulder import long_short_build
from alphamind.portfolio.rankbuilder import rank_build
from alphamind.portfolio.linearbuilder import linear_build
......@@ -60,7 +62,7 @@ def factor_analysis(factors: pd.DataFrame,
def er_portfolio_analysis(er: np.ndarray,
industry: np.ndarray,
dx_return: np.ndarray,
constraints: Optional[Constraints]=None,
constraints: Optional[Union[LinearConstraints, Constraints]]=None,
detail_analysis=True,
benchmark: Optional[np.ndarray] = None,
is_tradable: Optional[np.ndarray] = None,
......
......@@ -14,6 +14,10 @@ from alphamind.data.engines.universe import Universe
from alphamind.data.processing import factor_processing
from alphamind.portfolio.constraints import Constraints
from alphamind.portfolio.constraints import LinearConstraints
from alphamind.portfolio.constraints import BoundaryType
from alphamind.portfolio.constraints import BoundaryDirection
from alphamind.portfolio.constraints import create_box_bounds
from alphamind.portfolio.evolver import evolve_positions
from alphamind.data.engines.sqlengine import risk_styles
......@@ -58,6 +62,10 @@ __all__ = [
'Universe',
'factor_processing',
'Constraints',
'LinearConstraints',
'BoundaryType',
'BoundaryDirection',
'create_box_bounds',
'evolve_positions',
'risk_styles',
'industry_styles',
......
......@@ -53,7 +53,7 @@ class BoundaryImpl(object):
if self.b_type == BoundaryType.ABSOLUTE:
return self.val + center
else:
pyFinAssert(center > 0., ValueError, "relative bounds only support positive back bone value")
pyFinAssert(center >= 0., ValueError, "relative bounds only support positive back bone value")
return self.val * center
......@@ -72,7 +72,7 @@ class BoxBoundary(object):
def create_box_bounds(names: List[str],
b_type: BoundaryType,
b_type: Union[Iterable[BoundaryType], BoundaryType],
l_val: Union[Iterable[float], float],
u_val: Union[Iterable[float], float]) -> Dict[str, BoxBoundary]:
"""
......@@ -80,6 +80,9 @@ def create_box_bounds(names: List[str],
"""
bounds = dict()
if not hasattr(b_type, '__iter__'):
b_type = np.array([b_type] * len(names))
if not hasattr(l_val, '__iter__'):
l_val = np.array([l_val] * len(names))
......@@ -88,10 +91,10 @@ def create_box_bounds(names: List[str],
for i, name in enumerate(names):
lower = BoundaryImpl(BoundaryDirection.LOWER,
b_type,
b_type[i],
l_val[i])
upper = BoundaryImpl(BoundaryDirection.UPPER,
b_type,
b_type[i],
u_val[i])
bounds[name] = BoxBoundary(lower, upper)
return bounds
......@@ -122,6 +125,7 @@ class LinearConstraints(object):
upper_bounds.append(u)
return np.array(lower_bounds), np.array(upper_bounds)
@property
def risk_exp(self) -> np.ndarray:
return self.cons_mat[self.names].values
......
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