Introduction

This is page intended to help anyone that wants to participate in the development of jStock.

As my computer is fast enough (Athlon XP 2500 with 1 gig of RAM, I have not used a lot of time to optimise the speed and/or memory used by jStock. Earlier versions of jStock ran well on a PII with 192 MB RAM, I don't think use of resource has exploded since then. Oh, btw I use Linux only at home, but I try the applications once in a while on the W2K laptop I (have to) use at work, and it seems to work ok.

Classes in jstock (not complete yet)

UML class diagram

This class diagram is generated by the Eclipse UML plugin and may give an overview of the relationship between the classes. It is very out of date and will remain so until the free edition of Eclipse UML plugin is updated with support for Eclipse 3.0.

jStock

This is, as the name suggest, the main class. It is responsible for the most of the user interface and also have a Hashmap with stocks that is already drawn.

However when the user wants a new chart drawn, that task is left to ChartPanel.

ChartPanel

ChartPanel takes care of requesting data for the particular stock from the kind and helpful class ChartData. When the data is delivered it checks with the userPreferences and decides how the chart area should be partioned. The actual drawing of the chart is left to CandleStickPanel class.

CandleStickPanel

If this application has a workhorse this is it. Although it gets a lot more help than in earlier versions, the important parts of the application still is computed here. Based on the size of the screen the number of sticks to be drawn is found, X and Y axis is drawn, and finally the size and position of candlesticks themself are computed and drawn. And if the windows is resized it happens all over again.

Indicator Interfaces or how to write new indicators

Introduction

The whole idea behind the interfaces for the indicators was that it should be possible to write a new indicator without changing one line of the existing code (and that includes the fields in the "Options" menu where users can change indicators parameters).

The interfaces,IndicatorInterface, IndicatorParametersInterface, IndicatorValuesInterface and IndicatorLinesInterface can be found in the package com.exponto.jstock.indicators together with the indicators I have implemented. The defined methodes are fairly well (at least compared with the rest) documented in Java doc.

The interfaces allows for three types of indicators, a main indicator and "ordinary indicators either drawn together with the candlestick panel or drawn in a separate panel. Both types of ordinary indicators can either be enabled or disabled, dependant of user input. There can only be one main indicator implemented (the last one found will be used by the application) and that is the candlestick itself

To be drawn a indicator has to implement the IndicatorInterface and IndicatorParametersInterface. The other interfaces are used for additional fetures like supporting user drawn lines.

Be aware of the the candlestick panel uses a logaritmic scale, and any indicator that shall be drawn there must be "converted" to a logartmic scale as well. Look at MA.java or EMA.java for examples.

Indicator parameters

In addition to keeping the parameters used by an indicator, the indicator parameters also shall have the user interface for modifying the parameters. A 2D array of JComponents is used the transport the user interface. The array will typically contain JLabels and JTextfields, one pair for each parameter that may be modified, but the array may contain any JComponent that is suited for modifying the parameters.

New from version 0.5 is that each instance of a spesific indicator may have it's separate indicator parameters, but at the time of the release of version 0.5 this ability is only indirectly used as the user interface is not designed for this use as the user interface is only loaded from one static instance of the indicator parameters. This static instance will also be used as the default indicator when a new ticker is opened. However if the database is enabled the parameters will be stored in the database, and next time the same ticker is loaded the individual indicator parameters will be used. The reason behind this is that if there are any user drawn lines, they are specific to a given set of indicator parameters (e.g. lines drawn for RSI(14) is not applicable to RSI(21)). In version 0.5 only the default (static) parameters may be modified. A new tab in the "Notes" window will be added as soon as possible to modify the individual parameters. It will also be possible to had several inicators of the same type (e.g. both MA(9) and MA(200)).

How to use the classes the indicator receives

By far the most important class that is passed to the indicators is the LogDataSeries which contains all the daily (or weekly) data. The data is stored in a ArrayList of LogTradingData, one for each day (or week). The LogTradingData contains, among others, open, high low and closing prices and the date. LogDataSeries is a somewhat complicated class and the main reason for that is that it has the ability to set a "view" into the ArrayList. By setting a view other parts of the ArrayList is (almost) invisible. Normally a indicator would like to view the whole ArrayList so be sure to call the setCurrentPeriode() method. Without parameters this will set the view to the whole ArrayList. The hasNext() and getNext() method can be used to iterate the ArrayList in e.g. a while loop. Most indicators use the closing prices, the getClose() method in LogTradingData serves you well.

Modifying the Options menu

Introduction

The options menu was a kind of testbed for the indicator spesific menues. Each tab has its own class which is instantated by the PreferenceEditor class. The tab classes typically are named with there tab name with Menu added. Although there isn't a interface for the operations each tab class have to support, by convention several methodes are implemented by all tabs:

The UserPreferences instance is a singleton, so even if there are multiple instances of the PreferenceEditor, they all read and write to the same instanc of UserPreferences.

The Tab classes

Apart from the Indicator tab that get almost all components from the indicators themself, the tab classes defines all components that is displayed to the user except values for input field. The values are read from (and written to) the UserPreferences instance.

In addition to the public methodes mentioned above they all use the private methods (implemenatation is different from each class):

This makes adding new components to a tab fairly easy, but there is a couple of things to remember. First is that most tab classes uses a variable for the number of rows and columns. If components are added or removed they must be updated. The compoents must be defined, complete with toolTip and all in initComponents. If saving and restoring is applicable, please update save() and restore() and finally place the components in the array. Even more finally is to update the UserPreferences class with any new parameter that shall be stored in the properties file. Note that I'm considering to rewrite the UserPreferences to be more in style with the implementation used in the indicator classes. More about that later.

If a new tab is added, the PreferenceEditor has to be updated with calls to the new tab as well.

Database

Introduction

The purpose of the database is (at this moment) simply to provide persistence for a few items like placement of lines, notes and a watchlist. There is no need to use a database for that, but I used it anyway. jStock is only tested against Postgresql, but the sql used is rather simple so it is quite possible that other databases should work as well. At some point in time I may try to put Sleepycat je or hsqldb into jStock.

Tables

The following tables are used :

Database tables used by jStock
Table name Description
exchange Contains a references to stock exchanges used
tickers Contains a references to tickers viewed by the user, automatically updated
indicators Contains a references to indicators supported by the application
indicatorparameters May contain parameters for the seleceted indicators per tickerid. Default values are used if not present.
events Future extension currently not used
notes User written notes. Stored per tickerid
watchlist A simple list of tickerids that will be loaded on application startup.
lines Contains the position of user drawn lines.

Some of this tables has information that applies per tickerid like "notes". But there may exist more than one tab in the main jstock per tickerid as both daily and weekly charts are supported and more may come later on. A panelid is used to keep them apart. To enable multiple indicators of the same type a indicatorcode is used. This field has to be shared between a particular parametersetting of the indicator and e.g. the "lines" table. The hashCode of the indicatorparameter is probably a good choice.Tables like "lines" and "indicatorparameters" need the panelid and indicatorcode.

I spent some time looking for ER tool that supported reverse engineering from a Postgresql database. Postgresql_autodoc Postgresql_autodoc was the closest thing I found that work right away. It generated this page from the database.

Use of the database

The db is accessed through a jdbc driver. A generic database manager class in com.exponto.jstock.io handles the connection to the db and some other very generic stuff. All application spesific database stuff is handled by com.exponto.jstock.JstockDB.

Final remark

As I have released this application as open source, I will of course listen to feedback from users others than myself. I am open for requests and/or help with coding. Also, as this started as an attempt to learn Java, I very much would like critique and suggestions on how I could improve the way I write Java. Please mail me at jstock (at) exponto.com