Skip to content

Commit

Permalink
Int
Browse files Browse the repository at this point in the history
  • Loading branch information
PharosAbad committed Apr 22, 2023
1 parent bc84b3e commit c4b1b3d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "LightenQP"
uuid = "732b1220-b3b1-47df-92b9-9aafce73c71b"
authors = ["Pharos Abad"]
version = "1.0.7"
version = "1.0.8"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
26 changes: 24 additions & 2 deletions examples/SpeedAccuracy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

using EfficientFrontier, LinearAlgebra
using TranscodingStreams, CodecXz, Serialization, Downloads
using LightenQP: LightenQP #, solveOOQP
import LightenQP: OOQP, fPortfolio

if length(filter((x) -> x == :uOSQP, names(Main, imported=true))) == 0
include("./uOSQP.jl")
Expand All @@ -15,6 +17,26 @@ if length(filter((x) -> x == :uClarabel, names(Main, imported=true))) == 0
using .uClarabel
end

function OOQP(P::Problem{T}) where {T}
#Pack P into OOQP
(; E, V, u, d, G, g, A, b, N, M, J) = P
iu = findall(u .< Inf)
C = [G; -Matrix{T}(I, N, N); Matrix{T}(I, N, N)[iu, :]]
gq = [g; -d; u[iu]]
L = J + N + length(iu)
OOQP{T}(V, A, C, E, b, gq, N, M, L)
end

function fPortfolio(P::Problem{T}; settings=LightenQP.Settings{T}(), L=0.0) where {T}
Q = OOQP(P)
fPortfolio(Q; settings=settings, L=L)
end

function fPortfolio(P::Problem{T}, mu::T; settings=LightenQP.Settings{T}(), check=true) where {T}
Q = OOQP(P)
fPortfolio(Q, mu; settings=settings, check=check)
end

function testData(ds::Symbol)
if ds == :Ungil
E, V = EfficientFrontier.EVdata(:Ungil, false)
Expand Down Expand Up @@ -268,10 +290,10 @@ nothing


#=
Remark:
Remark:
* OSQP is dangerous when mu version is computed, low accuracy, volatile speed (fastest near LMEP, but slowest near HMEP, Highest Mean Efficient Portfolio)
* OSQP is very good, when L is used. Accuracy 1.28e-10 (SP500 and Ungil), very good (deteriorate near LMEP ); speed 0.0751 (Ungil) and 0.0909 (SP500), fastest, no speed down at HMEP;
* OSQP is very good, when L is used. Accuracy 1.28e-10 (SP500 and Ungil), very good (deteriorate near LMEP ); speed 0.0751 (Ungil) and 0.0909 (SP500), fastest, no speed down at HMEP;
objective 7.53e-14 (SP500 and Ungil), very good
=#
30 changes: 15 additions & 15 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ define the following convex quadratic programming problems (called OOQP)
s.t. Ax=b ∈ R^{M}
Cx≤g ∈ R^{L}
```
default values for OOQP(V, q; kwargs...): A = ones(1,N), b = [1], C = -I, g = zeros(N). Which define a portfolio optimization without short-sale
default values for OOQP(V, q; kwargs...): A = ones(1,N), b = [1], C = -I, g = zeros(N). Which define a portfolio optimization without short-sale
For portfolio optimization
OOQP(V, q) : for no short-sale
OOQP(V, q) : for no short-sale
OOQP(V, q, u) : for bounds 0 <= x <= u, and thus A = ones(1,N), b = [1], C = [-I; I], g = [zeros(N); u]
See [`Documentation for LightenQP.jl`](https://github.com/PharosAbad/LightenQP.jl/wiki)
Expand All @@ -30,21 +30,21 @@ struct OOQP{T<:AbstractFloat}
q::Vector{T}
b::Vector{T}
g::Vector{T}
N::Int32
M::Int32
L::Int32
N::Int
M::Int
L::Int
end

OOQP(args...) = OOQP{Float64}(args...)

function OOQP(V, q::Vector{T};
A=ones(1, length(q)),
function OOQP(V, q::Vector{T}; N = length(q),
A=ones(1, N),
b=ones(1),
C=-Matrix(I, length(q), length(q)),
g=zeros(length(q))) where {T}
C=-Matrix(I, N, N),
g=zeros(N)) where {T}

#T = typeof(q).parameters[1]
N::Int32 = length(q)
#N = length(q)
(N, N) == size(V) || throw(DimensionMismatch("incompatible dimension: V"))

qq = copy(vec(q)) #make sure vector and a new copy
Expand All @@ -55,8 +55,8 @@ function OOQP(V, q::Vector{T};
gb = g[ik]
Cb = C[ik, :]

M::Int32 = length(b)
L::Int32 = length(gb)
M = length(b)
L = length(gb)
(M, N) == size(A) || throw(DimensionMismatch("incompatible dimension: A"))
(L, N) == size(Cb) || throw(DimensionMismatch("incompatible dimension: C"))

Expand All @@ -70,7 +70,7 @@ end

function OOQP(V, q::Vector{T}, u) where {T}
#T = typeof(q).parameters[1]
N::Int32 = length(q)
N = length(q)
(N, N) == size(V) || throw(DimensionMismatch("incompatible dimension: V"))
A = ones(T, 1, N)
b = ones(T, 1)
Expand All @@ -87,7 +87,7 @@ end
#OOQP + bounds d <= x <= u
function OOQP(V, A, C, q::Vector{T}, b, g, d, u) where {T}
#T = typeof(q).parameters[1]
N::Int32 = length(q)
N = length(q)
(N, N) == size(V) || throw(DimensionMismatch("incompatible dimension: V"))
id = findall(d .> -Inf)
iu = findall(u .< Inf)
Expand Down Expand Up @@ -152,7 +152,7 @@ end


"""
struct Solution
Solution strcture to the following convex quadratic programming problems (called OOQP)
Expand Down

2 comments on commit c4b1b3d

@PharosAbad
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/82094

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.0.8 -m "<description of version>" c4b1b3dc23396ddb014d95ba430d4cad0734203c
git push origin v1.0.8

Please sign in to comment.