Sunday, September 25, 2011

Timed numeric series library for Scala

The first public release of my open-source timed-series library, janalyse-series, is available. It comes with a CSV parser which guesses used CSV format.

A use case : Google stock quote operations.
#!/bin/sh
export CP=../target/scala-2.9.1.final/janalyse-series_2.9.1-0.5.1.jar
exec scala -cp $CP "$0" "$@"
!#

import fr.janalyse.series._

val allSeries = CSV2Series.fromURL("http://ichart.finance.yahoo.com/table.csv?s=GOOG")
val closeSeries = allSeries("Close")

println("GOOGLE stock summary")
println("Higher : "+closeSeries.max)
println("Lowest : "+closeSeries.min)
println("Week Trend : "+closeSeries.stat.linearApproximation.slope*1000*3600*24*7)
println("Latest : "+closeSeries.last)


Notice that the startup script example has an hardcoded janalyse-series library dependency, update if necessary.
$ ./stock.scala 
GOOGLE stock summary
Higher : (07-11-06 00:00:00 -> 741,79)
Lowest : (04-09-03 00:00:00 -> 100,01)
Week Trend : 0.9271503465158119
Latest : (11-03-25 00:00:00 -> 579,74)

No comments:

Post a Comment