Commit 614b98a4 authored by Dr.李's avatar Dr.李

added ipopt

parent e5182b39
...@@ -8,5 +8,7 @@ Alpha_Mind.egg-info/* ...@@ -8,5 +8,7 @@ Alpha_Mind.egg-info/*
*.cpp *.cpp
*.html *.html
*.nbc *.nbc
*.nbi *.nbi
/notebooks/.ipynb_checkpoints /notebooks/.ipynb_checkpoints
\ No newline at end of file alphamind/examples/*
notebooks/*
\ No newline at end of file
...@@ -29,10 +29,10 @@ cdef class LPOptimizer: ...@@ -29,10 +29,10 @@ cdef class LPOptimizer:
cnp.ndarray[double] ubound, cnp.ndarray[double] ubound,
cnp.ndarray[double] objective): cnp.ndarray[double] objective):
self.cobj = new LpOptimizer(cons_matrix.flatten().copy(), self.cobj = new LpOptimizer(cons_matrix.flatten(),
lbound.copy(), lbound,
ubound.copy(), ubound,
objective.copy()) objective)
def __del__(self): def __del__(self):
del self.cobj del self.cobj
...@@ -43,5 +43,35 @@ cdef class LPOptimizer: ...@@ -43,5 +43,35 @@ cdef class LPOptimizer:
def feval(self): def feval(self):
return self.cobj.feval() return self.cobj.feval()
def x_value(self):
return np.array(self.cobj.xValue())
cdef extern from "meanvariance.hpp" namespace "pfopt":
cdef cppclass MeanVariance:
MeanVariance(vector[double], vector[double], double) except +
vector[double] xValue()
double feval()
cdef class MVOptimizer:
cdef MeanVariance* cobj
def __init__(self,
cnp.ndarray[double] expected_return,
cnp.ndarray[double, ndim=2] cov_matrix,
double risk_aversion):
self.cobj = new MeanVariance(expected_return,
cov_matrix.flatten(),
risk_aversion)
def __del__(self):
del self.cobj
def feval(self):
return self.cobj.feval()
def x_value(self): def x_value(self):
return np.array(self.cobj.xValue()) return np.array(self.cobj.xValue())
\ No newline at end of file
...@@ -8,7 +8,7 @@ Created on 2017-5-5 ...@@ -8,7 +8,7 @@ Created on 2017-5-5
import numpy as np import numpy as np
from typing import Tuple from typing import Tuple
from typing import Union from typing import Union
from alphamind.cython.lpoptimizer import LPOptimizer from alphamind.cython.optimizers import LPOptimizer
def linear_build(er: np.ndarray, def linear_build(er: np.ndarray,
......
...@@ -24,8 +24,8 @@ else: ...@@ -24,8 +24,8 @@ else:
if platform.system() != "Windows": if platform.system() != "Windows":
extensions = [ extensions = [
Extension('alphamind.cython.lpoptimizer', Extension('alphamind.cython.optimizers',
['alphamind/cython/lpoptimizer.pyx'], ['alphamind/cython/optimizers.pyx'],
include_dirs=["./libs/include/clp", include_dirs=["./libs/include/clp",
"./libs/include/ipopt", "./libs/include/ipopt",
"./libs/include/pfopt", "./libs/include/pfopt",
...@@ -36,8 +36,8 @@ if platform.system() != "Windows": ...@@ -36,8 +36,8 @@ if platform.system() != "Windows":
] ]
else: else:
extensions = [ extensions = [
Extension('alphamind.cython.lpoptimizer', Extension('alphamind.cython.optimizers',
['alphamind/cython/lpoptimizer.pyx'], ['alphamind/cython/optimizers.pyx'],
include_dirs=["./libs/include/clp", include_dirs=["./libs/include/clp",
"./libs/include/ipopt", "./libs/include/ipopt",
"./libs/include/pfopt", "./libs/include/pfopt",
......
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