An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20130710/891d2bba/attachment.pl>
efficient linear programming problem!
3 messages · Daniel Duan, Brian G. Peterson, Alexios Ghalanos
Try rglpk. In my experience it is faster than Rsymphony
On 07/10/2013 06:50 AM, Daniel Duan wrote:
Dear all,
I am dealing with a Linear Programming problem which involve intensive
caculation and my code seems quite inefficient: it take 10 to 30 minutes to
finish a single optimization. I wonder can anyone give me some advice on
how
to improve it. Any suggestions as to packages or code that will work
efficiently for my problem would be much appreciated.
Thanks!
Here are my code:
data: rmat is a time series object with s row and n column(or s*n
matrix,s=130,n=30)
memory.limit(12000)
require(Rsymphony)
P.risk_parameter<-c(106,44,4,3)
# parameter
PRAF10<-
function(p,risk_parameter=P.risk_parameter[2]){risk_parameter*(1-p)^(risk_parameter-1)}
# function
Amat.function<-function(rmat,RFR=0){
n = ncol(rmat)
s = nrow(rmat)
# construct constraint matrix
A<-matrix(0,2*s*s+3,s*s+s+n+1)
A[1,1:n]<- colMeans(rmat)
A[1,s*s+s+n+1]<- -RFR
A[2,1:n]<- 1
A[2,s*s+s+n+1]<- -1
for(i in 1:s)(A[(3+(i-1)*s):(i*s+2),1:n]<-rmat )
for(i in 1:s)(A[(3+(i-1)*s):(i*s+2),n+i]<- -1)
A[3:(s*s+2),(n+s+1):(s*s+s+n)]<- diag(s*s)
A[(3+s*s):(2*s*s+2),(n+s+1):(s*s+s+n)]<-diag(s*s)
A[3:(2*s*s+2),s*s+s+n+1]<- -RFR
A[2*s*s+3,s*s+s+n+1]<- 1
return(A)
}
[[alternative HTML version deleted]]
_______________________________________________ R-SIG-Finance at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Brian G. Peterson http://braverock.com/brian/ Ph: 773-459-4973 IM: bgpbraverock
Quick suggestion: If there is sparsity in your matrix you may benefit from using slam (Rsymphony and Rglpk both accept slam matrices). -Alexios
On 10 Jul 2013, at 12:50, Daniel Duan <elephann at gmail.com> wrote:
Dear all,
I am dealing with a Linear Programming problem which involve intensive
caculation and my code seems quite inefficient: it take 10 to 30 minutes to
finish a single optimization. I wonder can anyone give me some advice on
how
to improve it. Any suggestions as to packages or code that will work
efficiently for my problem would be much appreciated.
Thanks!
Here are my code:
data: rmat is a time series object with s row and n column(or s*n
matrix,s=130,n=30)
memory.limit(12000)
require(Rsymphony)
P.risk_parameter<-c(106,44,4,3)
# parameter
PRAF10<-
function(p,risk_parameter=P.risk_parameter[2]){risk_parameter*(1-p)^(risk_parameter-1)}
# function
Amat.function<-function(rmat,RFR=0){
n = ncol(rmat)
s = nrow(rmat)
# construct constraint matrix
A<-matrix(0,2*s*s+3,s*s+s+n+1)
A[1,1:n]<- colMeans(rmat)
A[1,s*s+s+n+1]<- -RFR
A[2,1:n]<- 1
A[2,s*s+s+n+1]<- -1
for(i in 1:s)(A[(3+(i-1)*s):(i*s+2),1:n]<-rmat )
for(i in 1:s)(A[(3+(i-1)*s):(i*s+2),n+i]<- -1)
A[3:(s*s+2),(n+s+1):(s*s+s+n)]<- diag(s*s)
A[(3+s*s):(2*s*s+2),(n+s+1):(s*s+s+n)]<-diag(s*s)
A[3:(2*s*s+2),s*s+s+n+1]<- -RFR
A[2*s*s+3,s*s+s+n+1]<- 1
return(A)
}
[[alternative HTML version deleted]]
_______________________________________________ R-SIG-Finance at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.