Grails Finance 0.5

This entry is part of 15 in the series Grails Finance

Birth of a simulation engine

Mmm, okay, so it’s back to the drawing board for Design Phase Deux. I want to run trading simulation sessions using different strategies. Each session will consist of different runs, where certain parameter values will be varied. Each run will have a P & L, that will be stored for later analysis. The simulation engine will generate orders, which will have different status and type.

Class diagram

I did some CRC analysis in my head and sketches on paper. So I made a preliminary draft design, which is obviously subject to change. Unfortunately, I don’t know how to draw UML diagrams in Vim. After trying out a few tools and getting increasingly annoyed I settled for Netbeans, because its diagrams seemed prettiest. Netbeans 6.5 to be exact, not the latest version, but the version I already had installed. Here is the class diagram, some of the datatypes are incorrect and while writing about the design, I realized, that I forgot a few classes 🙂

Simulation Engine

Code generation

Netbeans has the ability to generate code for you from UML, but it requires you to make a target project. Since I am not a Netbeans fan, I decided to generate the code myself. For that purpose I generated a HTML report from Netbeans. The script below parses the HTML files, calls the Grails commands to generate controllers and domain classes and then appends variable declarations to the generated domain classes. This means that manual editing is still required.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
REPORTDIR=~/NetBeansProjects/SimulationEngine/report/SimulationEngine
 
for f in `ls $REPORTDIR/*.html`
do
   str=`grep "public class" $f 2>/dev/null|
   grep -v Unnamed|
   grep "<B>"`
 
   if [ -n "$str" ] 
   then
      class=`echo $str|sed -e 's/.*<B>//g;s/<\/B>.*//g'`
      grails create-controller $class
      grails create-domain-class $class
      varname=`grep private $f|
      sed -e 's/.*html">//g;s/<\/A>//g;s/<B>//g;s/<\/B>.*$//g'`
      echo "    $varname" >> grails-app/domain/finance/${class}.groovy
   fi
done

Manual editing

The quick and dirty code generation script created code that doesn’t compile. I had to move the variable declarations to the correct place, fill in the constraints, belongsTo and hasMany values. Also it is good practice to have a toString implementation. The current stats are as follows

1
2
3
4
5
6
7
8
9
10
11
grails stats
 
    +----------------------+-------+-------+
    | Name                 | Files |  LOC  |
    +----------------------+-------+-------+
    | Controllers          |    15 |   174 | 
    | Domain Classes       |    14 |   168 | 
    | Unit Tests           |    29 |   348 | 
    +----------------------+-------+-------+
    | Totals               |    58 |   690 | 
    +----------------------+-------+-------+

690 LOC, not bad for a SHH ( Secret Home Hackathon ).

Random links of interest

And … now something really, absolutely and completely different.

  • CodingBat – webbased you can create an account here and track your progress.
  • SingPath – also webbased, track progress by signing in with your Google account.
  • Python koans – you can download the exercises with Mercurial. The exercises are failing tests, that you need to make pass.
  • Scala days 2010 videos
  • Vrapper – Eclipse vim plugin. Haven’t tried it out yet. TODO
Series Navigation
By the author of NumPy Beginner's Guide, NumPy Cookbook and Instant Pygame. If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.
Share
This entry was posted in programming and tagged , , . Bookmark the permalink.