Re: [ojAlgo-user] Getting started with ojAlgo
Mathematics, linear algebra and optimisation
Brought to you by:
apete
From: Anders P. <an...@op...> - 2009-11-02 19:06:03
|
On 2 nov 2009, at 15.22, Alok Saldanha wrote: > I am having trouble getting started with ojAlgo. I am confused by > the class structure and am not sure how to do basic things. Are > there tutorials anywhere? None that I know of. > I would like to be able to do the following > > 1) Load historical data for two tech stocks and the nasdaq that I > have already downloaded from yahoo > 2) Calculate raw covariance matrix for the two tech stocks. > 3) Solve a MarkowitzModel using some expected excess return values > also stored on disk. > > In order to load historical data, I modified SymbolData so that > fetch could take a BufferedReader argument that I built off a file, > > public void fetch() { > BufferedReader tmpInput = myResourceLocator.getStreamReader(); > fetch(tmpInput); > } > public void fetch(BufferedReader tmpInput) { > ... existing code here... > } > > It is somewhat surprising to me that I had to modify the library in > order to load data off disk rather than over the network, but I > couldn't figure out an easier way. The code in the org.ojalgo.finance.data package is designed to load data from Yahoo or Google - that's what it does. The use case you describe never occurred to me. (I never store data in Yahoo/Google format on file.) > I have not been able to figure out how to calculate covariance; I am > able to populate a matrix with my data values as follows (nokPrices, > orclPrices and nasdaqPrices are of type List<HistoricalData>, which > I made public so I could call SymbolData.getHistoricalPrices()): What I do is call/use SymbolDataCache.getInstance().getPriceSeries(...) I'll think about making the changes you suggested. > MatrixStore<Double> a = PrimitiveDenseStore.FACTORY.makeZero > (3, > nokPrices.size()); > BasicMatrix b = new PrimitiveMatrix(a); > for (int i = 0; i < nokPrices.size(); i++) { > b.set(0, i, nokPrices.get(i).getAdjustedClose()); > b.set(1, i, orclPrices.get(i).getAdjustedClose()); > b.set(2, i, nasdaqPrices.get(i).getAdjustedClose()); > } > > However, I am not sure how to calculate the covariance, i.e. is > there a function for this in a util library, or if now how can I > copy the array, take the transpose, subtract the column/row means > and multiply the arrays (i.e. the operations necessary to calculate > covariance). Look at org.ojalgo.series.CoordinationSet, and then at org.ojalgo.random.SampleSet. Maybe there could be a util method that takes you straight from a CoordinationSet to a covariance matrix, but at this moment there is not. /Anders > Thanks, > Alok > > ------------------------------------------------------------------------------ > Come build with us! The BlackBerry(R) Developer Conference in SF, CA > is the only developer event you need to attend this year. Jumpstart > your > developing skills, take BlackBerry mobile applications to market and > stay > ahead of the curve. Join us from November 9 - 12, 2009. Register now! > http://p.sf.net/sfu/devconference_______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user |