ojalgo-user Mailing List for oj! Algorithms (Page 22)
Mathematics, linear algebra and optimisation
Brought to you by:
apete
You can subscribe to this list here.
2003 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(1) |
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
---|---|---|---|---|---|---|---|---|---|---|---|---|
2004 |
Jan
|
Feb
(1) |
Mar
|
Apr
(14) |
May
(1) |
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
|
Dec
(1) |
2005 |
Jan
(3) |
Feb
|
Mar
|
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
(1) |
Sep
(3) |
Oct
|
Nov
|
Dec
(1) |
2006 |
Jan
(1) |
Feb
(1) |
Mar
(1) |
Apr
|
May
(1) |
Jun
(2) |
Jul
|
Aug
(5) |
Sep
|
Oct
(3) |
Nov
(4) |
Dec
(2) |
2007 |
Jan
(8) |
Feb
(1) |
Mar
(2) |
Apr
(11) |
May
(6) |
Jun
|
Jul
(10) |
Aug
(2) |
Sep
|
Oct
(4) |
Nov
|
Dec
(11) |
2008 |
Jan
(22) |
Feb
(4) |
Mar
(2) |
Apr
(4) |
May
(2) |
Jun
|
Jul
|
Aug
(1) |
Sep
|
Oct
(6) |
Nov
(17) |
Dec
(5) |
2009 |
Jan
(15) |
Feb
(2) |
Mar
(2) |
Apr
(3) |
May
(4) |
Jun
(5) |
Jul
(9) |
Aug
(2) |
Sep
|
Oct
(5) |
Nov
(14) |
Dec
|
2010 |
Jan
(3) |
Feb
(5) |
Mar
(2) |
Apr
(19) |
May
|
Jun
|
Jul
|
Aug
(2) |
Sep
|
Oct
(5) |
Nov
(3) |
Dec
|
2011 |
Jan
|
Feb
(1) |
Mar
(7) |
Apr
(10) |
May
(1) |
Jun
(15) |
Jul
(1) |
Aug
|
Sep
|
Oct
(13) |
Nov
(9) |
Dec
(11) |
2012 |
Jan
|
Feb
(1) |
Mar
(9) |
Apr
(23) |
May
(16) |
Jun
(9) |
Jul
(13) |
Aug
|
Sep
(4) |
Oct
(1) |
Nov
(1) |
Dec
|
2013 |
Jan
|
Feb
(12) |
Mar
(7) |
Apr
(24) |
May
|
Jun
(7) |
Jul
(4) |
Aug
|
Sep
(3) |
Oct
(16) |
Nov
(7) |
Dec
(3) |
2014 |
Jan
(22) |
Feb
(1) |
Mar
(1) |
Apr
|
May
(2) |
Jun
(3) |
Jul
(4) |
Aug
(4) |
Sep
(1) |
Oct
(2) |
Nov
(6) |
Dec
(2) |
2015 |
Jan
(11) |
Feb
(10) |
Mar
(1) |
Apr
(9) |
May
|
Jun
|
Jul
(1) |
Aug
(4) |
Sep
(6) |
Oct
(3) |
Nov
(15) |
Dec
(4) |
2016 |
Jan
(6) |
Feb
|
Mar
(18) |
Apr
(5) |
May
(9) |
Jun
(3) |
Jul
(5) |
Aug
(2) |
Sep
(5) |
Oct
(2) |
Nov
|
Dec
(5) |
2017 |
Jan
(4) |
Feb
(3) |
Mar
|
Apr
|
May
(12) |
Jun
(1) |
Jul
(4) |
Aug
|
Sep
(3) |
Oct
(1) |
Nov
|
Dec
(1) |
2018 |
Jan
(5) |
Feb
|
Mar
(1) |
Apr
(1) |
May
(1) |
Jun
|
Jul
(4) |
Aug
(1) |
Sep
(8) |
Oct
|
Nov
|
Dec
(1) |
2019 |
Jan
|
Feb
(2) |
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2022 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Anders P. <an...@op...> - 2009-04-16 06:30:24
|
Worked hard on improving performance on BasicMatrix operations (which means I had to optimise everything else). What I measure is how much faster/slower PrimitiveMatrix is compared to JamaMatrix, and the same correspondingly for decompositions. If "primitive" on an average used to be (v25) 5% to 10% faster than "jama", it is now roughly 25% faster. With decompositions the main improvements seem to be where "primitive" were already performing very well. The QR and SingularValue decompositions used to be 12 and 8 times faster than "jama" on tall matrices. Now they are 15 and 11 times faster. Try it yourself! /Anders On 15 apr 2009, at 16.57, Anders Peterson wrote: > v27 has been released. > > http://ojalgo.org/change_log.html > > /Anders > > ------------------------------------------------------------------------------ > This SF.net email is sponsored by: > High Quality Requirements in a Collaborative Environment. > Download a free trial of Rational Requirements Composer Now! > http://p.sf.net/sfu/www-ibm-com > _______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user |
From: Anders P. <an...@op...> - 2009-04-15 14:57:45
|
v27 has been released. http://ojalgo.org/change_log.html /Anders |
From: Anders P. <an...@op...> - 2009-03-25 09:36:54
|
I update the download files now and then (just did). Several operations on PrimitiveMatrix should be up to twice as fast as with previous versions. I'd very much like confirmation from other users that you also get/notice/can measure this improvement. /Anders On 17 mar 2009, at 09.02, Anders Peterson wrote: > This is not v27 - it's a pre-release of that version. Expect v27 to > be released soon after Easter. > > I would very much like feedback on performance differences between > v27 and v26. Particularity if you have access to a machine with 4 or > more CPUs (cores). > > /Anders |
From: Anders P. <an...@op...> - 2009-03-17 08:03:00
|
This is not v27 - it's a pre-release of that version. Expect v27 to be released soon after Easter. I would very much like feedback on performance differences between v27 and v26. Particularity if you have access to a machine with 4 or more CPUs (cores). /Anders |
From: Anders P. <an...@op...> - 2009-02-02 09:11:59
|
Thanks for the bug report. I've committed your suggested changes with only small modifications. /Anders On 2 feb 2009, at 03.23, Stefan Richthofer wrote: > Hello everybody, > I just tested ojalgo v.26 and experienced nullpointer-exceptions > when I tried to optimize any QP without equality-constraints. > > I think, I fixed the problem and want to bring the bugfix back to > you with this email. It was no big deal, since I only added null- > testing lines for the AE-matrix in > org.ojalgo.optimisation.quadratic.ActiveSetSolver and > org.ojalgo.optimisation.quadratic.LagrangeSolver > and added some lines for doing the job without the AE-matrix and > the BE-vector. > I hope, my solution is correct, since I'm not really familiar with > the subject of quadratic optimisation. The few simple problems, I > tested seem to be optimized well, also without equality > constraints now. > > I marked the code changes with > //change by swr: > > > > greetings > > Stefan > -- > Psssst! Schon vom neuen GMX MultiMessenger gehört? Der kann`s mit > allen: http://www.gmx.net/de/go/ > multimessenger01<ActiveSetSolver.java><LagrangeSolver.java>----------- > ------------------------------------------------------------------- > This SF.net email is sponsored by: > SourcForge Community > SourceForge wants to tell your story. > http://p.sf.net/sfu/sf- > spreadtheword_______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user |
From: Stefan R. <Ste...@gm...> - 2009-02-02 02:23:52
|
Hello everybody, I just tested ojalgo v.26 and experienced nullpointer-exceptions when I tried to optimize any QP without equality-constraints. I think, I fixed the problem and want to bring the bugfix back to you with this email. It was no big deal, since I only added null-testing lines for the AE-matrix in org.ojalgo.optimisation.quadratic.ActiveSetSolver and org.ojalgo.optimisation.quadratic.LagrangeSolver and added some lines for doing the job without the AE-matrix and the BE-vector. I hope, my solution is correct, since I'm not really familiar with the subject of quadratic optimisation. The few simple problems, I tested seem to be optimized well, also without equality constraints now. I marked the code changes with //change by swr: greetings Stefan -- Psssst! Schon vom neuen GMX MultiMessenger gehört? Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger01 |
From: Anders P. <an...@op...> - 2009-01-21 12:36:47
|
https://sourceforge.net/project/showfiles.php? group_id=79000&package_id=80289 http://ojalgo.org/change_log.html /Anders |
From: Anders P. <an...@op...> - 2009-01-20 10:20:31
|
On 16 jan 2009, at 07.25, Anders Peterson wrote: > On 16 jan 2009, at 02.28, Ruan Weichao wrote: > >> Hi, >> >> Yes, that's the expected excess returns of my program. >> >> Is it right? >> >> Can the "expected excess returns" be negative? > > > I have no way of knowing what model/problem you want to solve... > > In a general case excess returns (what you get for taking a risk) > should not be negative. If they are, you do not need to optimise > anything. Just invest everything in the risk free asset. > > I'm not sure exactly why you get those negative (constraint > breaking) portfolio weights. I'm going to look into this, but > later. Don't hold your breath. For you, I think the solution is to > work on your model. This is fixed in CVS now. Your model does not get those constraint breaking portfolio weights anymore. The solution I get is 100% of the last instrument (the one with 0.0 excess return) which seems reasonable. /Anders > >> On Thu, 15 Jan 2009 14:09:43 +0100, Anders Peterson wrote >>> Your expected excess returns matrix looks like this: >>> >>> class org.ojalgo.matrix.BigMatrix >>> {{-0.010638291263564232}, >>> {-0.013500370827906071}, >>> {-0.011390037735101773}, >>> {-0.010385042339767682}, >>> {-0.0003812208389845893}, >>> {-0.002315505853720011}, >>> {0}} >>> >>> Is that correct? >>> >>> Earlier you wrote "And i found that if i change the nagetive >>> ExceptedReturn to positive, the result will be fine." >>> >>> /Anders >>> >>> On 15 jan 2009, at 11.10, Ruan Weichao wrote: >>> >>>> Hi,i am using v25 and here's my code: >>>> >>>> / >>>> ******************************************************************* >>>> *** >>>> **********/ >>>> >>>> import java.math.BigDecimal; >>>> import java.util.List; >>>> >>>> import org.ojalgo.finance.portfolio.MarketEquilibrium; >>>> import org.ojalgo.finance.portfolio.MarkowitzModel; >>>> import org.ojalgo.matrix.*; >>>> import org.ojalgo.matrix.store.BigDenseStore; >>>> import org.ojalgo.matrix.store.MatrixStore; >>>> >>>> >>>> public class TestMarkowitz { >>>> >>>> public double getCovarance(double[] value1, double[] value2){ >>>> >>>> int n = value1.length; >>>> double averOne = 0; >>>> double averTwo = 0; >>>> for(int i=0;i<n;i++) >>>> { >>>> averOne+=value1[i]; >>>> averTwo+=value2[i]; >>>> } >>>> averOne /= n; >>>> averTwo /= n; >>>> >>>> double sum = 0; >>>> for(int i=0;i<n;i++) >>>> sum+=(value1[i]-averOne)*(value2[i]-averTwo); >>>> >>>> return sum / (n-1); >>>> } >>>> >>>> public BasicMatrix getACovariances(double[][] returns){ >>>> >>>> int row = returns.length; >>>> int col = returns[0].length; >>>> MatrixStore<BigDecimal> a = BigDenseStore.FACTORY..makeZero(row, >>>> col); >>>> BasicMatrix covariances = new BigMatrix(a); >>>> >>>> for(int i=1;i<=row;i++){ >>>> for(int j=i;j<=col;j++){ >>>> double tmp = this.getCovarance(returns[i-1], returns[j-1]); >>>> covariances = covariances.set(i-1, j-1,tmp); >>>> covariances = covariances.set(j-1, i-1,tmp); >>>> } >>>> } >>>> return covariances; >>>> } >>>> >>>> public BasicMatrix getAnExpectedExcessReturns(double[][] returns){ >>>> >>>> int row = returns.length; >>>> int col = returns[0].length; >>>> >>>> MatrixStore<BigDecimal> a = BigDenseStore.FACTORY..makeZero >>>> (row, 1); >>>> BasicMatrix expectedExcessReturns = new BigMatrix(a); >>>> >>>> double riskFreeReturn = 0; >>>> for(int i=1;i<=col;i++) >>>> riskFreeReturn+=returns[row-1][i-1]; >>>> riskFreeReturn/=row; >>>> >>>> for(int i=1;i<=row;i++){ >>>> >>>> double tmp = 0; >>>> for(int j=1;j<=col;j++) >>>> tmp+=returns[i-1][j-1]; >>>> tmp/=col; >>>> >>>> expectedExcessReturns = expectedExcessReturns.set(i-1, 0, tmp- >>>> riskFreeReturn); >>>> } >>>> >>>> return expectedExcessReturns; >>>> } >>>> >>>> public static void main(String[] args) >>>> { >>>> int assetNum=7; >>>> double[][] assets_return={ >>>> {-1.5905837442343828E-4, -0.03062360801781757, >>>> -0.029857534032853142, -0.011811692726036832, >>>> -0.017972310602803136, 0.017338003502626997, 0.0}, >>>> {-0.02757158006362653, -0.02562704471101405, >>>> -0.011751538891997735, -0.024915062287655786, -0.01684088269454123, >>>> 0.013585351447135364, 0.0}, >>>> {-0.00699300699300693, -0.033802816901408676, >>>> -0.04675196850393671, -0.021166752710376546, -0.007911392405063583, >>>> 0.03827751196172254, 0.0}, >>>> {-0.007626310772164015, 0.0038424591738713027, >>>> 0.02488038277511978, 0.025210084033613675, -0.02003642987249557, >>>> -0.09758364312267642, 0.0}, >>>> {-0.03965053763440893, 0.021693491952414375, >>>> 0.01643835616438392, -0.007412398921833087, 0.01765105227427014, >>>> -0.010006671114076025, 0.0}, >>>> {-0.017821782178217872, 0.005040322580645311, >>>> 0.006018054162487363, 9.008107296569024E-4, 0.002999999999999824, >>>> -0.01196410767696908, 0.0}, >>>> {2.630552127527583E-4, 2.5867028174649627E-4, >>>> 2.3866431891514327E-4, 1.9564035993080523E-4, 2.351016690966669E-4, >>>> 1.9070675120065465E-4, 0.0} >>>> }; >>>> >>>> TestMarkowitz tm = new TestMarkowitz(); >>>> BasicMatrix covariances = tm.getACovariances(assets_return); >>>> BasicMatrix expectedExcessReturns = tm.getAnExpectedExcessReturns >>>> (assets_return); >>>> BigDecimal riskAversion = new BigDecimal(1.0); >>>> >>>> MarketEquilibrium marketEquilibrium = new MarketEquilibrium >>>> (covariances,riskAversion); >>>> MarkowitzModel markowitzModel = new MarkowitzModel >>>> (marketEquilibrium,expectedExcessReturns); >>>> >>>> for(int i=0;i<assetNum;i++){ >>>> markowitzModel.setLowerLimit(i, new BigDecimal(0.0)); >>>> markowitzModel.setUpperLimit(i, new BigDecimal(1.0)); >>>> } >>>> List<BigDecimal> re = markowitzModel.getWeights(); >>>> >>>> System.out.println("=======result===================="); >>>> for(int i=0;i<re.size();i++) >>>> System.out.println(re.get(i)); >>>> >>>> return; >>>> } >>>> >>>> } >>>> >>>> / >>>> ******************************************************************* >>>> *** >>>> **********/ >>>> >>>> and the result turn out as: >>>> >>>> -0.25 >>>> -0.25 >>>> -0.25 >>>> -0.25 >>>> 0.75 >>>> 0.75 >>>> 0.75 >>>> >>>> / >>>> ******************************************************************* >>>> *** >>>> ******/ >>>> >>>> If you find out any problem, just let me know , thanks a lot! >>>> >>>> On Thu, 15 Jan 2009 09:20:52 +0100, Anders Peterson wrote >>>>> You have to send code (snippets) that I can execute. >>>>> >>>>> Are you using v25 or the latest from cvs? >>>>> >>>>> How do you instantiate the ActiveSetSolver? >>>>> >>>>> What's the correct solution? >>>>> >>>>> You say that if you change the sign of "C" you get an ok result. >>>>> What does this mean? Did you make a mistake with the sign, or do >>>>> you suspect there is a bug in ojAlgo? >>>>> >>>>> I need better info regarding what you do, and what the problem is! >>>>> >>>>> /Anders >>>>> >>>>> On 15 jan 2009, at 06.14, Ruan Weichao wrote: >>>>> >>>>>> >>>>>> Thank you for your response. >>>>>> >>>>>> Here's my model's detail: >>>>>> >>>>>> [AE]={1.0, 1.0, 1.0, 1.0, 1.0, 1.0, >>>> 1.0} >>>>>> >>>>>> >>>>>> [be]={1.0} >>>>>> >>>>>> >>>>>> [Q]={3.048907897157133E-4, 1.6671472561019247E-4, >>>>>> 4.4500080981934345E-4, -5.389129745055723E-4, >>>>>> -2.6090705011393183E-4, -1.2633284900760366E-4, >>>>>> -6.485428846447651E-7}, >>>>>> {1.6671472561019247E-4, 2.341985572849691E-4, >>>>>> 2.9113916450678265E-4, -4.5760873539850514E-4, >>>>>> 1.3078636134987255E-5, -2.354289901013046E-5, >>>> -7.578030042426654E-7}, >>>>>> {4.4500080981934345E-4, 2.9113916450678265E-4, >>>> 7.46023915996829E-4, >>>>>> -0.0010247176498305568, -2.6745504327902895E-4, >>>>>> -1.6563544154823496E-4, -8.293698990696063E-7}, >>>>>> {-5.389129745055723E-4, -4.5760873539850514E-4, >>>>>> -0.0010247176498305568, 0.001754169535149865, >>>>>> 2.0293065310212377E-4, 2.1401092557826588E-4, >>>> 1.0252846778608953E-7}, >>>>>> {-2.6090705011393183E-4, 1.3078636134987255E-5, >>>>>> -2.6745504327902895E-4, 2.0293065310212377E-4, >>>>>> 4.632320892679136E-4, 1.7969731066037214E-4, >>>> 2.4953495129362833E-8}, >>>>>> {-1.2633284900760366E-4, -2.354289901013046E-5, >>>>>> -1.6563544154823496E-4, 2.1401092557826588E-4, >>>>>> 1.7969731066037214E-4, 8..346410612364995E-5, >>>> -7.02099350897589E-8}, >>>>>> {-6.485428846447651E-7, -7.578030042426654E-7, >>>>>> -8.293698990696063E-7, 1.0252846778608953E-7, >>>>>> 2.4953495129362833E-8, -7.02099350897589E-8, >>>> 8.367244992498656E-9}} >>>>>> >>>>>> [c]={{0.010638291263564232}, >>>>>> {0.013500370827906071}, >>>>>> {0.011390037735101773}, >>>>>> {0.010385042339767682}, >>>>>> {3.812208389845893E-4}, >>>>>> {0.002315505853720011}, >>>>>> {0.0}} >>>>>> >>>>>> >>>>>> [AI]={{1.0, 0.0, 0.0, 0.0, 0.0, >>>> 0.0, 0.0}, >>>>>> {0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0}, >>>>>> {0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0}, >>>>>> {0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0}, >>>>>> {0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0}, >>>>>> {0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0}, >>>>>> {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0}, >>>>>> {-1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, >>>>>> {0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0}, >>>>>> {0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0}, >>>>>> {0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0}, >>>>>> {0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0}, >>>>>> {0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0}, >>>>>> {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0}} >>>>>> >>>>>> [bi]={{1.0}, >>>>>> {1.0}, >>>>>> {1.0}, >>>>>> {1.0}, >>>>>> {1.0}, >>>>>> {1.0}, >>>>>> {1.0}, >>>>>> {0.0}, >>>>>> {0.0}, >>>>>> {0.0}, >>>>>> {0.0}, >>>>>> {0.0}, >>>>>> {0.0}, >>>>>> {0.0}} >>>>>> >>>>>> And here's the result: >>>>>> >>>>>> -0.25 >>>>>> -0.25 >>>>>> -0.25 >>>>>> -0.25 >>>>>> 0.75 >>>>>> 0.75 >>>>>> 0.75 >>>>>> >>>>>> And i found that if i change the nagetive ExceptedReturn to >>>>>> positive, the result will be fine. >>>>>> >>>>>> >>>>>> On Wed, 14 Jan 2009 09:27:53 +0100, Anders Peterson wrote >>>>>>> How small are the negative values? >>>>>>> >>>>>>> Give me a unit test (something that I can easily integrate >>>> with the >>>>>>> existing junit tests) that shows what you do, and where/how you >>>>>>> think it goes wrong. >>>>>>> >>>>>>> /Anders >>>>>>> >>>>>>> On 14 jan 2009, at 03.58, Ruan Weichao wrote: >>>>>>> >>>>>>>> >>>>>>>> Hi, >>>>>>>> >>>>>>>> I use the Markowitz model to calculate the optimize some >>>> assets' >>>>>>>> weights, >>>>>>>> >>>>>>>> and set all the assets' lowerlimit with Zero and set all the >>>>>>>> upperlimits with >>>>>>>> >>>>>>>> One, but it turns out with some negative value which are >>>> little >>>>>>>> than Zero, it >>>>>>>> >>>>>>>> seems that the lowerlimit does not work. >>>>>>>> >>>>>>>> So I want to ask what should I do it to confirm the >>>> lowerlimit? >>>>>>>> >>>>>>>> -- >>>>>>>> Best regards >>>>>>>> >>>>>>>> weichao >>>>>>>> >>>>>>>> >>>>>> >>>> ------------------------------------------------------------------- >>>> --- >>>>>>>> -------- >>>>>>>> This SF.net email is sponsored by: >>>>>>>> SourcForge Community >>>>>>>> SourceForge wants to tell your story. >>>>>>>> http://p.sf.net/sfu/sf-spreadtheword >>>>>>>> _______________________________________________ >>>>>>>> ojAlgo-user mailing list >>>>>>>> ojA...@li... >>>>>>>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user >>>>>>>> >>>>>>>> >>>>>>> >>>>>>> >>>>>> >>>> ------------------------------------------------------------------- >>>> --- >>>>>> ------ >>>>>> -- >>>>>>> This SF.net email is sponsored by: >>>>>>> SourcForge Community >>>>>>> SourceForge wants to tell your story. >>>>>>> http://p.sf.net/sfu/sf-spreadtheword >>>>>>> _______________________________________________ >>>>>>> ojAlgo-user mailing list >>>>>>> ojA...@li... >>>>>>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user >>>>>> >>>>>> >>>>>> -- >>>>>> Best regards >>>>>> >>>>>> >>>> ------------------------------------------------------------------- >>>> --- >>>>>> -------- >>>>>> This SF.net email is sponsored by: >>>>>> SourcForge Community >>>>>> SourceForge wants to tell your story. >>>>>> http://p.sf.net/sfu/sf- >>>>>> spreadtheword_______________________________________________ >>>>>> ojAlgo-user mailing list >>>>>> ojA...@li... >>>>>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user >>>>> >>>>> >>>> ------------------------------------------------------------------- >>>> --- >>>> ------ >>>> -- >>>>> This SF.net email is sponsored by: >>>>> SourcForge Community >>>>> SourceForge wants to tell your story. >>>>> http://p.sf.net/sfu/sf-spreadtheword >>>>> _______________________________________________ >>>>> ojAlgo-user mailing list >>>>> ojA...@li... >>>>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user >>>> >>>> >>>> -- >>>> Best regards >>>> >>>> ------------------------------------------------------------------- >>>> --- >>>> -------- >>>> This SF.net email is sponsored by: >>>> SourcForge Community >>>> SourceForge wants to tell your story. >>>> http://p.sf.net/sfu/sf- >>>> spreadtheword_______________________________________________ >>>> ojAlgo-user mailing list >>>> ojA...@li... >>>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user >>> >>> -------------------------------------------------------------------- >>> -------- >> -- >>> This SF.net email is sponsored by: >>> SourcForge Community >>> SourceForge wants to tell your story. >>> http://p.sf.net/sfu/sf-spreadtheword >>> _______________________________________________ >>> ojAlgo-user mailing list >>> ojA...@li... >>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user >> >> >> -- >> Best regards >> >> >> --------------------------------------------------------------------- >> --------- >> This SF.net email is sponsored by: >> SourcForge Community >> SourceForge wants to tell your story. >> http://p.sf.net/sfu/sf-spreadtheword >> _______________________________________________ >> ojAlgo-user mailing list >> ojA...@li... >> https://lists.sourceforge.net/lists/listinfo/ojalgo-user > |
From: Ruan W. <is0...@ma...> - 2009-01-16 07:53:10
|
I think i get your point. So I should not use negative excess returns in my model. Thank you very much! On Fri, 16 Jan 2009 07:25:41 +0100, Anders Peterson wrote > On 16 jan 2009, at 02.28, Ruan Weichao wrote: > > > Hi, > > > > Yes, that's the expected excess returns of my program. > > > > Is it right? > > > > Can the "expected excess returns" be negative? > > I have no way of knowing what model/problem you want to solve... > > In a general case excess returns (what you get for taking a risk) > should not be negative. If they are, you do not need to optimise > anything. Just invest everything in the risk free asset. > > I'm not sure exactly why you get those negative (constraint breaking) > portfolio weights. I'm going to look into this, but later. Don't > hold your breath. For you, I think the solution is to work on your model. > > /Anders > > > On Thu, 15 Jan 2009 14:09:43 +0100, Anders Peterson wrote > >> Your expected excess returns matrix looks like this: > >> > >> class org.ojalgo.matrix.BigMatrix > >> {{-0.010638291263564232}, > >> {-0.013500370827906071}, > >> {-0.011390037735101773}, > >> {-0.010385042339767682}, > >> {-0.0003812208389845893}, > >> {-0.002315505853720011}, > >> {0}} > >> > >> Is that correct? > >> > >> Earlier you wrote "And i found that if i change the nagetive > >> ExceptedReturn to positive, the result will be fine." > >> > >> /Anders > >> > >> On 15 jan 2009, at 11.10, Ruan Weichao wrote: > >> > >>> Hi,i am using v25 and here's my code: > >>> > >>> / > >>> ******************************************************************** > >>> ** > >>> **********/ > >>> > >>> import java.math.BigDecimal; > >>> import java.util.List; > >>> > >>> import org.ojalgo.finance.portfolio.MarketEquilibrium; > >>> import org.ojalgo.finance.portfolio.MarkowitzModel; > >>> import org.ojalgo.matrix.*; > >>> import org.ojalgo.matrix.store.BigDenseStore; > >>> import org.ojalgo.matrix.store.MatrixStore; > >>> > >>> > >>> public class TestMarkowitz { > >>> > >>> public double getCovarance(double[] value1, double[] value2){ > >>> > >>> int n = value1.length; > >>> double averOne = 0; > >>> double averTwo = 0; > >>> for(int i=0;i<n;i++) > >>> { > >>> averOne+=value1[i]; > >>> averTwo+=value2[i]; > >>> } > >>> averOne /= n; > >>> averTwo /= n; > >>> > >>> double sum = 0; > >>> for(int i=0;i<n;i++) > >>> sum+=(value1[i]-averOne)*(value2[i]-averTwo); > >>> > >>> return sum / (n-1); > >>> } > >>> > >>> public BasicMatrix getACovariances(double[][] returns){ > >>> > >>> int row = returns.length; > >>> int col = returns[0].length; > >>> MatrixStore<BigDecimal> a = BigDenseStore.FACTORY..makeZero(row, > >>> col); > >>> BasicMatrix covariances = new BigMatrix(a); > >>> > >>> for(int i=1;i<=row;i++){ > >>> for(int j=i;j<=col;j++){ > >>> double tmp = this.getCovarance(returns[i-1], returns[j-1]); > >>> covariances = covariances.set(i-1, j-1,tmp); > >>> covariances = covariances.set(j-1, i-1,tmp); > >>> } > >>> } > >>> return covariances; > >>> } > >>> > >>> public BasicMatrix getAnExpectedExcessReturns(double[][] returns){ > >>> > >>> int row = returns.length; > >>> int col = returns[0].length; > >>> > >>> MatrixStore<BigDecimal> a = BigDenseStore.FACTORY..makeZero > >>> (row, 1); > >>> BasicMatrix expectedExcessReturns = new BigMatrix(a); > >>> > >>> double riskFreeReturn = 0; > >>> for(int i=1;i<=col;i++) > >>> riskFreeReturn+=returns[row-1][i-1]; > >>> riskFreeReturn/=row; > >>> > >>> for(int i=1;i<=row;i++){ > >>> > >>> double tmp = 0; > >>> for(int j=1;j<=col;j++) > >>> tmp+=returns[i-1][j-1]; > >>> tmp/=col; > >>> > >>> expectedExcessReturns = expectedExcessReturns.set(i-1, 0, tmp- > >>> riskFreeReturn); > >>> } > >>> > >>> return expectedExcessReturns; > >>> } > >>> > >>> public static void main(String[] args) > >>> { > >>> int assetNum=7; > >>> double[][] assets_return={ > >>> {-1.5905837442343828E-4, -0.03062360801781757, > >>> -0.029857534032853142, -0.011811692726036832, > >>> -0.017972310602803136, 0.017338003502626997, 0.0}, > >>> {-0.02757158006362653, -0.02562704471101405, > >>> -0.011751538891997735, -0.024915062287655786, -0.01684088269454123, > >>> 0.013585351447135364, 0.0}, > >>> {-0.00699300699300693, -0.033802816901408676, > >>> -0.04675196850393671, -0.021166752710376546, -0.007911392405063583, > >>> 0.03827751196172254, 0.0}, > >>> {-0.007626310772164015, 0.0038424591738713027, > >>> 0.02488038277511978, 0.025210084033613675, -0.02003642987249557, > >>> -0.09758364312267642, 0.0}, > >>> {-0.03965053763440893, 0.021693491952414375, > >>> 0.01643835616438392, -0.007412398921833087, 0.01765105227427014, > >>> -0.010006671114076025, 0.0}, > >>> {-0.017821782178217872, 0.005040322580645311, > >>> 0.006018054162487363, 9.008107296569024E-4, 0.002999999999999824, > >>> -0.01196410767696908, 0.0}, > >>> {2.630552127527583E-4, 2.5867028174649627E-4, > >>> 2.3866431891514327E-4, 1.9564035993080523E-4, 2.351016690966669E-4, > >>> 1.9070675120065465E-4, 0.0} > >>> }; > >>> > >>> TestMarkowitz tm = new TestMarkowitz(); > >>> BasicMatrix covariances = tm.getACovariances(assets_return); > >>> BasicMatrix expectedExcessReturns = tm.getAnExpectedExcessReturns > >>> (assets_return); > >>> BigDecimal riskAversion = new BigDecimal(1.0); > >>> > >>> MarketEquilibrium marketEquilibrium = new MarketEquilibrium > >>> (covariances,riskAversion); > >>> MarkowitzModel markowitzModel = new MarkowitzModel > >>> (marketEquilibrium,expectedExcessReturns); > >>> > >>> for(int i=0;i<assetNum;i++){ > >>> markowitzModel.setLowerLimit(i, new BigDecimal(0.0)); > >>> markowitzModel.setUpperLimit(i, new BigDecimal(1.0)); > >>> } > >>> List<BigDecimal> re = markowitzModel.getWeights(); > >>> > >>> System.out.println("=======result===================="); > >>> for(int i=0;i<re.size();i++) > >>> System.out.println(re.get(i)); > >>> > >>> return; > >>> } > >>> > >>> } > >>> > >>> / > >>> ******************************************************************** > >>> ** > >>> **********/ > >>> > >>> and the result turn out as: > >>> > >>> -0.25 > >>> -0.25 > >>> -0.25 > >>> -0.25 > >>> 0.75 > >>> 0.75 > >>> 0.75 > >>> > >>> / > >>> ******************************************************************** > >>> ** > >>> ******/ > >>> > >>> If you find out any problem, just let me know , thanks a lot! > >>> > >>> On Thu, 15 Jan 2009 09:20:52 +0100, Anders Peterson wrote > >>>> You have to send code (snippets) that I can execute. > >>>> > >>>> Are you using v25 or the latest from cvs? > >>>> > >>>> How do you instantiate the ActiveSetSolver? > >>>> > >>>> What's the correct solution? > >>>> > >>>> You say that if you change the sign of "C" you get an ok result. > >>>> What does this mean? Did you make a mistake with the sign, or do > >>>> you suspect there is a bug in ojAlgo? > >>>> > >>>> I need better info regarding what you do, and what the problem is! > >>>> > >>>> /Anders > >>>> > >>>> On 15 jan 2009, at 06.14, Ruan Weichao wrote: > >>>> > >>>>> > >>>>> Thank you for your response. > >>>>> > >>>>> Here's my model's detail: > >>>>> > >>>>> [AE]={1.0, 1.0, 1.0, 1.0, 1.0, 1.0, > >>> 1.0} > >>>>> > >>>>> > >>>>> [be]={1.0} > >>>>> > >>>>> > >>>>> [Q]={3.048907897157133E-4, 1.6671472561019247E-4, > >>>>> 4.4500080981934345E-4, -5.389129745055723E-4, > >>>>> -2.6090705011393183E-4, -1.2633284900760366E-4, > >>>>> -6.485428846447651E-7}, > >>>>> {1.6671472561019247E-4, 2.341985572849691E-4, > >>>>> 2.9113916450678265E-4, -4.5760873539850514E-4, > >>>>> 1.3078636134987255E-5, -2.354289901013046E-5, > >>> -7.578030042426654E-7}, > >>>>> {4.4500080981934345E-4, 2.9113916450678265E-4, > >>> 7.46023915996829E-4, > >>>>> -0.0010247176498305568, -2.6745504327902895E-4, > >>>>> -1.6563544154823496E-4, -8.293698990696063E-7}, > >>>>> {-5.389129745055723E-4, -4.5760873539850514E-4, > >>>>> -0.0010247176498305568, 0.001754169535149865, > >>>>> 2.0293065310212377E-4, 2.1401092557826588E-4, > >>> 1.0252846778608953E-7}, > >>>>> {-2.6090705011393183E-4, 1.3078636134987255E-5, > >>>>> -2.6745504327902895E-4, 2.0293065310212377E-4, > >>>>> 4.632320892679136E-4, 1.7969731066037214E-4, > >>> 2.4953495129362833E-8}, > >>>>> {-1.2633284900760366E-4, -2.354289901013046E-5, > >>>>> -1.6563544154823496E-4, 2.1401092557826588E-4, > >>>>> 1.7969731066037214E-4, 8..346410612364995E-5, > >>> -7.02099350897589E-8}, > >>>>> {-6.485428846447651E-7, -7.578030042426654E-7, > >>>>> -8.293698990696063E-7, 1.0252846778608953E-7, > >>>>> 2.4953495129362833E-8, -7.02099350897589E-8, > >>> 8.367244992498656E-9}} > >>>>> > >>>>> [c]={{0.010638291263564232}, > >>>>> {0.013500370827906071}, > >>>>> {0.011390037735101773}, > >>>>> {0.010385042339767682}, > >>>>> {3.812208389845893E-4}, > >>>>> {0.002315505853720011}, > >>>>> {0.0}} > >>>>> > >>>>> > >>>>> [AI]={{1.0, 0.0, 0.0, 0.0, 0.0, > >>> 0.0, 0.0}, > >>>>> {0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0}, > >>>>> {0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0}, > >>>>> {0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0}, > >>>>> {0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0}, > >>>>> {0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0}, > >>>>> {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0}, > >>>>> {-1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, > >>>>> {0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0}, > >>>>> {0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0}, > >>>>> {0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0}, > >>>>> {0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0}, > >>>>> {0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0}, > >>>>> {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0}} > >>>>> > >>>>> [bi]={{1.0}, > >>>>> {1.0}, > >>>>> {1.0}, > >>>>> {1.0}, > >>>>> {1.0}, > >>>>> {1.0}, > >>>>> {1.0}, > >>>>> {0.0}, > >>>>> {0.0}, > >>>>> {0.0}, > >>>>> {0.0}, > >>>>> {0.0}, > >>>>> {0.0}, > >>>>> {0.0}} > >>>>> > >>>>> And here's the result: > >>>>> > >>>>> -0.25 > >>>>> -0.25 > >>>>> -0.25 > >>>>> -0.25 > >>>>> 0.75 > >>>>> 0.75 > >>>>> 0.75 > >>>>> > >>>>> And i found that if i change the nagetive ExceptedReturn to > >>>>> positive, the result will be fine. > >>>>> > >>>>> > >>>>> On Wed, 14 Jan 2009 09:27:53 +0100, Anders Peterson wrote > >>>>>> How small are the negative values? > >>>>>> > >>>>>> Give me a unit test (something that I can easily integrate > >>> with the > >>>>>> existing junit tests) that shows what you do, and where/how you > >>>>>> think it goes wrong. > >>>>>> > >>>>>> /Anders > >>>>>> > >>>>>> On 14 jan 2009, at 03.58, Ruan Weichao wrote: > >>>>>> > >>>>>>> > >>>>>>> Hi, > >>>>>>> > >>>>>>> I use the Markowitz model to calculate the optimize some > >>> assets' > >>>>>>> weights, > >>>>>>> > >>>>>>> and set all the assets' lowerlimit with Zero and set all the > >>>>>>> upperlimits with > >>>>>>> > >>>>>>> One, but it turns out with some negative value which are > >>> little > >>>>>>> than Zero, it > >>>>>>> > >>>>>>> seems that the lowerlimit does not work. > >>>>>>> > >>>>>>> So I want to ask what should I do it to confirm the > >>> lowerlimit? > >>>>>>> > >>>>>>> -- > >>>>>>> Best regards > >>>>>>> > >>>>>>> weichao > >>>>>>> > >>>>>>> > >>>>> > >>> -------------------------------------------------------------------- > >>> -- > >>>>>>> -------- > >>>>>>> This SF.net email is sponsored by: > >>>>>>> SourcForge Community > >>>>>>> SourceForge wants to tell your story. > >>>>>>> http://p.sf.net/sfu/sf-spreadtheword > >>>>>>> _______________________________________________ > >>>>>>> ojAlgo-user mailing list > >>>>>>> ojA...@li... > >>>>>>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user > >>>>>>> > >>>>>>> > >>>>>> > >>>>>> > >>>>> > >>> -------------------------------------------------------------------- > >>> -- > >>>>> ------ > >>>>> -- > >>>>>> This SF.net email is sponsored by: > >>>>>> SourcForge Community > >>>>>> SourceForge wants to tell your story. > >>>>>> http://p.sf.net/sfu/sf-spreadtheword > >>>>>> _______________________________________________ > >>>>>> ojAlgo-user mailing list > >>>>>> ojA...@li... > >>>>>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user > >>>>> > >>>>> > >>>>> -- > >>>>> Best regards > >>>>> > >>>>> > >>> -------------------------------------------------------------------- > >>> -- > >>>>> -------- > >>>>> This SF.net email is sponsored by: > >>>>> SourcForge Community > >>>>> SourceForge wants to tell your story. > >>>>> http://p.sf.net/sfu/sf- > >>>>> spreadtheword_______________________________________________ > >>>>> ojAlgo-user mailing list > >>>>> ojA...@li... > >>>>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user > >>>> > >>>> > >>> -------------------------------------------------------------------- > >>> -- > >>> ------ > >>> -- > >>>> This SF.net email is sponsored by: > >>>> SourcForge Community > >>>> SourceForge wants to tell your story. > >>>> http://p.sf.net/sfu/sf-spreadtheword > >>>> _______________________________________________ > >>>> ojAlgo-user mailing list > >>>> ojA...@li... > >>>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user > >>> > >>> > >>> -- > >>> Best regards > >>> > >>> -------------------------------------------------------------------- > >>> -- > >>> -------- > >>> This SF.net email is sponsored by: > >>> SourcForge Community > >>> SourceForge wants to tell your story. > >>> http://p.sf.net/sfu/sf- > >>> spreadtheword_______________________________________________ > >>> ojAlgo-user mailing list > >>> ojA...@li... > >>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user > >> > >> --------------------------------------------------------------------- > >> ------- > > -- > >> This SF.net email is sponsored by: > >> SourcForge Community > >> SourceForge wants to tell your story. > >> http://p.sf.net/sfu/sf-spreadtheword > >> _______________________________________________ > >> ojAlgo-user mailing list > >> ojA...@li... > >> https://lists.sourceforge.net/lists/listinfo/ojalgo-user > > > > > > -- > > Best regards > > > > > > ---------------------------------------------------------------------- > > -------- > > This SF.net email is sponsored by: > > SourcForge Community > > SourceForge wants to tell your story. > > http://p.sf.net/sfu/sf-spreadtheword > > _______________________________________________ > > ojAlgo-user mailing list > > ojA...@li... > > https://lists.sourceforge.net/lists/listinfo/ojalgo-user > > ---------------------------------------------------------------------------- -- > This SF.net email is sponsored by: > SourcForge Community > SourceForge wants to tell your story. > http://p.sf.net/sfu/sf-spreadtheword > _______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user -- Best regards |
From: Anders P. <an...@op...> - 2009-01-16 06:25:55
|
On 16 jan 2009, at 02.28, Ruan Weichao wrote: > Hi, > > Yes, that's the expected excess returns of my program. > > Is it right? > > Can the "expected excess returns" be negative? I have no way of knowing what model/problem you want to solve... In a general case excess returns (what you get for taking a risk) should not be negative. If they are, you do not need to optimise anything. Just invest everything in the risk free asset. I'm not sure exactly why you get those negative (constraint breaking) portfolio weights. I'm going to look into this, but later. Don't hold your breath. For you, I think the solution is to work on your model. /Anders > On Thu, 15 Jan 2009 14:09:43 +0100, Anders Peterson wrote >> Your expected excess returns matrix looks like this: >> >> class org.ojalgo.matrix.BigMatrix >> {{-0.010638291263564232}, >> {-0.013500370827906071}, >> {-0.011390037735101773}, >> {-0.010385042339767682}, >> {-0.0003812208389845893}, >> {-0.002315505853720011}, >> {0}} >> >> Is that correct? >> >> Earlier you wrote "And i found that if i change the nagetive >> ExceptedReturn to positive, the result will be fine." >> >> /Anders >> >> On 15 jan 2009, at 11.10, Ruan Weichao wrote: >> >>> Hi,i am using v25 and here's my code: >>> >>> / >>> ******************************************************************** >>> ** >>> **********/ >>> >>> import java.math.BigDecimal; >>> import java.util.List; >>> >>> import org.ojalgo.finance.portfolio.MarketEquilibrium; >>> import org.ojalgo.finance.portfolio.MarkowitzModel; >>> import org.ojalgo.matrix.*; >>> import org.ojalgo.matrix.store.BigDenseStore; >>> import org.ojalgo.matrix.store.MatrixStore; >>> >>> >>> public class TestMarkowitz { >>> >>> public double getCovarance(double[] value1, double[] value2){ >>> >>> int n = value1.length; >>> double averOne = 0; >>> double averTwo = 0; >>> for(int i=0;i<n;i++) >>> { >>> averOne+=value1[i]; >>> averTwo+=value2[i]; >>> } >>> averOne /= n; >>> averTwo /= n; >>> >>> double sum = 0; >>> for(int i=0;i<n;i++) >>> sum+=(value1[i]-averOne)*(value2[i]-averTwo); >>> >>> return sum / (n-1); >>> } >>> >>> public BasicMatrix getACovariances(double[][] returns){ >>> >>> int row = returns.length; >>> int col = returns[0].length; >>> MatrixStore<BigDecimal> a = BigDenseStore.FACTORY..makeZero(row, >>> col); >>> BasicMatrix covariances = new BigMatrix(a); >>> >>> for(int i=1;i<=row;i++){ >>> for(int j=i;j<=col;j++){ >>> double tmp = this.getCovarance(returns[i-1], returns[j-1]); >>> covariances = covariances.set(i-1, j-1,tmp); >>> covariances = covariances.set(j-1, i-1,tmp); >>> } >>> } >>> return covariances; >>> } >>> >>> public BasicMatrix getAnExpectedExcessReturns(double[][] returns){ >>> >>> int row = returns.length; >>> int col = returns[0].length; >>> >>> MatrixStore<BigDecimal> a = BigDenseStore.FACTORY..makeZero >>> (row, 1); >>> BasicMatrix expectedExcessReturns = new BigMatrix(a); >>> >>> double riskFreeReturn = 0; >>> for(int i=1;i<=col;i++) >>> riskFreeReturn+=returns[row-1][i-1]; >>> riskFreeReturn/=row; >>> >>> for(int i=1;i<=row;i++){ >>> >>> double tmp = 0; >>> for(int j=1;j<=col;j++) >>> tmp+=returns[i-1][j-1]; >>> tmp/=col; >>> >>> expectedExcessReturns = expectedExcessReturns.set(i-1, 0, tmp- >>> riskFreeReturn); >>> } >>> >>> return expectedExcessReturns; >>> } >>> >>> public static void main(String[] args) >>> { >>> int assetNum=7; >>> double[][] assets_return={ >>> {-1.5905837442343828E-4, -0.03062360801781757, >>> -0.029857534032853142, -0.011811692726036832, >>> -0.017972310602803136, 0.017338003502626997, 0.0}, >>> {-0.02757158006362653, -0.02562704471101405, >>> -0.011751538891997735, -0.024915062287655786, -0.01684088269454123, >>> 0.013585351447135364, 0.0}, >>> {-0.00699300699300693, -0.033802816901408676, >>> -0.04675196850393671, -0.021166752710376546, -0.007911392405063583, >>> 0.03827751196172254, 0.0}, >>> {-0.007626310772164015, 0.0038424591738713027, >>> 0.02488038277511978, 0.025210084033613675, -0.02003642987249557, >>> -0.09758364312267642, 0.0}, >>> {-0.03965053763440893, 0.021693491952414375, >>> 0.01643835616438392, -0.007412398921833087, 0.01765105227427014, >>> -0.010006671114076025, 0.0}, >>> {-0.017821782178217872, 0.005040322580645311, >>> 0.006018054162487363, 9.008107296569024E-4, 0.002999999999999824, >>> -0.01196410767696908, 0.0}, >>> {2.630552127527583E-4, 2.5867028174649627E-4, >>> 2.3866431891514327E-4, 1.9564035993080523E-4, 2.351016690966669E-4, >>> 1.9070675120065465E-4, 0.0} >>> }; >>> >>> TestMarkowitz tm = new TestMarkowitz(); >>> BasicMatrix covariances = tm.getACovariances(assets_return); >>> BasicMatrix expectedExcessReturns = tm.getAnExpectedExcessReturns >>> (assets_return); >>> BigDecimal riskAversion = new BigDecimal(1.0); >>> >>> MarketEquilibrium marketEquilibrium = new MarketEquilibrium >>> (covariances,riskAversion); >>> MarkowitzModel markowitzModel = new MarkowitzModel >>> (marketEquilibrium,expectedExcessReturns); >>> >>> for(int i=0;i<assetNum;i++){ >>> markowitzModel.setLowerLimit(i, new BigDecimal(0.0)); >>> markowitzModel.setUpperLimit(i, new BigDecimal(1.0)); >>> } >>> List<BigDecimal> re = markowitzModel.getWeights(); >>> >>> System.out.println("=======result===================="); >>> for(int i=0;i<re.size();i++) >>> System.out.println(re.get(i)); >>> >>> return; >>> } >>> >>> } >>> >>> / >>> ******************************************************************** >>> ** >>> **********/ >>> >>> and the result turn out as: >>> >>> -0.25 >>> -0.25 >>> -0.25 >>> -0.25 >>> 0.75 >>> 0.75 >>> 0.75 >>> >>> / >>> ******************************************************************** >>> ** >>> ******/ >>> >>> If you find out any problem, just let me know , thanks a lot! >>> >>> On Thu, 15 Jan 2009 09:20:52 +0100, Anders Peterson wrote >>>> You have to send code (snippets) that I can execute. >>>> >>>> Are you using v25 or the latest from cvs? >>>> >>>> How do you instantiate the ActiveSetSolver? >>>> >>>> What's the correct solution? >>>> >>>> You say that if you change the sign of "C" you get an ok result. >>>> What does this mean? Did you make a mistake with the sign, or do >>>> you suspect there is a bug in ojAlgo? >>>> >>>> I need better info regarding what you do, and what the problem is! >>>> >>>> /Anders >>>> >>>> On 15 jan 2009, at 06.14, Ruan Weichao wrote: >>>> >>>>> >>>>> Thank you for your response. >>>>> >>>>> Here's my model's detail: >>>>> >>>>> [AE]={1.0, 1.0, 1.0, 1.0, 1.0, 1.0, >>> 1.0} >>>>> >>>>> >>>>> [be]={1.0} >>>>> >>>>> >>>>> [Q]={3.048907897157133E-4, 1.6671472561019247E-4, >>>>> 4.4500080981934345E-4, -5.389129745055723E-4, >>>>> -2.6090705011393183E-4, -1.2633284900760366E-4, >>>>> -6.485428846447651E-7}, >>>>> {1.6671472561019247E-4, 2.341985572849691E-4, >>>>> 2.9113916450678265E-4, -4.5760873539850514E-4, >>>>> 1.3078636134987255E-5, -2.354289901013046E-5, >>> -7.578030042426654E-7}, >>>>> {4.4500080981934345E-4, 2.9113916450678265E-4, >>> 7.46023915996829E-4, >>>>> -0.0010247176498305568, -2.6745504327902895E-4, >>>>> -1.6563544154823496E-4, -8.293698990696063E-7}, >>>>> {-5.389129745055723E-4, -4.5760873539850514E-4, >>>>> -0.0010247176498305568, 0.001754169535149865, >>>>> 2.0293065310212377E-4, 2.1401092557826588E-4, >>> 1.0252846778608953E-7}, >>>>> {-2.6090705011393183E-4, 1.3078636134987255E-5, >>>>> -2.6745504327902895E-4, 2.0293065310212377E-4, >>>>> 4.632320892679136E-4, 1.7969731066037214E-4, >>> 2.4953495129362833E-8}, >>>>> {-1.2633284900760366E-4, -2.354289901013046E-5, >>>>> -1.6563544154823496E-4, 2.1401092557826588E-4, >>>>> 1.7969731066037214E-4, 8..346410612364995E-5, >>> -7.02099350897589E-8}, >>>>> {-6.485428846447651E-7, -7.578030042426654E-7, >>>>> -8.293698990696063E-7, 1.0252846778608953E-7, >>>>> 2.4953495129362833E-8, -7.02099350897589E-8, >>> 8.367244992498656E-9}} >>>>> >>>>> [c]={{0.010638291263564232}, >>>>> {0.013500370827906071}, >>>>> {0.011390037735101773}, >>>>> {0.010385042339767682}, >>>>> {3.812208389845893E-4}, >>>>> {0.002315505853720011}, >>>>> {0.0}} >>>>> >>>>> >>>>> [AI]={{1.0, 0.0, 0.0, 0.0, 0.0, >>> 0.0, 0.0}, >>>>> {0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0}, >>>>> {0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0}, >>>>> {0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0}, >>>>> {0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0}, >>>>> {0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0}, >>>>> {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0}, >>>>> {-1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, >>>>> {0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0}, >>>>> {0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0}, >>>>> {0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0}, >>>>> {0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0}, >>>>> {0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0}, >>>>> {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0}} >>>>> >>>>> [bi]={{1.0}, >>>>> {1.0}, >>>>> {1.0}, >>>>> {1.0}, >>>>> {1.0}, >>>>> {1.0}, >>>>> {1.0}, >>>>> {0.0}, >>>>> {0.0}, >>>>> {0.0}, >>>>> {0.0}, >>>>> {0.0}, >>>>> {0.0}, >>>>> {0.0}} >>>>> >>>>> And here's the result: >>>>> >>>>> -0.25 >>>>> -0.25 >>>>> -0.25 >>>>> -0.25 >>>>> 0.75 >>>>> 0.75 >>>>> 0.75 >>>>> >>>>> And i found that if i change the nagetive ExceptedReturn to >>>>> positive, the result will be fine. >>>>> >>>>> >>>>> On Wed, 14 Jan 2009 09:27:53 +0100, Anders Peterson wrote >>>>>> How small are the negative values? >>>>>> >>>>>> Give me a unit test (something that I can easily integrate >>> with the >>>>>> existing junit tests) that shows what you do, and where/how you >>>>>> think it goes wrong. >>>>>> >>>>>> /Anders >>>>>> >>>>>> On 14 jan 2009, at 03.58, Ruan Weichao wrote: >>>>>> >>>>>>> >>>>>>> Hi, >>>>>>> >>>>>>> I use the Markowitz model to calculate the optimize some >>> assets' >>>>>>> weights, >>>>>>> >>>>>>> and set all the assets' lowerlimit with Zero and set all the >>>>>>> upperlimits with >>>>>>> >>>>>>> One, but it turns out with some negative value which are >>> little >>>>>>> than Zero, it >>>>>>> >>>>>>> seems that the lowerlimit does not work. >>>>>>> >>>>>>> So I want to ask what should I do it to confirm the >>> lowerlimit? >>>>>>> >>>>>>> -- >>>>>>> Best regards >>>>>>> >>>>>>> weichao >>>>>>> >>>>>>> >>>>> >>> -------------------------------------------------------------------- >>> -- >>>>>>> -------- >>>>>>> This SF.net email is sponsored by: >>>>>>> SourcForge Community >>>>>>> SourceForge wants to tell your story. >>>>>>> http://p.sf.net/sfu/sf-spreadtheword >>>>>>> _______________________________________________ >>>>>>> ojAlgo-user mailing list >>>>>>> ojA...@li... >>>>>>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user >>>>>>> >>>>>>> >>>>>> >>>>>> >>>>> >>> -------------------------------------------------------------------- >>> -- >>>>> ------ >>>>> -- >>>>>> This SF.net email is sponsored by: >>>>>> SourcForge Community >>>>>> SourceForge wants to tell your story. >>>>>> http://p.sf.net/sfu/sf-spreadtheword >>>>>> _______________________________________________ >>>>>> ojAlgo-user mailing list >>>>>> ojA...@li... >>>>>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user >>>>> >>>>> >>>>> -- >>>>> Best regards >>>>> >>>>> >>> -------------------------------------------------------------------- >>> -- >>>>> -------- >>>>> This SF.net email is sponsored by: >>>>> SourcForge Community >>>>> SourceForge wants to tell your story. >>>>> http://p.sf.net/sfu/sf- >>>>> spreadtheword_______________________________________________ >>>>> ojAlgo-user mailing list >>>>> ojA...@li... >>>>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user >>>> >>>> >>> -------------------------------------------------------------------- >>> -- >>> ------ >>> -- >>>> This SF.net email is sponsored by: >>>> SourcForge Community >>>> SourceForge wants to tell your story. >>>> http://p.sf.net/sfu/sf-spreadtheword >>>> _______________________________________________ >>>> ojAlgo-user mailing list >>>> ojA...@li... >>>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user >>> >>> >>> -- >>> Best regards >>> >>> -------------------------------------------------------------------- >>> -- >>> -------- >>> This SF.net email is sponsored by: >>> SourcForge Community >>> SourceForge wants to tell your story. >>> http://p.sf.net/sfu/sf- >>> spreadtheword_______________________________________________ >>> ojAlgo-user mailing list >>> ojA...@li... >>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user >> >> --------------------------------------------------------------------- >> ------- > -- >> This SF.net email is sponsored by: >> SourcForge Community >> SourceForge wants to tell your story. >> http://p.sf.net/sfu/sf-spreadtheword >> _______________________________________________ >> ojAlgo-user mailing list >> ojA...@li... >> https://lists.sourceforge.net/lists/listinfo/ojalgo-user > > > -- > Best regards > > > ---------------------------------------------------------------------- > -------- > This SF.net email is sponsored by: > SourcForge Community > SourceForge wants to tell your story. > http://p.sf.net/sfu/sf-spreadtheword > _______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user |
From: Ruan W. <is0...@ma...> - 2009-01-16 01:28:28
|
Hi, Yes, that's the expected excess returns of my program. Is it right? Can the "expected excess returns" be negative? On Thu, 15 Jan 2009 14:09:43 +0100, Anders Peterson wrote > Your expected excess returns matrix looks like this: > > class org.ojalgo.matrix.BigMatrix > {{-0.010638291263564232}, > {-0.013500370827906071}, > {-0.011390037735101773}, > {-0.010385042339767682}, > {-0.0003812208389845893}, > {-0.002315505853720011}, > {0}} > > Is that correct? > > Earlier you wrote "And i found that if i change the nagetive > ExceptedReturn to positive, the result will be fine." > > /Anders > > On 15 jan 2009, at 11.10, Ruan Weichao wrote: > > > Hi,i am using v25 and here's my code: > > > > / > > ********************************************************************** > > **********/ > > > > import java.math.BigDecimal; > > import java.util.List; > > > > import org.ojalgo.finance.portfolio.MarketEquilibrium; > > import org.ojalgo.finance.portfolio.MarkowitzModel; > > import org.ojalgo.matrix.*; > > import org.ojalgo.matrix.store.BigDenseStore; > > import org.ojalgo.matrix.store.MatrixStore; > > > > > > public class TestMarkowitz { > > > > public double getCovarance(double[] value1, double[] value2){ > > > > int n = value1.length; > > double averOne = 0; > > double averTwo = 0; > > for(int i=0;i<n;i++) > > { > > averOne+=value1[i]; > > averTwo+=value2[i]; > > } > > averOne /= n; > > averTwo /= n; > > > > double sum = 0; > > for(int i=0;i<n;i++) > > sum+=(value1[i]-averOne)*(value2[i]-averTwo); > > > > return sum / (n-1); > > } > > > > public BasicMatrix getACovariances(double[][] returns){ > > > > int row = returns.length; > > int col = returns[0].length; > > MatrixStore<BigDecimal> a = BigDenseStore.FACTORY..makeZero(row, > > col); > > BasicMatrix covariances = new BigMatrix(a); > > > > for(int i=1;i<=row;i++){ > > for(int j=i;j<=col;j++){ > > double tmp = this.getCovarance(returns[i-1], returns[j-1]); > > covariances = covariances.set(i-1, j-1,tmp); > > covariances = covariances.set(j-1, i-1,tmp); > > } > > } > > return covariances; > > } > > > > public BasicMatrix getAnExpectedExcessReturns(double[][] returns){ > > > > int row = returns.length; > > int col = returns[0].length; > > > > MatrixStore<BigDecimal> a = BigDenseStore.FACTORY..makeZero(row, 1); > > BasicMatrix expectedExcessReturns = new BigMatrix(a); > > > > double riskFreeReturn = 0; > > for(int i=1;i<=col;i++) > > riskFreeReturn+=returns[row-1][i-1]; > > riskFreeReturn/=row; > > > > for(int i=1;i<=row;i++){ > > > > double tmp = 0; > > for(int j=1;j<=col;j++) > > tmp+=returns[i-1][j-1]; > > tmp/=col; > > > > expectedExcessReturns = expectedExcessReturns.set(i-1, 0, tmp- > > riskFreeReturn); > > } > > > > return expectedExcessReturns; > > } > > > > public static void main(String[] args) > > { > > int assetNum=7; > > double[][] assets_return={ > > {-1.5905837442343828E-4, -0.03062360801781757, > > -0.029857534032853142, -0.011811692726036832, > > -0.017972310602803136, 0.017338003502626997, 0.0}, > > {-0.02757158006362653, -0.02562704471101405, > > -0.011751538891997735, -0.024915062287655786, -0.01684088269454123, > > 0.013585351447135364, 0.0}, > > {-0.00699300699300693, -0.033802816901408676, > > -0.04675196850393671, -0.021166752710376546, -0.007911392405063583, > > 0.03827751196172254, 0.0}, > > {-0.007626310772164015, 0.0038424591738713027, > > 0.02488038277511978, 0.025210084033613675, -0.02003642987249557, > > -0.09758364312267642, 0.0}, > > {-0.03965053763440893, 0.021693491952414375, > > 0.01643835616438392, -0.007412398921833087, 0.01765105227427014, > > -0.010006671114076025, 0.0}, > > {-0.017821782178217872, 0.005040322580645311, > > 0.006018054162487363, 9.008107296569024E-4, 0.002999999999999824, > > -0.01196410767696908, 0.0}, > > {2.630552127527583E-4, 2.5867028174649627E-4, > > 2.3866431891514327E-4, 1.9564035993080523E-4, 2.351016690966669E-4, > > 1.9070675120065465E-4, 0.0} > > }; > > > > TestMarkowitz tm = new TestMarkowitz(); > > BasicMatrix covariances = tm.getACovariances(assets_return); > > BasicMatrix expectedExcessReturns = tm.getAnExpectedExcessReturns > > (assets_return); > > BigDecimal riskAversion = new BigDecimal(1.0); > > > > MarketEquilibrium marketEquilibrium = new MarketEquilibrium > > (covariances,riskAversion); > > MarkowitzModel markowitzModel = new MarkowitzModel > > (marketEquilibrium,expectedExcessReturns); > > > > for(int i=0;i<assetNum;i++){ > > markowitzModel.setLowerLimit(i, new BigDecimal(0.0)); > > markowitzModel.setUpperLimit(i, new BigDecimal(1.0)); > > } > > List<BigDecimal> re = markowitzModel.getWeights(); > > > > System.out.println("=======result===================="); > > for(int i=0;i<re.size();i++) > > System.out.println(re.get(i)); > > > > return; > > } > > > > } > > > > / > > ********************************************************************** > > **********/ > > > > and the result turn out as: > > > > -0.25 > > -0.25 > > -0.25 > > -0.25 > > 0.75 > > 0.75 > > 0.75 > > > > / > > ********************************************************************** > > ******/ > > > > If you find out any problem, just let me know , thanks a lot! > > > > On Thu, 15 Jan 2009 09:20:52 +0100, Anders Peterson wrote > > > You have to send code (snippets) that I can execute. > > > > > > Are you using v25 or the latest from cvs? > > > > > > How do you instantiate the ActiveSetSolver? > > > > > > What's the correct solution? > > > > > > You say that if you change the sign of "C" you get an ok result. > > > What does this mean? Did you make a mistake with the sign, or do > > > you suspect there is a bug in ojAlgo? > > > > > > I need better info regarding what you do, and what the problem is! > > > > > > /Anders > > > > > > On 15 jan 2009, at 06.14, Ruan Weichao wrote: > > > > > > > > > > > Thank you for your response. > > > > > > > > Here's my model's detail: > > > > > > > > [AE]={1.0, 1.0, 1.0, 1.0, 1.0, 1.0, > > 1.0} > > > > > > > > > > > > [be]={1.0} > > > > > > > > > > > > [Q]={3.048907897157133E-4, 1.6671472561019247E-4, > > > > 4.4500080981934345E-4, -5.389129745055723E-4, > > > > -2.6090705011393183E-4, -1.2633284900760366E-4, > > > > -6.485428846447651E-7}, > > > > {1.6671472561019247E-4, 2.341985572849691E-4, > > > > 2.9113916450678265E-4, -4.5760873539850514E-4, > > > > 1.3078636134987255E-5, -2.354289901013046E-5, > > -7.578030042426654E-7}, > > > > {4.4500080981934345E-4, 2.9113916450678265E-4, > > 7.46023915996829E-4, > > > > -0.0010247176498305568, -2.6745504327902895E-4, > > > > -1.6563544154823496E-4, -8.293698990696063E-7}, > > > > {-5.389129745055723E-4, -4.5760873539850514E-4, > > > > -0.0010247176498305568, 0.001754169535149865, > > > > 2.0293065310212377E-4, 2.1401092557826588E-4, > > 1.0252846778608953E-7}, > > > > {-2.6090705011393183E-4, 1.3078636134987255E-5, > > > > -2.6745504327902895E-4, 2.0293065310212377E-4, > > > > 4.632320892679136E-4, 1.7969731066037214E-4, > > 2.4953495129362833E-8}, > > > > {-1.2633284900760366E-4, -2.354289901013046E-5, > > > > -1.6563544154823496E-4, 2.1401092557826588E-4, > > > > 1.7969731066037214E-4, 8..346410612364995E-5, > > -7.02099350897589E-8}, > > > > {-6.485428846447651E-7, -7.578030042426654E-7, > > > > -8.293698990696063E-7, 1.0252846778608953E-7, > > > > 2.4953495129362833E-8, -7.02099350897589E-8, > > 8.367244992498656E-9}} > > > > > > > > [c]={{0.010638291263564232}, > > > > {0.013500370827906071}, > > > > {0.011390037735101773}, > > > > {0.010385042339767682}, > > > > {3.812208389845893E-4}, > > > > {0.002315505853720011}, > > > > {0.0}} > > > > > > > > > > > > [AI]={{1.0, 0.0, 0.0, 0.0, 0.0, > > 0.0, 0.0}, > > > > {0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0}, > > > > {0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0}, > > > > {0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0}, > > > > {0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0}, > > > > {0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0}, > > > > {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0}, > > > > {-1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, > > > > {0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0}, > > > > {0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0}, > > > > {0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0}, > > > > {0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0}, > > > > {0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0}, > > > > {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0}} > > > > > > > > [bi]={{1.0}, > > > > {1.0}, > > > > {1.0}, > > > > {1.0}, > > > > {1.0}, > > > > {1.0}, > > > > {1.0}, > > > > {0.0}, > > > > {0.0}, > > > > {0.0}, > > > > {0.0}, > > > > {0.0}, > > > > {0.0}, > > > > {0.0}} > > > > > > > > And here's the result: > > > > > > > > -0.25 > > > > -0.25 > > > > -0.25 > > > > -0.25 > > > > 0.75 > > > > 0.75 > > > > 0.75 > > > > > > > > And i found that if i change the nagetive ExceptedReturn to > > > > positive, the result will be fine. > > > > > > > > > > > > On Wed, 14 Jan 2009 09:27:53 +0100, Anders Peterson wrote > > > > > How small are the negative values? > > > > > > > > > > Give me a unit test (something that I can easily integrate > > with the > > > > > existing junit tests) that shows what you do, and where/how you > > > > > think it goes wrong. > > > > > > > > > > /Anders > > > > > > > > > > On 14 jan 2009, at 03.58, Ruan Weichao wrote: > > > > > > > > > > > > > > > > > Hi, > > > > > > > > > > > > I use the Markowitz model to calculate the optimize some > > assets' > > > > > > weights, > > > > > > > > > > > > and set all the assets' lowerlimit with Zero and set all the > > > > > > upperlimits with > > > > > > > > > > > > One, but it turns out with some negative value which are > > little > > > > > > than Zero, it > > > > > > > > > > > > seems that the lowerlimit does not work. > > > > > > > > > > > > So I want to ask what should I do it to confirm the > > lowerlimit? > > > > > > > > > > > > -- > > > > > > Best regards > > > > > > > > > > > > weichao > > > > > > > > > > > > > > > > > > ---------------------------------------------------------------------- > > > > > > -------- > > > > > > This SF.net email is sponsored by: > > > > > > SourcForge Community > > > > > > SourceForge wants to tell your story. > > > > > > http://p.sf.net/sfu/sf-spreadtheword > > > > > > _______________________________________________ > > > > > > ojAlgo-user mailing list > > > > > > ojA...@li... > > > > > > https://lists.sourceforge.net/lists/listinfo/ojalgo-user > > > > > > > > > > > > > > > > > > > > > > > > > > > > ---------------------------------------------------------------------- > > > > ------ > > > > -- > > > > > This SF.net email is sponsored by: > > > > > SourcForge Community > > > > > SourceForge wants to tell your story. > > > > > http://p.sf.net/sfu/sf-spreadtheword > > > > > _______________________________________________ > > > > > ojAlgo-user mailing list > > > > > ojA...@li... > > > > > https://lists.sourceforge.net/lists/listinfo/ojalgo-user > > > > > > > > > > > > -- > > > > Best regards > > > > > > > > > > ---------------------------------------------------------------------- > > > > -------- > > > > This SF.net email is sponsored by: > > > > SourcForge Community > > > > SourceForge wants to tell your story. > > > > http://p.sf.net/sfu/sf- > > > > spreadtheword_______________________________________________ > > > > ojAlgo-user mailing list > > > > ojA...@li... > > > > https://lists.sourceforge.net/lists/listinfo/ojalgo-user > > > > > > > > ---------------------------------------------------------------------- > > ------ > > -- > > > This SF.net email is sponsored by: > > > SourcForge Community > > > SourceForge wants to tell your story. > > > http://p.sf.net/sfu/sf-spreadtheword > > > _______________________________________________ > > > ojAlgo-user mailing list > > > ojA...@li... > > > https://lists.sourceforge.net/lists/listinfo/ojalgo-user > > > > > > -- > > Best regards > > > > ---------------------------------------------------------------------- > > -------- > > This SF.net email is sponsored by: > > SourcForge Community > > SourceForge wants to tell your story. > > http://p.sf.net/sfu/sf- > > spreadtheword_______________________________________________ > > ojAlgo-user mailing list > > ojA...@li... > > https://lists.sourceforge.net/lists/listinfo/ojalgo-user > > ---------------------------------------------------------------------------- -- > This SF.net email is sponsored by: > SourcForge Community > SourceForge wants to tell your story. > http://p.sf.net/sfu/sf-spreadtheword > _______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user -- Best regards |
From: Anders P. <an...@op...> - 2009-01-15 13:09:57
|
Your expected excess returns matrix looks like this: class org.ojalgo.matrix.BigMatrix {{-0.010638291263564232}, {-0.013500370827906071}, {-0.011390037735101773}, {-0.010385042339767682}, {-0.0003812208389845893}, {-0.002315505853720011}, {0}} Is that correct? Earlier you wrote "And i found that if i change the nagetive ExceptedReturn to positive, the result will be fine." /Anders On 15 jan 2009, at 11.10, Ruan Weichao wrote: > Hi,i am using v25 and here's my code: > > / > ********************************************************************** > **********/ > > import java.math.BigDecimal; > import java.util.List; > > import org.ojalgo.finance.portfolio.MarketEquilibrium; > import org.ojalgo.finance.portfolio.MarkowitzModel; > import org.ojalgo.matrix.*; > import org.ojalgo.matrix.store.BigDenseStore; > import org.ojalgo.matrix.store.MatrixStore; > > > public class TestMarkowitz { > > public double getCovarance(double[] value1, double[] value2){ > > int n = value1.length; > double averOne = 0; > double averTwo = 0; > for(int i=0;i<n;i++) > { > averOne+=value1[i]; > averTwo+=value2[i]; > } > averOne /= n; > averTwo /= n; > > double sum = 0; > for(int i=0;i<n;i++) > sum+=(value1[i]-averOne)*(value2[i]-averTwo); > > return sum / (n-1); > } > > public BasicMatrix getACovariances(double[][] returns){ > > int row = returns.length; > int col = returns[0].length; > MatrixStore<BigDecimal> a = BigDenseStore.FACTORY..makeZero(row, > col); > BasicMatrix covariances = new BigMatrix(a); > > for(int i=1;i<=row;i++){ > for(int j=i;j<=col;j++){ > double tmp = this.getCovarance(returns[i-1], returns[j-1]); > covariances = covariances.set(i-1, j-1,tmp); > covariances = covariances.set(j-1, i-1,tmp); > } > } > return covariances; > } > > public BasicMatrix getAnExpectedExcessReturns(double[][] returns){ > > int row = returns.length; > int col = returns[0].length; > > MatrixStore<BigDecimal> a = BigDenseStore.FACTORY..makeZero(row, 1); > BasicMatrix expectedExcessReturns = new BigMatrix(a); > > double riskFreeReturn = 0; > for(int i=1;i<=col;i++) > riskFreeReturn+=returns[row-1][i-1]; > riskFreeReturn/=row; > > for(int i=1;i<=row;i++){ > > double tmp = 0; > for(int j=1;j<=col;j++) > tmp+=returns[i-1][j-1]; > tmp/=col; > > expectedExcessReturns = expectedExcessReturns.set(i-1, 0, tmp- > riskFreeReturn); > } > > return expectedExcessReturns; > } > > public static void main(String[] args) > { > int assetNum=7; > double[][] assets_return={ > {-1.5905837442343828E-4, -0.03062360801781757, > -0.029857534032853142, -0.011811692726036832, > -0.017972310602803136, 0.017338003502626997, 0.0}, > {-0.02757158006362653, -0.02562704471101405, > -0.011751538891997735, -0.024915062287655786, -0.01684088269454123, > 0.013585351447135364, 0.0}, > {-0.00699300699300693, -0.033802816901408676, > -0.04675196850393671, -0.021166752710376546, -0.007911392405063583, > 0.03827751196172254, 0.0}, > {-0.007626310772164015, 0.0038424591738713027, > 0.02488038277511978, 0.025210084033613675, -0.02003642987249557, > -0.09758364312267642, 0.0}, > {-0.03965053763440893, 0.021693491952414375, > 0.01643835616438392, -0.007412398921833087, 0.01765105227427014, > -0.010006671114076025, 0.0}, > {-0.017821782178217872, 0.005040322580645311, > 0.006018054162487363, 9.008107296569024E-4, 0.002999999999999824, > -0.01196410767696908, 0.0}, > {2.630552127527583E-4, 2.5867028174649627E-4, > 2.3866431891514327E-4, 1.9564035993080523E-4, 2.351016690966669E-4, > 1.9070675120065465E-4, 0.0} > }; > > TestMarkowitz tm = new TestMarkowitz(); > BasicMatrix covariances = tm.getACovariances(assets_return); > BasicMatrix expectedExcessReturns = tm.getAnExpectedExcessReturns > (assets_return); > BigDecimal riskAversion = new BigDecimal(1.0); > > MarketEquilibrium marketEquilibrium = new MarketEquilibrium > (covariances,riskAversion); > MarkowitzModel markowitzModel = new MarkowitzModel > (marketEquilibrium,expectedExcessReturns); > > for(int i=0;i<assetNum;i++){ > markowitzModel.setLowerLimit(i, new BigDecimal(0.0)); > markowitzModel.setUpperLimit(i, new BigDecimal(1.0)); > } > List<BigDecimal> re = markowitzModel.getWeights(); > > System.out.println("=======result===================="); > for(int i=0;i<re.size();i++) > System.out.println(re.get(i)); > > return; > } > > } > > / > ********************************************************************** > **********/ > > and the result turn out as: > > -0.25 > -0.25 > -0.25 > -0.25 > 0.75 > 0.75 > 0.75 > > / > ********************************************************************** > ******/ > > If you find out any problem, just let me know , thanks a lot! > > On Thu, 15 Jan 2009 09:20:52 +0100, Anders Peterson wrote > > You have to send code (snippets) that I can execute. > > > > Are you using v25 or the latest from cvs? > > > > How do you instantiate the ActiveSetSolver? > > > > What's the correct solution? > > > > You say that if you change the sign of "C" you get an ok result. > > What does this mean? Did you make a mistake with the sign, or do > > you suspect there is a bug in ojAlgo? > > > > I need better info regarding what you do, and what the problem is! > > > > /Anders > > > > On 15 jan 2009, at 06.14, Ruan Weichao wrote: > > > > > > > > Thank you for your response. > > > > > > Here's my model's detail: > > > > > > [AE]={1.0, 1.0, 1.0, 1.0, 1.0, 1.0, > 1.0} > > > > > > > > > [be]={1.0} > > > > > > > > > [Q]={3.048907897157133E-4, 1.6671472561019247E-4, > > > 4.4500080981934345E-4, -5.389129745055723E-4, > > > -2.6090705011393183E-4, -1.2633284900760366E-4, > > > -6.485428846447651E-7}, > > > {1.6671472561019247E-4, 2.341985572849691E-4, > > > 2.9113916450678265E-4, -4.5760873539850514E-4, > > > 1.3078636134987255E-5, -2.354289901013046E-5, > -7.578030042426654E-7}, > > > {4.4500080981934345E-4, 2.9113916450678265E-4, > 7.46023915996829E-4, > > > -0.0010247176498305568, -2.6745504327902895E-4, > > > -1.6563544154823496E-4, -8.293698990696063E-7}, > > > {-5.389129745055723E-4, -4.5760873539850514E-4, > > > -0.0010247176498305568, 0.001754169535149865, > > > 2.0293065310212377E-4, 2.1401092557826588E-4, > 1.0252846778608953E-7}, > > > {-2.6090705011393183E-4, 1.3078636134987255E-5, > > > -2.6745504327902895E-4, 2.0293065310212377E-4, > > > 4.632320892679136E-4, 1.7969731066037214E-4, > 2.4953495129362833E-8}, > > > {-1.2633284900760366E-4, -2.354289901013046E-5, > > > -1.6563544154823496E-4, 2.1401092557826588E-4, > > > 1.7969731066037214E-4, 8..346410612364995E-5, > -7.02099350897589E-8}, > > > {-6.485428846447651E-7, -7.578030042426654E-7, > > > -8.293698990696063E-7, 1.0252846778608953E-7, > > > 2.4953495129362833E-8, -7.02099350897589E-8, > 8.367244992498656E-9}} > > > > > > [c]={{0.010638291263564232}, > > > {0.013500370827906071}, > > > {0.011390037735101773}, > > > {0.010385042339767682}, > > > {3.812208389845893E-4}, > > > {0.002315505853720011}, > > > {0.0}} > > > > > > > > > [AI]={{1.0, 0.0, 0.0, 0.0, 0.0, > 0.0, 0.0}, > > > {0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0}, > > > {0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0}, > > > {0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0}, > > > {0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0}, > > > {0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0}, > > > {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0}, > > > {-1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, > > > {0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0}, > > > {0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0}, > > > {0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0}, > > > {0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0}, > > > {0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0}, > > > {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0}} > > > > > > [bi]={{1.0}, > > > {1.0}, > > > {1.0}, > > > {1.0}, > > > {1.0}, > > > {1.0}, > > > {1.0}, > > > {0.0}, > > > {0.0}, > > > {0.0}, > > > {0.0}, > > > {0.0}, > > > {0.0}, > > > {0.0}} > > > > > > And here's the result: > > > > > > -0.25 > > > -0.25 > > > -0.25 > > > -0.25 > > > 0.75 > > > 0.75 > > > 0.75 > > > > > > And i found that if i change the nagetive ExceptedReturn to > > > positive, the result will be fine. > > > > > > > > > On Wed, 14 Jan 2009 09:27:53 +0100, Anders Peterson wrote > > > > How small are the negative values? > > > > > > > > Give me a unit test (something that I can easily integrate > with the > > > > existing junit tests) that shows what you do, and where/how you > > > > think it goes wrong. > > > > > > > > /Anders > > > > > > > > On 14 jan 2009, at 03.58, Ruan Weichao wrote: > > > > > > > > > > > > > > Hi, > > > > > > > > > > I use the Markowitz model to calculate the optimize some > assets' > > > > > weights, > > > > > > > > > > and set all the assets' lowerlimit with Zero and set all the > > > > > upperlimits with > > > > > > > > > > One, but it turns out with some negative value which are > little > > > > > than Zero, it > > > > > > > > > > seems that the lowerlimit does not work. > > > > > > > > > > So I want to ask what should I do it to confirm the > lowerlimit? > > > > > > > > > > -- > > > > > Best regards > > > > > > > > > > weichao > > > > > > > > > > > > > > ---------------------------------------------------------------------- > > > > > -------- > > > > > This SF.net email is sponsored by: > > > > > SourcForge Community > > > > > SourceForge wants to tell your story. > > > > > http://p.sf.net/sfu/sf-spreadtheword > > > > > _______________________________________________ > > > > > ojAlgo-user mailing list > > > > > ojA...@li... > > > > > https://lists.sourceforge.net/lists/listinfo/ojalgo-user > > > > > > > > > > > > > > > > > > > > > > ---------------------------------------------------------------------- > > > ------ > > > -- > > > > This SF.net email is sponsored by: > > > > SourcForge Community > > > > SourceForge wants to tell your story. > > > > http://p.sf.net/sfu/sf-spreadtheword > > > > _______________________________________________ > > > > ojAlgo-user mailing list > > > > ojA...@li... > > > > https://lists.sourceforge.net/lists/listinfo/ojalgo-user > > > > > > > > > -- > > > Best regards > > > > > > > ---------------------------------------------------------------------- > > > -------- > > > This SF.net email is sponsored by: > > > SourcForge Community > > > SourceForge wants to tell your story. > > > http://p.sf.net/sfu/sf- > > > spreadtheword_______________________________________________ > > > ojAlgo-user mailing list > > > ojA...@li... > > > https://lists.sourceforge.net/lists/listinfo/ojalgo-user > > > > > ---------------------------------------------------------------------- > ------ > -- > > This SF.net email is sponsored by: > > SourcForge Community > > SourceForge wants to tell your story. > > http://p.sf.net/sfu/sf-spreadtheword > > _______________________________________________ > > ojAlgo-user mailing list > > ojA...@li... > > https://lists.sourceforge.net/lists/listinfo/ojalgo-user > > > -- > Best regards > > ---------------------------------------------------------------------- > -------- > This SF.net email is sponsored by: > SourcForge Community > SourceForge wants to tell your story. > http://p.sf.net/sfu/sf- > spreadtheword_______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user |
From: Ruan W. <is0...@ma...> - 2009-01-15 10:10:28
|
<HTML> <HEAD> <META content="text/html; charset=gb2312" http-equiv=Content-Type> <META content="OPENWEBMAIL" name=GENERATOR> </HEAD> <BODY bgColor=#ffffff> <font size="2"> <p><font size="2"><b>Hi,i am using v25 and here's my code:</b></font></p> <p><strong><font size="2">/********************************************************************************/</font></strong></p> <p>import java.math.BigDecimal; <br />import java.util.List;</p> <p>import org.ojalgo.finance.portfolio.MarketEquilibrium; <br />import org.ojalgo.finance.portfolio.MarkowitzModel; <br />import org.ojalgo.matrix.*; <br />import org.ojalgo.matrix.store.BigDenseStore; <br />import org.ojalgo.matrix.store.MatrixStore;</p> <p> <br />public class TestMarkowitz { <br /> <br /> public double getCovarance(double[] value1, double[] value2){ <br /> <br /> int n = value1.length; <br /> double averOne = 0; <br /> double averTwo = 0; <br /> for(int i=0;i<n;i++) <br /> { <br /> averOne+=value1[i]; <br /> averTwo+=value2[i]; <br /> } <br /> averOne /= n; <br /> averTwo /= n; <br /> <br /> double sum = 0; <br /> for(int i=0;i<n;i++) <br /> sum+=(value1[i]-averOne)*(value2[i]-averTwo);</p> <p> return sum / (n-1); <br /> } <br /> <br /> public BasicMatrix getACovariances(double[][] returns){ <br /> <br /> int row = returns.length; <br /> int col = returns[0].length; <br /> MatrixStore<BigDecimal> a = BigDenseStore.FACTORY.makeZero(row, col); <br /> BasicMatrix covariances = new BigMatrix(a); <br /> <br /> for(int i=1;i<=row;i++){ <br /> for(int j=i;j<=col;j++){ <br /> double tmp = this.getCovarance(returns[i-1], returns[j-1]); <br /> covariances = covariances.set(i-1, j-1,tmp); <br /> covariances = covariances.set(j-1, i-1,tmp); <br /> } <br /> } <br /> return covariances; <br /> } <br /> <br /> public BasicMatrix getAnExpectedExcessReturns(double[][] returns){ <br /> <br /> int row = returns.length; <br /> int col = returns[0].length; <br /> <br /> MatrixStore<BigDecimal> a = BigDenseStore.FACTORY.makeZero(row, 1); <br /> BasicMatrix expectedExcessReturns = new BigMatrix(a); <br /> <br /> double riskFreeReturn = 0; <br /> for(int i=1;i<=col;i++) <br /> riskFreeReturn+=returns[row-1][i-1]; <br /> riskFreeReturn/=row; <br /> <br /> for(int i=1;i<=row;i++){ <br /> <br /> double tmp = 0; <br /> for(int j=1;j<=col;j++) <br /> tmp+=returns[i-1][j-1]; <br /> tmp/=col; <br /> <br /> expectedExcessReturns = expectedExcessReturns.set(i-1, 0, tmp-riskFreeReturn); <br /> } <br /> <br /> return expectedExcessReturns; <br /> }</p> <p> public static void main(String[] args) <br /> { <br /> int assetNum=7; <br /> double[][] assets_return={ <br /> {-1.5905837442343828E-4, -0.03062360801781757, -0.029857534032853142, -0.011811692726036832, -0.017972310602803136, 0.017338003502626997, 0.0}, <br /> {-0.02757158006362653, -0.02562704471101405, -0.011751538891997735, -0.024915062287655786, -0.01684088269454123, 0.013585351447135364, 0.0}, <br /> {-0.00699300699300693, -0.033802816901408676, -0.04675196850393671, -0.021166752710376546, -0.007911392405063583, 0.03827751196172254, 0.0}, <br /> {-0.007626310772164015, 0.0038424591738713027, 0.02488038277511978, 0.025210084033613675, -0.02003642987249557, -0.09758364312267642, 0.0}, <br /> {-0.03965053763440893, 0.021693491952414375, 0.01643835616438392, -0.007412398921833087, 0.01765105227427014, -0.010006671114076025, 0.0}, <br /> {-0.017821782178217872, 0.005040322580645311, 0.006018054162487363, 9.008107296569024E-4, 0.002999999999999824, -0.01196410767696908, 0.0}, <br /> {2.630552127527583E-4, 2.5867028174649627E-4, 2.3866431891514327E-4, 1.9564035993080523E-4, 2.351016690966669E-4, 1.9070675120065465E-4, 0.0} <br /> }; <br /> <br /> TestMarkowitz tm = new TestMarkowitz(); <br /> BasicMatrix covariances = tm.getACovariances(assets_return); <br /> BasicMatrix expectedExcessReturns = tm.getAnExpectedExcessReturns(assets_return); <br /> BigDecimal riskAversion = new BigDecimal(1.0); <br /> <br /> MarketEquilibrium marketEquilibrium = new MarketEquilibrium(covariances,riskAversion); <br /> MarkowitzModel markowitzModel = new MarkowitzModel(marketEquilibrium,expectedExcessReturns); <br /> <br /> for(int i=0;i<assetNum;i++){ <br /> markowitzModel.setLowerLimit(i, new BigDecimal(0.0)); <br /> markowitzModel.setUpperLimit(i, new BigDecimal(1.0)); <br /> } <br /> List<BigDecimal> re = markowitzModel.getWeights(); <br /> <br /> System.out.println("=======result===================="); <br /> for(int i=0;i<re.size();i++) <br /> System.out.println(re.get(i)); <br /> <br /> return; <br /> } <br /> <br />} <br /></p> <p><strong><font size="2">/********************************************************************************/</font></strong></p> <p><font size="2"><b>and the result turn out as:</b></font></p> <p>-0.25 <br />-0.25 <br />-0.25 <br />-0.25 <br />0.75 <br />0.75 <br />0.75</p> <p><strong><font size="2">/****************************************************************************/</font></strong></p> <p><strong><font size="2">If you find out any problem, just let me know , thanks a lot!</font></strong></p> </font> <p><font size="2">On Thu, 15 Jan 2009 09:20:52 +0100, Anders Peterson wrote <br />> You have to send code (snippets) that I can execute. <br />> <br />> Are you using v25 or the latest from cvs? <br />> <br />> How do you instantiate the ActiveSetSolver? <br />> <br />> What's the correct solution? <br />> <br />> You say that if you change the sign of "C" you get an ok result. <br />> What does this mean? Did you make a mistake with the sign, or do <br />> you suspect there is a bug in ojAlgo? <br />> <br />> I need better info regarding what you do, and what the problem is! <br />> <br />> /Anders <br />> <br />> On 15 jan 2009, at 06.14, Ruan Weichao wrote: <br />> <br />> > <br />> > Thank you for your response. <br />> > <br />> > Here's my model's detail: <br />> > <br />> > [AE]={1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0} <br />> > <br />> > <br />> > [be]={1.0} <br />> > <br />> > <br />> > [Q]={3.048907897157133E-4, 1.6671472561019247E-4, <br />> > 4.4500080981934345E-4, -5.389129745055723E-4, <br />> > -2.6090705011393183E-4, -1.2633284900760366E-4, <br />> > -6.485428846447651E-7}, <br />> > {1.6671472561019247E-4, 2.341985572849691E-4, <br />> > 2.9113916450678265E-4, -4.5760873539850514E-4, <br />> > 1.3078636134987255E-5, -2.354289901013046E-5, -7.578030042426654E-7}, <br />> > {4.4500080981934345E-4, 2.9113916450678265E-4, 7.46023915996829E-4, <br />> > -0.0010247176498305568, -2.6745504327902895E-4, <br />> > -1.6563544154823496E-4, -8.293698990696063E-7}, <br />> > {-5.389129745055723E-4, -4.5760873539850514E-4, <br />> > -0.0010247176498305568, 0.001754169535149865, <br />> > 2.0293065310212377E-4, 2.1401092557826588E-4, 1.0252846778608953E-7}, <br />> > {-2.6090705011393183E-4, 1.3078636134987255E-5, <br />> > -2.6745504327902895E-4, 2.0293065310212377E-4, <br />> > 4.632320892679136E-4, 1.7969731066037214E-4, 2.4953495129362833E-8}, <br />> > {-1.2633284900760366E-4, -2.354289901013046E-5, <br />> > -1.6563544154823496E-4, 2.1401092557826588E-4, <br />> > 1.7969731066037214E-4, 8..346410612364995E-5, -7.02099350897589E-8}, <br />> > {-6.485428846447651E-7, -7.578030042426654E-7, <br />> > -8.293698990696063E-7, 1.0252846778608953E-7, <br />> > 2.4953495129362833E-8, -7.02099350897589E-8, 8.367244992498656E-9}} <br />> > <br />> > [c]={{0.010638291263564232}, <br />> > {0.013500370827906071}, <br />> > {0.011390037735101773}, <br />> > {0.010385042339767682}, <br />> > {3.812208389845893E-4}, <br />> > {0.002315505853720011}, <br />> > {0.0}} <br />> > <br />> > <br />> > [AI]={{1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, <br />> > {0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0}, <br />> > {0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0}, <br />> > {0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0}, <br />> > {0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0}, <br />> > {0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0}, <br />> > {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0}, <br />> > {-1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, <br />> > {0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0}, <br />> > {0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0}, <br />> > {0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0}, <br />> > {0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0}, <br />> > {0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0}, <br />> > {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0}} <br />> > <br />> > [bi]={{1.0}, <br />> > {1.0}, <br />> > {1.0}, <br />> > {1.0}, <br />> > {1.0}, <br />> > {1.0}, <br />> > {1.0}, <br />> > {0.0}, <br />> > {0.0}, <br />> > {0.0}, <br />> > {0.0}, <br />> > {0.0}, <br />> > {0.0}, <br />> > {0.0}} <br />> > <br />> > And here's the result: <br />> > <br />> > -0.25 <br />> > -0.25 <br />> > -0.25 <br />> > -0.25 <br />> > 0.75 <br />> > 0.75 <br />> > 0.75 <br />> > <br />> > And i found that if i change the nagetive ExceptedReturn to <br />> > positive, the result will be fine. <br />> > <br />> > <br />> > On Wed, 14 Jan 2009 09:27:53 +0100, Anders Peterson wrote <br />> > > How small are the negative values? <br />> > > <br />> > > Give me a unit test (something that I can easily integrate with the <br />> > > existing junit tests) that shows what you do, and where/how you <br />> > > think it goes wrong. <br />> > > <br />> > > /Anders <br />> > > <br />> > > On 14 jan 2009, at 03.58, Ruan Weichao wrote: <br />> > > <br />> > > > <br />> > > > Hi, <br />> > > > <br />> > > > I use the Markowitz model to calculate the optimize some assets' <br />> > > > weights, <br />> > > > <br />> > > > and set all the assets' lowerlimit with Zero and set all the <br />> > > > upperlimits with <br />> > > > <br />> > > > One, but it turns out with some negative value which are little <br />> > > > than Zero, it <br />> > > > <br />> > > > seems that the lowerlimit does not work. <br />> > > > <br />> > > > So I want to ask what should I do it to confirm the lowerlimit? <br />> > > > <br />> > > > -- <br />> > > > Best regards <br />> > > > <br />> > > > weichao <br />> > > > <br />> > > > <br />> > ---------------------------------------------------------------------- <br />> > > > -------- <br />> > > > This SF.net email is sponsored by: <br />> > > > SourcForge Community <br />> > > > SourceForge wants to tell your story. <br />> > > > <a href="http://p.sf.net/sfu/sf-spreadtheword" target="_blank">http://p.sf.net/sfu/sf-spreadtheword</a> <br />> > > > _______________________________________________ <br />> > > > ojAlgo-user mailing list <br />> > > > ojA...@li... <br />> > > > <a href="https://lists.sourceforge.net/lists/listinfo/ojalgo-user" target="_blank">https://lists.sourceforge.net/lists/listinfo/ojalgo-user</a> <br />> > > > <br />> > > > <br />> > > <br />> > > <br />> > ---------------------------------------------------------------------- <br />> > ------ <br />> > -- <br />> > > This SF.net email is sponsored by: <br />> > > SourcForge Community <br />> > > SourceForge wants to tell your story. <br />> > > <a href="http://p.sf.net/sfu/sf-spreadtheword" target="_blank">http://p.sf.net/sfu/sf-spreadtheword</a> <br />> > > _______________________________________________ <br />> > > ojAlgo-user mailing list <br />> > > ojA...@li... <br />> > > <a href="https://lists.sourceforge.net/lists/listinfo/ojalgo-user" target="_blank">https://lists.sourceforge.net/lists/listinfo/ojalgo-user</a> <br />> > <br />> > <br />> > -- <br />> > Best regards <br />> > <br />> > ---------------------------------------------------------------------- <br />> > -------- <br />> > This SF.net email is sponsored by: <br />> > SourcForge Community <br />> > SourceForge wants to tell your story. <br />> > <a href="http://p.sf.net/sfu/sf" target="_blank">http://p.sf.net/sfu/sf</a>- <br />> > spreadtheword_______________________________________________ <br />> > ojAlgo-user mailing list <br />> > ojA...@li... <br />> > <a href="https://lists.sourceforge.net/lists/listinfo/ojalgo-user" target="_blank">https://lists.sourceforge.net/lists/listinfo/ojalgo-user</a> <br />> <br />> ---------------------------------------------------------------------------- <br />-- <br />> This SF.net email is sponsored by: <br />> SourcForge Community <br />> SourceForge wants to tell your story. <br />> <a href="http://p.sf.net/sfu/sf-spreadtheword" target="_blank">http://p.sf.net/sfu/sf-spreadtheword</a> <br />> _______________________________________________ <br />> ojAlgo-user mailing list <br />> ojA...@li... <br />> <a href="https://lists.sourceforge.net/lists/listinfo/ojalgo-user" target="_blank">https://lists.sourceforge.net/lists/listinfo/ojalgo-user</a> <br /> <br /> <br />-- <br />Best regards <br /></font></p> </BODY> </HTML> |
From: Anders P. <an...@op...> - 2009-01-15 08:21:00
|
You have to send code (snippets) that I can execute. Are you using v25 or the latest from cvs? How do you instantiate the ActiveSetSolver? What's the correct solution? You say that if you change the sign of "C" you get an ok result. What does this mean? Did you make a mistake with the sign, or do you suspect there is a bug in ojAlgo? I need better info regarding what you do, and what the problem is! /Anders On 15 jan 2009, at 06.14, Ruan Weichao wrote: > > Thank you for your response. > > Here's my model's detail: > > [AE]={1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0} > > > [be]={1.0} > > > [Q]={3.048907897157133E-4, 1.6671472561019247E-4, > 4.4500080981934345E-4, -5.389129745055723E-4, > -2.6090705011393183E-4, -1.2633284900760366E-4, > -6.485428846447651E-7}, > {1.6671472561019247E-4, 2.341985572849691E-4, > 2.9113916450678265E-4, -4.5760873539850514E-4, > 1.3078636134987255E-5, -2.354289901013046E-5, -7.578030042426654E-7}, > {4.4500080981934345E-4, 2.9113916450678265E-4, 7.46023915996829E-4, > -0.0010247176498305568, -2.6745504327902895E-4, > -1.6563544154823496E-4, -8.293698990696063E-7}, > {-5.389129745055723E-4, -4.5760873539850514E-4, > -0.0010247176498305568, 0.001754169535149865, > 2.0293065310212377E-4, 2.1401092557826588E-4, 1.0252846778608953E-7}, > {-2.6090705011393183E-4, 1.3078636134987255E-5, > -2.6745504327902895E-4, 2.0293065310212377E-4, > 4.632320892679136E-4, 1.7969731066037214E-4, 2.4953495129362833E-8}, > {-1.2633284900760366E-4, -2.354289901013046E-5, > -1.6563544154823496E-4, 2.1401092557826588E-4, > 1.7969731066037214E-4, 8..346410612364995E-5, -7.02099350897589E-8}, > {-6.485428846447651E-7, -7.578030042426654E-7, > -8.293698990696063E-7, 1.0252846778608953E-7, > 2.4953495129362833E-8, -7.02099350897589E-8, 8.367244992498656E-9}} > > [c]={{0.010638291263564232}, > {0.013500370827906071}, > {0.011390037735101773}, > {0.010385042339767682}, > {3.812208389845893E-4}, > {0.002315505853720011}, > {0.0}} > > > [AI]={{1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, > {0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0}, > {0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0}, > {0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0}, > {0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0}, > {0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0}, > {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0}, > {-1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, > {0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0}, > {0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0}, > {0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0}, > {0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0}, > {0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0}, > {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0}} > > [bi]={{1.0}, > {1.0}, > {1.0}, > {1.0}, > {1.0}, > {1.0}, > {1.0}, > {0.0}, > {0.0}, > {0.0}, > {0.0}, > {0.0}, > {0.0}, > {0.0}} > > And here's the result: > > -0.25 > -0.25 > -0.25 > -0.25 > 0.75 > 0.75 > 0.75 > > And i found that if i change the nagetive ExceptedReturn to > positive, the result will be fine. > > > On Wed, 14 Jan 2009 09:27:53 +0100, Anders Peterson wrote > > How small are the negative values? > > > > Give me a unit test (something that I can easily integrate with the > > existing junit tests) that shows what you do, and where/how you > > think it goes wrong. > > > > /Anders > > > > On 14 jan 2009, at 03.58, Ruan Weichao wrote: > > > > > > > > Hi, > > > > > > I use the Markowitz model to calculate the optimize some assets' > > > weights, > > > > > > and set all the assets' lowerlimit with Zero and set all the > > > upperlimits with > > > > > > One, but it turns out with some negative value which are little > > > than Zero, it > > > > > > seems that the lowerlimit does not work. > > > > > > So I want to ask what should I do it to confirm the lowerlimit? > > > > > > -- > > > Best regards > > > > > > weichao > > > > > > > ---------------------------------------------------------------------- > > > -------- > > > This SF.net email is sponsored by: > > > SourcForge Community > > > SourceForge wants to tell your story. > > > http://p.sf.net/sfu/sf-spreadtheword > > > _______________________________________________ > > > ojAlgo-user mailing list > > > ojA...@li... > > > https://lists.sourceforge.net/lists/listinfo/ojalgo-user > > > > > > > > > > > ---------------------------------------------------------------------- > ------ > -- > > This SF.net email is sponsored by: > > SourcForge Community > > SourceForge wants to tell your story. > > http://p.sf.net/sfu/sf-spreadtheword > > _______________________________________________ > > ojAlgo-user mailing list > > ojA...@li... > > https://lists.sourceforge.net/lists/listinfo/ojalgo-user > > > -- > Best regards > > ---------------------------------------------------------------------- > -------- > This SF.net email is sponsored by: > SourcForge Community > SourceForge wants to tell your story. > http://p.sf.net/sfu/sf- > spreadtheword_______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user |
From: Ruan W. <is0...@ma...> - 2009-01-15 05:14:34
|
<HTML> <HEAD> <META content="text/html; charset=gb2312" http-equiv=Content-Type> <META content="OPENWEBMAIL" name=GENERATOR> </HEAD> <BODY bgColor=#ffffff> <font size="2"> <p> <br />Thank you for your response. <br /> <br />Here's my model's detail: <br /> <br />[AE]={1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0} </p> <p> <br />[be]={1.0} </p> <p> <br />[Q]={3.048907897157133E-4, 1.6671472561019247E-4, 4.4500080981934345E-4, -5.389129745055723E-4, -2.6090705011393183E-4, -1.2633284900760366E-4, -6.485428846447651E-7}, <br />{1.6671472561019247E-4, 2.341985572849691E-4, 2.9113916450678265E-4, -4.5760873539850514E-4, 1.3078636134987255E-5, -2.354289901013046E-5, -7.578030042426654E-7}, <br />{4.4500080981934345E-4, 2.9113916450678265E-4, 7.46023915996829E-4, -0.0010247176498305568, -2.6745504327902895E-4, -1.6563544154823496E-4, -8.293698990696063E-7}, <br />{-5.389129745055723E-4, -4.5760873539850514E-4, -0.0010247176498305568, 0.001754169535149865, 2.0293065310212377E-4, 2.1401092557826588E-4, 1.0252846778608953E-7}, <br />{-2.6090705011393183E-4, 1.3078636134987255E-5, -2.6745504327902895E-4, 2.0293065310212377E-4, 4.632320892679136E-4, 1.7969731066037214E-4, 2.4953495129362833E-8}, <br />{-1.2633284900760366E-4, -2.354289901013046E-5, -1.6563544154823496E-4, 2.1401092557826588E-4, 1.7969731066037214E-4, 8.346410612364995E-5, -7.02099350897589E-8}, <br />{-6.485428846447651E-7, -7.578030042426654E-7, -8.293698990696063E-7, 1.0252846778608953E-7, 2.4953495129362833E-8, -7.02099350897589E-8, 8.367244992498656E-9}}</p> <p>[c]={{0.010638291263564232}, <br />{0.013500370827906071}, <br />{0.011390037735101773}, <br />{0.010385042339767682}, <br />{3.812208389845893E-4}, <br />{0.002315505853720011}, <br />{0.0}} </p> <p> <br />[AI]={{1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, <br />{0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0}, <br />{0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0}, <br />{0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0}, <br />{0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0}, <br />{0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0}, <br />{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0}, <br />{-1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, <br />{0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0}, <br />{0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0}, <br />{0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0}, <br />{0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0}, <br />{0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0}, <br />{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0}} <br /></p> <p>[bi]={{1.0}, <br />{1.0}, <br />{1.0}, <br />{1.0}, <br />{1.0}, <br />{1.0}, <br />{1.0}, <br />{0.0}, <br />{0.0}, <br />{0.0}, <br />{0.0}, <br />{0.0}, <br />{0.0}, <br />{0.0}} <br /></p> <p>And here's the result:</p> <p>-0.25 <br />-0.25 <br />-0.25 <br />-0.25 <br />0.75 <br />0.75 <br />0.75</p> <p>And i found that if i change the nagetive ExceptedReturn to positive, the result will be fine.</p> <p> <br />On Wed, 14 Jan 2009 09:27:53 +0100, Anders Peterson wrote <br />> How small are the negative values? <br />> <br />> Give me a unit test (something that I can easily integrate with the <br />> existing junit tests) that shows what you do, and where/how you <br />> think it goes wrong. <br />> <br />> /Anders <br />> <br />> On 14 jan 2009, at 03.58, Ruan Weichao wrote: <br />> <br />> > <br />> > Hi, <br />> > <br />> > I use the Markowitz model to calculate the optimize some assets' <br />> > weights, <br />> > <br />> > and set all the assets' lowerlimit with Zero and set all the <br />> > upperlimits with <br />> > <br />> > One, but it turns out with some negative value which are little <br />> > than Zero, it <br />> > <br />> > seems that the lowerlimit does not work. <br />> > <br />> > So I want to ask what should I do it to confirm the lowerlimit? <br />> > <br />> > -- <br />> > Best regards <br />> > <br />> > weichao <br />> > <br />> > ---------------------------------------------------------------------- <br />> > -------- <br />> > This SF.net email is sponsored by: <br />> > SourcForge Community <br />> > SourceForge wants to tell your story. <br />> > <a href="http://p.sf.net/sfu/sf-spreadtheword" target="_blank">http://p.sf.net/sfu/sf-spreadtheword</a> <br />> > _______________________________________________ <br />> > ojAlgo-user mailing list <br />> > ojA...@li... <br />> > <a href="https://lists.sourceforge.net/lists/listinfo/ojalgo-user" target="_blank">https://lists.sourceforge.net/lists/listinfo/ojalgo-user</a> <br />> > <br />> > <br />> <br />> ---------------------------------------------------------------------------- <br />-- <br />> This SF.net email is sponsored by: <br />> SourcForge Community <br />> SourceForge wants to tell your story. <br />> <a href="http://p.sf.net/sfu/sf-spreadtheword" target="_blank">http://p.sf.net/sfu/sf-spreadtheword</a> <br />> _______________________________________________ <br />> ojAlgo-user mailing list <br />> ojA...@li... <br />> <a href="https://lists.sourceforge.net/lists/listinfo/ojalgo-user" target="_blank">https://lists.sourceforge.net/lists/listinfo/ojalgo-user</a> <br /> <br /> <br />-- <br />Best regards <br /></p> </font> </BODY> </HTML> |
From: Anders P. <an...@op...> - 2009-01-14 09:03:52
|
I believe this is the first time a list member (other than me) tried to help another member! On 14 jan 2009, at 09.26, bru...@uk... wrote: > Hi, even if I am not the expert ni this topic, I think your problem > is that actually your model fails to find a solution and then just > gives you wrong results that are beyond your constraints. Please give me test cases for things you think should work, but currently doesn't. > I had this problem to when ysing a sytem with ActiveSetSolver. > Before looking at your solution you should check that the > optimization actually did not failed. This could be the case, but I'd like to see the actual case. With all lower limits set to 0 and all upper limits set to 1 (and no other constraints) the ActiveSetSolver should be able to find a solution. The quadratic solvers has been much improved since the release of version 25. If it's not to much trouble I'd recommend getting the latest source code from CVS. There's still a few things I'd like to fix before releasing version 26. /Anders > BasicMatrix[] system = new BasicMatrix[6]; > //[AE], [be], [Q], [c], [AI], [bi] > ..... > //create your matrix here > ..... > > ActiveSetSolver as = new ActiveSetSolver(system); > > OptimisationSolver.Result res = as.solve(); > State state = res.getState(); > > if(state != state.FAILED ) { > solution = res.getSolution(); > } > Let me know if this solve your problem. > Regards > BF > > > > > Internet > is0...@ma... > 14/01/2009 02:58 > Please respond to > oja...@li... > > To > oja...@li... > cc > Subject > [ojAlgo-user] Markowitz Model Problem > > > > > > > Hi, > > I use the Markowitz model to calculate the optimize some assets' > weights, > > and set all the assets' lowerlimit with Zero and set all the > upperlimits with > > One, but it turns out with some negative value which are little > than Zero, it > > seems that the lowerlimit does not work. > > So I want to ask what should I do it to confirm the lowerlimit? > > -- > Best regards > > weichao > > ---------------------------------------------------------------------- > -------- > This SF.net email is sponsored by: > SourcForge Community > SourceForge wants to tell your story. > http://p.sf.net/sfu/sf-spreadtheword > _______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user > > This communication is confidential, may be privileged and is meant > only for the intended recipient. If you are not the intended > recipient, please notify the sender by reply and delete the message > from your system. Any unauthorised dissemination, distribution or > copying hereof is prohibited. BNP Paribas Trust Corporation UK > Limited, BNP Paribas UK Limited, BNP Paribas Commodity Futures > Limited, BNP Paribas Asset Management UK Limited and Investment > Fund Services Limited are authorised and regulated by the Financial > Services Authority. BNP Paribas London Branch and BNP Paribas > Private Bank London Branch are authorised by the CECEI and > supervised by the Commission Bancaire. BNP Paribas London Branch is > authorised and subject to limited regulation by the Financial > Services Authority. Details about the extent of our authorisation > and regulation by the Financial Services Authority are available > from us on request. BNP Paribas is also a member of the London > Stock Exchange. BNP Paribas Private Bank London Branch is subject > to limited regulation by the Financial Services Authority. Details > about the extent of our authorisation and regulation by the > Financial Services Authority are available from us on request. BNP > Paribas Securities Services London Branch is authorised by the > CECEI and supervised by the AMF, and subject to limited regulation > by the Financial Services Authority. Details on the extent of our > regulation by the Financial Services Authority are available from > us on request. BNP Paribas Securities Services is also a member of > the London Stock Exchange. > ---------------------------------------------------------------------- > -------- > This SF.net email is sponsored by: > SourcForge Community > SourceForge wants to tell your story. > http://p.sf.net/sfu/sf- > spreadtheword_______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user |
From: <bru...@uk...> - 2009-01-14 08:41:55
|
Hi, even if I am not the expert ni this topic, I think your problem is that actually your model fails to find a solution and then just gives you wrong results that are beyond your constraints. I had this problem to when ysing a sytem with ActiveSetSolver. Before looking at your solution you should check that the optimization actually did not failed. BasicMatrix[] system = new BasicMatrix[6]; //[AE], [be], [Q], [c], [AI], [bi] ..... //create your matrix here ..... ActiveSetSolver as = new ActiveSetSolver(system); OptimisationSolver.Result res = as.solve(); State state = res.getState(); if(state != state.FAILED ) { solution = res.getSolution(); } Let me know if this solve your problem. Regards BF Internet is0...@ma... 14/01/2009 02:58 Please respond to oja...@li... To oja...@li... cc Subject [ojAlgo-user] Markowitz Model Problem Hi, I use the Markowitz model to calculate the optimize some assets' weights, and set all the assets' lowerlimit with Zero and set all the upperlimits with One, but it turns out with some negative value which are little than Zero, it seems that the lowerlimit does not work. So I want to ask what should I do it to confirm the lowerlimit? -- Best regards weichao ------------------------------------------------------------------------------ This SF.net email is sponsored by: SourcForge Community SourceForge wants to tell your story. http://p.sf.net/sfu/sf-spreadtheword _______________________________________________ ojAlgo-user mailing list ojA...@li... https://lists.sourceforge.net/lists/listinfo/ojalgo-user This communication is confidential, may be privileged and is meant only for the intended recipient. If you are not the intended recipient, please notify the sender by reply and delete the message from your system. Any unauthorised dissemination, distribution or copying hereof is prohibited. BNP Paribas Trust Corporation UK Limited, BNP Paribas UK Limited, BNP Paribas Commodity Futures Limited, BNP Paribas Asset Management UK Limited and Investment Fund Services Limited are authorised and regulated by the Financial Services Authority. BNP Paribas London Branch and BNP Paribas Private Bank London Branch are authorised by the CECEI and supervised by the Commission Bancaire. BNP Paribas London Branch is authorised and subject to limited regulation by the Financial Services Authority. Details about the extent of our authorisation and regulation by the Financial Services Authority are available from us on request. BNP Paribas is also a member of the London Stock Exchange. BNP Paribas Private Bank London Branch is subject to limited regulation by the Financial Services Authority. Details about the extent of our authorisation and regulation by the Financial Services Authority are available from us on request. BNP Paribas Securities Services London Branch is authorised by the CECEI and supervised by the AMF, and subject to limited regulation by the Financial Services Authority. Details on the extent of our regulation by the Financial Services Authority are available from us on request. BNP Paribas Securities Services is also a member of the London Stock Exchange. |
From: Anders P. <an...@op...> - 2009-01-14 08:28:07
|
How small are the negative values? Give me a unit test (something that I can easily integrate with the existing junit tests) that shows what you do, and where/how you think it goes wrong. /Anders On 14 jan 2009, at 03.58, Ruan Weichao wrote: > > Hi, > > I use the Markowitz model to calculate the optimize some assets' > weights, > > and set all the assets' lowerlimit with Zero and set all the > upperlimits with > > One, but it turns out with some negative value which are little > than Zero, it > > seems that the lowerlimit does not work. > > So I want to ask what should I do it to confirm the lowerlimit? > > -- > Best regards > > weichao > > ---------------------------------------------------------------------- > -------- > This SF.net email is sponsored by: > SourcForge Community > SourceForge wants to tell your story. > http://p.sf.net/sfu/sf-spreadtheword > _______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user > > |
From: Ruan W. <is0...@ma...> - 2009-01-14 02:59:07
|
Hi, I use the Markowitz model to calculate the optimize some assets' weights, and set all the assets' lowerlimit with Zero and set all the upperlimits with One, but it turns out with some negative value which are little than Zero, it seems that the lowerlimit does not work. So I want to ask what should I do it to confirm the lowerlimit? -- Best regards weichao |
From: Anders P. <an...@op...> - 2009-01-13 18:07:41
|
On 13 jan 2009, at 16.19, bru...@uk... wrote: > Hej, I would like to know where I can get the BLApp application > source code? You cannot get it - it's not open source. > Indeed, the links on the olAlgo and on the Optimatika web sites > seems to be broken. Yes, there seems to be a problem. I can most likely fix that as soon as I get to the office tomorrow morning. Try again later tomorrow... > I succesfully solved my optimization problem using ActiveSolver with > a system and now I would like to use the Black-Litterman Model. > On the ojAlgo websida it is mentionned the following: > The Black-LItterman model delegates to a Markowitz model that in > turn generates a quadratic optimisation model that instantiates an > active set solver that iteratively calls a lagrange solver I see that some of those javadoc links are outdated (but they do give you info about where to go). Start here: http://ojalgo.org/generated/org/ojalgo/finance/portfolio/BlackLittermanModel.html or better still, look at the source code for that class (and everything else in that package). > Though it doesn't help me that much. It would be great if I could > see how it is implementde using a Model. If you don't want to use the BlackLittermanModel class you can looks at its source and do the same thing. If you have questions related to (using) ojAlgo source code you may ask about that on the ojAlgo-user mailing list. https://lists.sourceforge.net/lists/listinfo/ojalgo-user /Anders |
From: Anders P. <an...@op...> - 2009-01-10 17:03:46
|
You have to be a member to post to the list, and the code you posted makes no sense to me. Have you tried: BasicMatrix tmpRandomBigMatrix = BigMatrix.FACTORY.buildRandom(int, int, RandomNumber); There are many different random number implementations/distributions: http://ojalgo.org/generated/org/ojalgo/random/RandomNumber.html /Anders On 10 jan 2009, at 14.09, oja...@li... wrote: > The attached message has been automatically discarded. > Date: lördag 10 jan 2009 13.42.36 GMT+01:00 > To: oja...@li... > Subject: BigMatrix > > > Hi there > > I try to instantiate a BigMatrix Object with random BigDecimal > values (nxn matrix). Most probably it is very obvious but I don't > get it... > I tried something like that: > Error BigDenseStore bigStore=BigDenseStore; > bigStore.add(new BigDecimal("4355")); > BigMatrix bigA=new BigMatrix(bigStore); > > > For those who wondering what the bigger problem is: > I want to square a nxn matrix multiple times. I implemented it > already with the Matrix object from the JAMA package. The problem I > had, is that I get INFINITY values after 5 squarings already.... So > I need a matrix object with BigDecimal values.... > > > Could somebody help me? > > Cheers > Rolf > > > > > |
From: Anders P. <an...@op...> - 2008-12-22 10:07:53
|
On 19 dec 2008, at 15.47, Oddvar Grønning wrote: > Changing the sign of the c vector did fix the odd results of the > new solver.. I had not noticed the change. > > Further, I found a bug in my own code (sorry!). I change the sign > of the elements in c according to the sign of the corresponding vx2 > variable, this is to force the variables towards zero. This causes > oscillations around zero if the variable is (near) zero, vx2_0 in > this case. If I detect oscillations like this I set the variable to > zero and change the constraints 0.0 < variable < 0.0. The faulty > detection of the oscillation was the reason the version with AS did > not converge. After I fixed it, the AS results had the same > accuracy as Matlabs, and about the same performance. (I got latest > version from CVS today). Having roughly the same performance and accuracy as MatLab seems ok to me. > I have done a few more test (changing tau) where the AS fails [60 > 10 0] and matlab does not. This can probably be fixed by the new > Builder system, but I have to look into it some more later. Any > hints on how to use the enforce method? I'm testing a new/simpler/different implementation of NumberContext.enforce(double), and changed Builder.enforce (NumberContext) to Builder.round(int) - they do the same thing with this new implementation. They simply round to a specified number of decimals. Note that if you call more than one of the methods balance, eliminate and round it matters in which order you do it. There is no correct or wrong order; just different results. /Anders > -----Original Message----- >> From: Anders Peterson [mailto:an...@op...] > Sent: 19. desember 2008 12:12 > To: Anders Peterson > Subject: Re: [ojAlgo-user] v25.1 > > On 18 dec 2008, at 20.15, Oddvar Grønning wrote: > >> Hi, >> >> I've been comparing the 25.1 ActiveSetSolver version with the one >> currently in the CVS. Both of them are again compared to Matlabs >> quadprog QP solver. >> >> My system is quite complex, I've reduced the example code as much >> as I possibly can, but it is still quite large. You asked for test >> cases, so here it goes.:-) > > > It'll take me some time to study this. Don't think I have that time > before Xmas. > > >> I've made a SQP for nonlinear problems using the ActiveSetSolver as >> QP engine. This means that I am linearizing and iterating till a >> good enough solution is found. >> >> What I have found is that Matlab produces results very close to the >> expected result, within 2 decimals. The AS 25.1 version produces >> results within 1 decimal of expected results, but uses way to much >> cpu-time. The latest AS version is fast, but the results are >> different from Matlabs and the 25.1 version. See simulations >> results below. > > > I had set the iterations limit too tight - perhaps that was part of > the problem. Also changed a couple of other things yesterday. Get the > latest source from CVS. > > Have you tried the new builder/presolver? > > http://ojalgo.org/generated/org/ojalgo/optimisation/quadratic/ > QuadraticSolver.Builder.html > > Calling "balance" and maybe "enforce" will change the quality of the > solution. > > When you move from using the AS constructor with your BasicMatrix[] > to using the QuadraticSolver.Builder you should change the sign of > "C". > > I was able to get results, on your previous test cases, much closer > to the MatLab-solution by simply "balancing" and "enforcing". But you > should really try to do this earlier in your program. Once you end up > with a number like -3.5E-15 you have already lost some precision. You > can't just scale it back up to a larger number. > > >> I think I need to explain the system a bit. There are 10 variables >> to find optimum values for, the first 5 are low cost, they can have >> any value within the constraints. The next 5 have high cost and >> should be as close to zero as possible. There are nonlinear >> relationships between the variables, defined as equality >> constraints. 3 slack variables are used for the equality >> constraints to ensure a feasible solution. This makes a total of 13 >> variables.. >> >> The slack variables s are defined: >> >> s = tau - Beta(vx1)*vx2, where tau is a vector and Beta is a >> matrix, we want s->0. vx1 are the first 5 low cost states and vx2 >> are the high cost states. >> >> In the example I set tau to be [60 0 0]'. The expected result is: >> >> vx1: 1.5708; 0; 0; 0; 0; vx2: 0; 5; 5; 25; 25 >> >> In the first call to the SQP all states are zero. In the second >> call the result variables from the first call are used as start >> values. >> >> Matlab produces: >> >> i = 1 >> >> Solution found after 11 iterations >> Result vx1: 1.5708; -1.0601e-005; -0.002093; 0.00073549; >> -0.00031633; vx2: 0; 4.9991; 4.9947; 24.9996; 25.0065 >> Elapsed time is 0.641000 seconds. >> >> i = 2 >> >> Solution found after 1 iterations >> Result vx1: 1.5708; -0.0020056; -9.2987e-005; -0.0012645; >> 0.0016837; vx2: -5.0796e-017; 4.9991; 4.9947; 24.9997; 25.0064 >> Elapsed time is 0.015000 seconds. >> >> Version 25.1 of AS produces: >> >> Simstep 0 >> Aborting, too long time consumed ( > 5 sec). numIt: 41 >> Result: vx1_0: 1.5707672233183787 vx1_1: 1.6823620274180337E-4 >> vx1_2: -0.00196511057420812 vx1_3: -0.002354032968486829 vx1_4: >> 0.0015265945920139418 vx2_0: 0.029590231612839257 vx2_1: >> 4.999569087984196 vx2_2: 4.990762180635852 vx2_3: 25.10133831261425 >> vx2_4: 24.908290373430617 >> Elapsed time is: 5.172 seconds >> >> Simstep 1 >> Aborting, too long time consumed ( > 5 sec). numIt: 17 >> Result: vx1_0: 1.5707672230998035 vx1_1: 1.6823670234216445E-4 >> vx1_2: -0.001965110213385637 vx1_3: -0.0023328019515429285 vx1_4: >> 0.0015265967291932642 vx2_0: 0.0290511558573982 vx2_1: >> 4.999360102203392 vx2_2: 4.990900599987205 vx2_3: >> 25.099688807764156 vx2_4: 24.910009190020308 >> Elapsed time is: 5.015 seconds >> >> Latest AS produces: >> >> Simstep 0 >> Solution found after 50 iteration(s) >> Result: vx1_0: 1.5708199749750982 vx1_1: 0.0920372744518574 vx1_2: >> 0.09394993946428473 vx1_3: -0.09067631072129541 vx1_4: >> 0.0808235035333966 vx2_0: -1.427792446101636 vx2_1: >> 4.557265828873959 vx2_2: 5.000000000931323 vx2_3: >> 20.727837553658237 vx2_4: 29.939015120581345 >> Elapsed time is: 1.578 seconds >> >> Simstep 1 >> Solution found after 1 iteration(s) >> Result: vx1_0: 1.5708199751971428 vx1_1: 0.09403727461728063 >> vx1_2: 0.09594993965746354 vx1_3: -0.09267630822218338 vx1_4: >> 0.08184556774440976 vx2_0: -1.4450338119993977 vx2_1: >> 4.551633923447908 vx2_2: 5.000000000931323 vx2_3: >> 20.680542518842206 vx2_4: 30.0 >> Elapsed time is: 0.078 seconds >> >> The odd thing is that the results from the latest ActiveSetSolver, >> is not all wrong, it meets the iteration stop requirement for s >> (which the 25.1 version does not), but the solution is not optimal. >> The c vector is designed to drive vx2 to a minimum (towards zero), >> but this does not seem happen in this case. > > > This is the part I'll have to look into a bit later... > > >> I'll be happy to supply the Matlab code if you want. > > > Don't have MatLab. I prefer junit test cases where you also supply > the expected/MatLab solution and/or describes what goes wrong. > > >> Java program was run on JRE1.6.0_01. > > > I'm on Java 1.5 on a Mac. > > /Anders > > >> - Oddvar >> >> -----Original Message----- >>> From: Anders Peterson [mailto:an...@op...] >> Sent: 16. desember 2008 14:47 >> To: Anders Peterson >> Subject: Re: [ojAlgo-user] v25.1 >> >> On 26 nov 2008, at 09.06, Oddvar Grønning wrote: >> >>> >>>>> Do you have any hints/links that can put me on the right track to >>>>> pre-solve the system myself? >>> >>>> Don't feel I know the best way to fix your problem. >>> >>>> The AE matrix contains some very small elements like for instance >>>> -3.4914813388431334E-15. This is a constraint parameter?! Having >>>> parameters with very different magnitude could be a problem, but in >>>> this case the number itself is just too small. >>> >>> Ok, I see. Just so you don't think I take the numbers out of the >>> air :-): That small number is the result of a cosine call with an >>> angle close to pi/2.. The angle is actually a direction of a moving >>> object, and can take the value of any number between - pi and pi. >>> Such numbers are also common in control systems (i.e. Model >>> Predictive Control) due to rounding errors. >>> I'll try to remove such numbers before calling the QP solver. >>> >>>>> Or do you have any plans for developing a pre-solver? >>> >>>> Yes... >> >> >> I'm interested in getting feedback on what's new / in CVS. >> >> /Anders >> --------------------------------------------------------------------- >> - >> -------- >> SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, >> Nevada. >> The future of the web can't happen without you. Join us at MIX09 >> to help >> pave the way to the Next Web now. Learn more and register at >> http://ad.doubleclick.net/clk;208669438;13503038;i?http:// >> 2009.visitmix.com/ >> _______________________________________________ >> ojAlgo-user mailing list >> ojA...@li... >> https://lists.sourceforge.net/lists/listinfo/ojalgo-user >> >> >> <AllocationTest.java>------------------------------------------------ >> - >> ----------------------------- >> SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, >> Nevada. >> The future of the web can't happen without you. Join us at MIX09 >> to help >> pave the way to the Next Web now. Learn more and register at >> http://ad.doubleclick.net/clk;208669438;13503038;i?http:// >> 2009.visitmix.com/_______________________________________________ >> ojAlgo-user mailing list >> ojA...@li... >> https://lists.sourceforge.net/lists/listinfo/ojalgo-user > > > ---------------------------------------------------------------------- > -------- > _______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user > > > <AllocationTest.java>------------------------------------------------- > ----------------------------- > _______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user |
From: Oddvar G. <od...@pr...> - 2008-12-19 14:48:35
|
Changing the sign of the c vector did fix the odd results of the new solver. I had not noticed the change. Further, I found a bug in my own code (sorry!). I change the sign of the elements in c according to the sign of the corresponding vx2 variable, this is to force the variables towards zero. This causes oscillations around zero if the variable is (near) zero, vx2_0 in this case. If I detect oscillations like this I set the variable to zero and change the constraints 0.0 < variable < 0.0. The faulty detection of the oscillation was the reason the version with AS did not converge. After I fixed it, the AS results had the same accuracy as Matlabs, and about the same performance. (I got latest version from CVS today). I have done a few more test (changing tau) where the AS fails [60 10 0] and matlab does not. This can probably be fixed by the new Builder system, but I have to look into it some more later. Any hints on how to use the enforce method? - Oddvar -----Original Message----- From: Anders Peterson [mailto:an...@op...] Sent: 19. desember 2008 12:12 To: Anders Peterson Subject: Re: [ojAlgo-user] v25.1 On 18 dec 2008, at 20.15, Oddvar Grønning wrote: > Hi, > > I've been comparing the 25.1 ActiveSetSolver version with the one > currently in the CVS. Both of them are again compared to Matlabs > quadprog QP solver. > > My system is quite complex, I've reduced the example code as much > as I possibly can, but it is still quite large. You asked for test > cases, so here it goes.:-) It'll take me some time to study this. Don't think I have that time before Xmas. > I've made a SQP for nonlinear problems using the ActiveSetSolver as > QP engine. This means that I am linearizing and iterating till a > good enough solution is found. > > What I have found is that Matlab produces results very close to the > expected result, within 2 decimals. The AS 25.1 version produces > results within 1 decimal of expected results, but uses way to much > cpu-time. The latest AS version is fast, but the results are > different from Matlabs and the 25.1 version. See simulations > results below. I had set the iterations limit too tight - perhaps that was part of the problem. Also changed a couple of other things yesterday. Get the latest source from CVS. Have you tried the new builder/presolver? http://ojalgo.org/generated/org/ojalgo/optimisation/quadratic/ QuadraticSolver.Builder.html Calling "balance" and maybe "enforce" will change the quality of the solution. When you move from using the AS constructor with your BasicMatrix[] to using the QuadraticSolver.Builder you should change the sign of "C". I was able to get results, on your previous test cases, much closer to the MatLab-solution by simply "balancing" and "enforcing". But you should really try to do this earlier in your program. Once you end up with a number like -3.5E-15 you have already lost some precision. You can't just scale it back up to a larger number. > I think I need to explain the system a bit. There are 10 variables > to find optimum values for, the first 5 are low cost, they can have > any value within the constraints. The next 5 have high cost and > should be as close to zero as possible. There are nonlinear > relationships between the variables, defined as equality > constraints. 3 slack variables are used for the equality > constraints to ensure a feasible solution. This makes a total of 13 > variables.. > > The slack variables s are defined: > > s = tau - Beta(vx1)*vx2, where tau is a vector and Beta is a > matrix, we want s->0. vx1 are the first 5 low cost states and vx2 > are the high cost states. > > In the example I set tau to be [60 0 0]'. The expected result is: > > vx1: 1.5708; 0; 0; 0; 0; vx2: 0; 5; 5; 25; 25 > > In the first call to the SQP all states are zero. In the second > call the result variables from the first call are used as start > values. > > Matlab produces: > > i = 1 > > Solution found after 11 iterations > Result vx1: 1.5708; -1.0601e-005; -0.002093; 0.00073549; > -0.00031633; vx2: 0; 4.9991; 4.9947; 24.9996; 25.0065 > Elapsed time is 0.641000 seconds. > > i = 2 > > Solution found after 1 iterations > Result vx1: 1.5708; -0.0020056; -9.2987e-005; -0.0012645; > 0.0016837; vx2: -5.0796e-017; 4.9991; 4.9947; 24.9997; 25.0064 > Elapsed time is 0.015000 seconds. > > Version 25.1 of AS produces: > > Simstep 0 > Aborting, too long time consumed ( > 5 sec). numIt: 41 > Result: vx1_0: 1.5707672233183787 vx1_1: 1.6823620274180337E-4 > vx1_2: -0.00196511057420812 vx1_3: -0.002354032968486829 vx1_4: > 0.0015265945920139418 vx2_0: 0.029590231612839257 vx2_1: > 4.999569087984196 vx2_2: 4.990762180635852 vx2_3: 25.10133831261425 > vx2_4: 24.908290373430617 > Elapsed time is: 5.172 seconds > > Simstep 1 > Aborting, too long time consumed ( > 5 sec). numIt: 17 > Result: vx1_0: 1.5707672230998035 vx1_1: 1.6823670234216445E-4 > vx1_2: -0.001965110213385637 vx1_3: -0.0023328019515429285 vx1_4: > 0.0015265967291932642 vx2_0: 0.0290511558573982 vx2_1: > 4.999360102203392 vx2_2: 4.990900599987205 vx2_3: > 25.099688807764156 vx2_4: 24.910009190020308 > Elapsed time is: 5.015 seconds > > Latest AS produces: > > Simstep 0 > Solution found after 50 iteration(s) > Result: vx1_0: 1.5708199749750982 vx1_1: 0.0920372744518574 vx1_2: > 0.09394993946428473 vx1_3: -0.09067631072129541 vx1_4: > 0.0808235035333966 vx2_0: -1.427792446101636 vx2_1: > 4.557265828873959 vx2_2: 5.000000000931323 vx2_3: > 20.727837553658237 vx2_4: 29.939015120581345 > Elapsed time is: 1.578 seconds > > Simstep 1 > Solution found after 1 iteration(s) > Result: vx1_0: 1.5708199751971428 vx1_1: 0.09403727461728063 > vx1_2: 0.09594993965746354 vx1_3: -0.09267630822218338 vx1_4: > 0.08184556774440976 vx2_0: -1.4450338119993977 vx2_1: > 4.551633923447908 vx2_2: 5.000000000931323 vx2_3: > 20.680542518842206 vx2_4: 30.0 > Elapsed time is: 0.078 seconds > > The odd thing is that the results from the latest ActiveSetSolver, > is not all wrong, it meets the iteration stop requirement for s > (which the 25.1 version does not), but the solution is not optimal. > The c vector is designed to drive vx2 to a minimum (towards zero), > but this does not seem happen in this case. This is the part I'll have to look into a bit later... > I'll be happy to supply the Matlab code if you want. Don't have MatLab. I prefer junit test cases where you also supply the expected/MatLab solution and/or describes what goes wrong. > Java program was run on JRE1.6.0_01. I'm on Java 1.5 on a Mac. /Anders > - Oddvar > > -----Original Message----- >> From: Anders Peterson [mailto:an...@op...] > Sent: 16. desember 2008 14:47 > To: Anders Peterson > Subject: Re: [ojAlgo-user] v25.1 > > On 26 nov 2008, at 09.06, Oddvar Grønning wrote: > >> >>>> Do you have any hints/links that can put me on the right track to >>>> pre-solve the system myself? >> >>> Don't feel I know the best way to fix your problem. >> >>> The AE matrix contains some very small elements like for instance >>> -3.4914813388431334E-15. This is a constraint parameter?! Having >>> parameters with very different magnitude could be a problem, but in >>> this case the number itself is just too small. >> >> Ok, I see. Just so you don't think I take the numbers out of the >> air :-): That small number is the result of a cosine call with an >> angle close to pi/2.. The angle is actually a direction of a moving >> object, and can take the value of any number between - pi and pi. >> Such numbers are also common in control systems (i.e. Model >> Predictive Control) due to rounding errors. >> I'll try to remove such numbers before calling the QP solver. >> >>>> Or do you have any plans for developing a pre-solver? >> >>> Yes... > > > I'm interested in getting feedback on what's new / in CVS. > > /Anders > ---------------------------------------------------------------------- > -------- > SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, > Nevada. > The future of the web can't happen without you. Join us at MIX09 > to help > pave the way to the Next Web now. Learn more and register at > http://ad.doubleclick.net/clk;208669438;13503038;i?http:// > 2009.visitmix.com/ > _______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user > > > <AllocationTest.java>------------------------------------------------- > ----------------------------- > SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, > Nevada. > The future of the web can't happen without you. Join us at MIX09 > to help > pave the way to the Next Web now. Learn more and register at > http://ad.doubleclick.net/clk;208669438;13503038;i?http:// > 2009.visitmix.com/_______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user ------------------------------------------------------------------------------ _______________________________________________ ojAlgo-user mailing list ojA...@li... https://lists.sourceforge.net/lists/listinfo/ojalgo-user |
From: Anders P. <an...@op...> - 2008-12-19 11:11:45
|
On 18 dec 2008, at 20.15, Oddvar Grønning wrote: > Hi, > > I've been comparing the 25.1 ActiveSetSolver version with the one > currently in the CVS. Both of them are again compared to Matlabs > quadprog QP solver. > > My system is quite complex, I've reduced the example code as much > as I possibly can, but it is still quite large. You asked for test > cases, so here it goes.:-) It'll take me some time to study this. Don't think I have that time before Xmas. > I've made a SQP for nonlinear problems using the ActiveSetSolver as > QP engine. This means that I am linearizing and iterating till a > good enough solution is found. > > What I have found is that Matlab produces results very close to the > expected result, within 2 decimals. The AS 25.1 version produces > results within 1 decimal of expected results, but uses way to much > cpu-time. The latest AS version is fast, but the results are > different from Matlabs and the 25.1 version. See simulations > results below. I had set the iterations limit too tight - perhaps that was part of the problem. Also changed a couple of other things yesterday. Get the latest source from CVS. Have you tried the new builder/presolver? http://ojalgo.org/generated/org/ojalgo/optimisation/quadratic/ QuadraticSolver.Builder.html Calling "balance" and maybe "enforce" will change the quality of the solution. When you move from using the AS constructor with your BasicMatrix[] to using the QuadraticSolver.Builder you should change the sign of "C". I was able to get results, on your previous test cases, much closer to the MatLab-solution by simply "balancing" and "enforcing". But you should really try to do this earlier in your program. Once you end up with a number like -3.5E-15 you have already lost some precision. You can't just scale it back up to a larger number. > I think I need to explain the system a bit. There are 10 variables > to find optimum values for, the first 5 are low cost, they can have > any value within the constraints. The next 5 have high cost and > should be as close to zero as possible. There are nonlinear > relationships between the variables, defined as equality > constraints. 3 slack variables are used for the equality > constraints to ensure a feasible solution. This makes a total of 13 > variables.. > > The slack variables s are defined: > > s = tau - Beta(vx1)*vx2, where tau is a vector and Beta is a > matrix, we want s->0. vx1 are the first 5 low cost states and vx2 > are the high cost states. > > In the example I set tau to be [60 0 0]'. The expected result is: > > vx1: 1.5708; 0; 0; 0; 0; vx2: 0; 5; 5; 25; 25 > > In the first call to the SQP all states are zero. In the second > call the result variables from the first call are used as start > values. > > Matlab produces: > > i = 1 > > Solution found after 11 iterations > Result vx1: 1.5708; -1.0601e-005; -0.002093; 0.00073549; > -0.00031633; vx2: 0; 4.9991; 4.9947; 24.9996; 25.0065 > Elapsed time is 0.641000 seconds. > > i = 2 > > Solution found after 1 iterations > Result vx1: 1.5708; -0.0020056; -9.2987e-005; -0.0012645; > 0.0016837; vx2: -5.0796e-017; 4.9991; 4.9947; 24.9997; 25.0064 > Elapsed time is 0.015000 seconds. > > Version 25.1 of AS produces: > > Simstep 0 > Aborting, too long time consumed ( > 5 sec). numIt: 41 > Result: vx1_0: 1.5707672233183787 vx1_1: 1.6823620274180337E-4 > vx1_2: -0.00196511057420812 vx1_3: -0.002354032968486829 vx1_4: > 0.0015265945920139418 vx2_0: 0.029590231612839257 vx2_1: > 4.999569087984196 vx2_2: 4.990762180635852 vx2_3: 25.10133831261425 > vx2_4: 24.908290373430617 > Elapsed time is: 5.172 seconds > > Simstep 1 > Aborting, too long time consumed ( > 5 sec). numIt: 17 > Result: vx1_0: 1.5707672230998035 vx1_1: 1.6823670234216445E-4 > vx1_2: -0.001965110213385637 vx1_3: -0.0023328019515429285 vx1_4: > 0.0015265967291932642 vx2_0: 0.0290511558573982 vx2_1: > 4.999360102203392 vx2_2: 4.990900599987205 vx2_3: > 25.099688807764156 vx2_4: 24.910009190020308 > Elapsed time is: 5.015 seconds > > Latest AS produces: > > Simstep 0 > Solution found after 50 iteration(s) > Result: vx1_0: 1.5708199749750982 vx1_1: 0.0920372744518574 vx1_2: > 0.09394993946428473 vx1_3: -0.09067631072129541 vx1_4: > 0.0808235035333966 vx2_0: -1.427792446101636 vx2_1: > 4.557265828873959 vx2_2: 5.000000000931323 vx2_3: > 20.727837553658237 vx2_4: 29.939015120581345 > Elapsed time is: 1.578 seconds > > Simstep 1 > Solution found after 1 iteration(s) > Result: vx1_0: 1.5708199751971428 vx1_1: 0.09403727461728063 > vx1_2: 0.09594993965746354 vx1_3: -0.09267630822218338 vx1_4: > 0.08184556774440976 vx2_0: -1.4450338119993977 vx2_1: > 4.551633923447908 vx2_2: 5.000000000931323 vx2_3: > 20.680542518842206 vx2_4: 30.0 > Elapsed time is: 0.078 seconds > > The odd thing is that the results from the latest ActiveSetSolver, > is not all wrong, it meets the iteration stop requirement for s > (which the 25.1 version does not), but the solution is not optimal. > The c vector is designed to drive vx2 to a minimum (towards zero), > but this does not seem happen in this case. This is the part I'll have to look into a bit later... > I'll be happy to supply the Matlab code if you want. Don't have MatLab. I prefer junit test cases where you also supply the expected/MatLab solution and/or describes what goes wrong. > Java program was run on JRE1.6.0_01. I'm on Java 1.5 on a Mac. /Anders > - Oddvar > > -----Original Message----- >> From: Anders Peterson [mailto:an...@op...] > Sent: 16. desember 2008 14:47 > To: Anders Peterson > Subject: Re: [ojAlgo-user] v25.1 > > On 26 nov 2008, at 09.06, Oddvar Grønning wrote: > >> >>>> Do you have any hints/links that can put me on the right track to >>>> pre-solve the system myself? >> >>> Don't feel I know the best way to fix your problem. >> >>> The AE matrix contains some very small elements like for instance >>> -3.4914813388431334E-15. This is a constraint parameter?! Having >>> parameters with very different magnitude could be a problem, but in >>> this case the number itself is just too small. >> >> Ok, I see. Just so you don't think I take the numbers out of the >> air :-): That small number is the result of a cosine call with an >> angle close to pi/2.. The angle is actually a direction of a moving >> object, and can take the value of any number between - pi and pi. >> Such numbers are also common in control systems (i.e. Model >> Predictive Control) due to rounding errors. >> I'll try to remove such numbers before calling the QP solver. >> >>>> Or do you have any plans for developing a pre-solver? >> >>> Yes... > > > I'm interested in getting feedback on what's new / in CVS. > > /Anders > ---------------------------------------------------------------------- > -------- > SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, > Nevada. > The future of the web can't happen without you. Join us at MIX09 > to help > pave the way to the Next Web now. Learn more and register at > http://ad.doubleclick.net/clk;208669438;13503038;i?http:// > 2009.visitmix.com/ > _______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user > > > <AllocationTest.java>------------------------------------------------- > ----------------------------- > SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, > Nevada. > The future of the web can't happen without you. Join us at MIX09 > to help > pave the way to the Next Web now. Learn more and register at > http://ad.doubleclick.net/clk;208669438;13503038;i?http:// > 2009.visitmix.com/_______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user |
From: Oddvar G. <od...@pr...> - 2008-12-18 19:16:30
|
Hi, I've been comparing the 25.1 ActiveSetSolver version with the one currently in the CVS. Both of them are again compared to Matlabs quadprog QP solver. My system is quite complex, I've reduced the example code as much as I possibly can, but it is still quite large. You asked for test cases, so here it goes.:-) I've made a SQP for nonlinear problems using the ActiveSetSolver as QP engine. This means that I am linearizing and iterating till a good enough solution is found. What I have found is that Matlab produces results very close to the expected result, within 2 decimals. The AS 25.1 version produces results within 1 decimal of expected results, but uses way to much cpu-time. The latest AS version is fast, but the results are different from Matlabs and the 25.1 version. See simulations results below. I think I need to explain the system a bit. There are 10 variables to find optimum values for, the first 5 are low cost, they can have any value within the constraints. The next 5 have high cost and should be as close to zero as possible. There are nonlinear relationships between the variables, defined as equality constraints. 3 slack variables are used for the equality constraints to ensure a feasible solution. This makes a total of 13 variables. The slack variables s are defined: s = tau - Beta(vx1)*vx2, where tau is a vector and Beta is a matrix, we want s->0. vx1 are the first 5 low cost states and vx2 are the high cost states. In the example I set tau to be [60 0 0]'. The expected result is: vx1: 1.5708; 0; 0; 0; 0; vx2: 0; 5; 5; 25; 25 In the first call to the SQP all states are zero. In the second call the result variables from the first call are used as start values. Matlab produces: i = 1 Solution found after 11 iterations Result vx1: 1.5708; -1.0601e-005; -0.002093; 0.00073549; -0.00031633; vx2: 0; 4.9991; 4.9947; 24.9996; 25.0065 Elapsed time is 0.641000 seconds. i = 2 Solution found after 1 iterations Result vx1: 1.5708; -0.0020056; -9.2987e-005; -0.0012645; 0.0016837; vx2: -5.0796e-017; 4.9991; 4.9947; 24.9997; 25.0064 Elapsed time is 0.015000 seconds. Version 25.1 of AS produces: Simstep 0 Aborting, too long time consumed ( > 5 sec). numIt: 41 Result: vx1_0: 1.5707672233183787 vx1_1: 1.6823620274180337E-4 vx1_2: -0.00196511057420812 vx1_3: -0.002354032968486829 vx1_4: 0.0015265945920139418 vx2_0: 0.029590231612839257 vx2_1: 4.999569087984196 vx2_2: 4.990762180635852 vx2_3: 25.10133831261425 vx2_4: 24.908290373430617 Elapsed time is: 5.172 seconds Simstep 1 Aborting, too long time consumed ( > 5 sec). numIt: 17 Result: vx1_0: 1.5707672230998035 vx1_1: 1.6823670234216445E-4 vx1_2: -0.001965110213385637 vx1_3: -0.0023328019515429285 vx1_4: 0.0015265967291932642 vx2_0: 0.0290511558573982 vx2_1: 4.999360102203392 vx2_2: 4.990900599987205 vx2_3: 25.099688807764156 vx2_4: 24.910009190020308 Elapsed time is: 5.015 seconds Latest AS produces: Simstep 0 Solution found after 50 iteration(s) Result: vx1_0: 1.5708199749750982 vx1_1: 0.0920372744518574 vx1_2: 0.09394993946428473 vx1_3: -0.09067631072129541 vx1_4: 0.0808235035333966 vx2_0: -1.427792446101636 vx2_1: 4.557265828873959 vx2_2: 5.000000000931323 vx2_3: 20.727837553658237 vx2_4: 29.939015120581345 Elapsed time is: 1.578 seconds Simstep 1 Solution found after 1 iteration(s) Result: vx1_0: 1.5708199751971428 vx1_1: 0.09403727461728063 vx1_2: 0.09594993965746354 vx1_3: -0.09267630822218338 vx1_4: 0.08184556774440976 vx2_0: -1.4450338119993977 vx2_1: 4.551633923447908 vx2_2: 5.000000000931323 vx2_3: 20.680542518842206 vx2_4: 30.0 Elapsed time is: 0.078 seconds The odd thing is that the results from the latest ActiveSetSolver, is not all wrong, it meets the iteration stop requirement for s (which the 25.1 version does not), but the solution is not optimal. The c vector is designed to drive vx2 to a minimum (towards zero), but this does not seem happen in this case. I'll be happy to supply the Matlab code if you want. Java program was run on JRE1.6.0_01. - Oddvar -----Original Message----- From: Anders Peterson [mailto:an...@op...] Sent: 16. desember 2008 14:47 To: Anders Peterson Subject: Re: [ojAlgo-user] v25.1 On 26 nov 2008, at 09.06, Oddvar Grønning wrote: > >>> Do you have any hints/links that can put me on the right track to >>> pre-solve the system myself? > >> Don't feel I know the best way to fix your problem. > >> The AE matrix contains some very small elements like for instance >> -3.4914813388431334E-15. This is a constraint parameter?! Having >> parameters with very different magnitude could be a problem, but in >> this case the number itself is just too small. > > Ok, I see. Just so you don't think I take the numbers out of the > air :-): That small number is the result of a cosine call with an > angle close to pi/2.. The angle is actually a direction of a moving > object, and can take the value of any number between - pi and pi. > Such numbers are also common in control systems (i.e. Model > Predictive Control) due to rounding errors. > I'll try to remove such numbers before calling the QP solver. > >>> Or do you have any plans for developing a pre-solver? > >> Yes... I'm interested in getting feedback on what's new / in CVS. /Anders ------------------------------------------------------------------------------ SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada. The future of the web can't happen without you. Join us at MIX09 to help pave the way to the Next Web now. Learn more and register at http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/ _______________________________________________ ojAlgo-user mailing list ojA...@li... https://lists.sourceforge.net/lists/listinfo/ojalgo-user |