[ojAlgo-user] Getting started with ojAlgo
Mathematics, linear algebra and optimisation
Brought to you by:
apete
From: Alok S. <alo...@gm...> - 2009-11-02 14:22:46
|
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? 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. 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()): 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). Thanks, Alok |