phschiele / pycla Goto Github PK
View Code? Open in Web Editor NEWA Python Package for Portfolio Optimization using the Critical Line Algorithm
A Python Package for Portfolio Optimization using the Critical Line Algorithm
I have used this fragment.
def init_algo_lp(
mean: MATRIX,
lower_bounds: MATRIX,
upper_bounds: MATRIX,
A_eq: MATRIX | None = None,
b_eq: MATRIX | None = None,
A_ub: MATRIX | None = None,
b_ub: MATRIX | None = None,
) -> Next:
if A_eq is None:
A_eq = np.atleast_2d(np.ones_like(mean))
if b_eq is None:
b_eq = np.array([1.0])
if A_ub is None:
A_ub = np.atleast_2d(np.zeros_like(mean))
if b_ub is None:
b_ub = np.array([0.0])
w = cp.Variable(mean.shape[0], "weights")
objective = cp.Maximize(mean.T @ w)
constraints = [
A_eq @ w == b_eq,
A_ub @ w <= b_ub,
lower_bounds <= w,
w <= upper_bounds,
]
cp.Problem(objective, constraints).solve()
w = w.value
# compute the distance from the closest bound
distance = np.min(
np.array([np.abs(w - lower_bounds), np.abs(upper_bounds - w)]), axis=0
)
# which element has the largest distance to any bound?
# Even if all assets are at their bounds,
# we get a (somewhat random) free asset.
index = np.argmax(distance)
free = np.full_like(mean, False, dtype=np.bool_)
free[index] = True
return Next(free=free, weights=w, mean=mean.T @ w)
Hi,
Thank you for developing this package.
I was playing a bit with it and I am wondering how to increase the number of points computed to draw the efficient frontier?
With my input, only 9 points are computed, which is too low to achieve my goal of finding the optimal weights for a given volatility target (let say 10%).
Is there a way to achieve what I am looking for?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.