Wednesday, April 18, 2012

First nasdaq stock query using scala and JASeries

The following script is a first attempt to make a stock query over nasdaq using JASeries (scala time series API).
exec java -jar jaseries.jar -nocompdaemon -usejavacp -savecompiled "$0" "$@"

import io.Source
import fr.janalyse.series._

// Get nasdaq codes
val codes = 
    .toList.tail.init //.take(10)

// Get nasdaq stocks history
val stocks =
  codes.flatMap(code =>
    try {
     Some(code -> CSV2Series.fromURL(""+code))
    } catch {
      case => 
        println("Could'nt find %s stock data".format(code))

// get close series
val closes = stocks flatMap { case (code, allSeries) => 
  allSeries.get("Close").map(_.rename(code+" Close"))

val top10incr =
    .sortBy( _.stat.linearApproximation.slope)
// print highest slope top20, but remember that all history data is taken into
// account, so the last value may not be quiter higher than the first one.
for(stock <- top10incr) {
  println("%s : %f -> %f".format(, stock.head.value, stock.last.value))

This script is the starting point to next JASeries improvements and new features.

No comments:

Post a Comment