This demo runs with only the Java interface to ObjectStore. It
does not run with PSE or PSE Pro.


Securities and Portfolios
=========================

This program models the trading of portfolios of securities.  It can
compute the "net asset value" of a portfolio as a function of time,
based on the changes in the prices of the securities in the portfolio.

This is just like the "cport" program, except that it uses Sets to
represent aggregation and does lookups with queries, instead of using
Dictionary classes.  See "Comparison With cport" below.

Data Model
==========

Security: Each object represents a particular security, for example,
"the common stock of General Motors."  Each security has a "ticker
symbol", which is the short character-string name by which the
security is known to traders. Each security also has a history of its
price over time, represented as a TimeSeries object. There is a
Dictionary of the Security objects in the database, keyed by the
ticker symbol. A reference to the Dictionary is kept in a root.

Portfolio: Each object represents a collection of securities owned by
somebody. A portfolio has a name (an arbitrary string). It also has
a history of what securities were bought into and sold from the
portfolio at what time, represented as a List of Trade objects. There
is a Dictionary of all the Portfolio objects in the database, keyed by
the name of the portfolio. A reference to the Dictionary is kept in a
root.

Trade: Each object represents an event in which some quantity of a
security was bought into or sold from a portfolio. A Trade has a
Security, the TradeDate specifying when it happened, and an integer
called "delta" specifying how much was bought or sold. A positive delta
means that the securities were bought.

TradeDate: Each object represents a date, expressed as year, month,
and date.

TimeSeries: Each object represents the trading history of a portfolio.
It is represented as a three-level "trie", for storage efficiency.

Input Data
==========

smallstocktab.txt: A text file representing a set of securities and
their prices over time.  Each line of the file represents one price,
and consists of a security ticker symbol, a date, and the price of the
security on that date.

smallportfoliotab.txt: A text file representing a set of portfolios
and their trades over time.  Each line of the file represents one
trade, and consists of a portfolio name, a security ticker symbol, a
date, a change in the number of shares, and the total number of shares
after that trade.  (The total number is not used by this program.)

Comparison With cport
=====================

The qport and cport programs are almost identical.  Where cport uses
COM.odi.coll.Dictionary_String, qport uses COM.odi.coll.Set.

To look up a portfolio by name, or a security by symbol, qport uses a
query.  When the database is created, indexes are added to the sets in
order to speed up the queries.  The cfpargs file, which contains the
arguments to the postprocessor, has two extra lines at the end to make
the relevant fields be indexable.

Running the Applications
========================

Before running the program, you need additional entries in your
CLASSPATH environment variable. You must already have two ObjectStore
related entries in your CLASSPATH. An entry for the "osji.zip" file,
in order to use ObjectStore, and a second entry for the tools.zip file
in order to use the class file postprocessor and other database
tools. You must add two entries to the CLASSPATH variable to build and
run the demo programs. The first entry enables ObjectStore locate
the annotated classes when the demo is run. The second entry
establishes the location of the sources being compiled. The order of
these two entries is significant. The entry that establishes the
location of the annotated classes must precede the entry that
establishes the location of the source files. This sequence ensures
that when you run the demo, ObjectStore finds the annotated class
definitions rather than the unannotated definitions.

For example, on Solaris, if you place the ObjectStore distribution into 
/opt/ODI/osji, you need the following two additional entries:

  CLASSPATH=/opt/ODI/osji/osji.zip:/opt/ODI/osji/tools.zip:
   /opt/ODI/osji/COM/odi/demo/osjcfpout:/opt/ODI/osji

On Windows, if you place the ObjectStore distribution into
c:\odi\osji, you need these entries:

  CLASSPATH=c:\odi\osji\osji.zip;c:\odi\osji\tools.zip;
   c:\odi\osji\COM\odi\demo\osjcfpout;c:\odi\osji

Compile the program: first go to the directory COM/odi/demo/qport,
and then do "javac *.java".

Before running the demo you must run the class file postprocessor to
make the classes work persistently.  You can run the postprocessor as
follows.  Be sure that the "bin" directory containing the osjcfp
executable is in your path as noted in the toplevel README.

On Windows use:

  osjcfp -dest ..\osjcfpout @cfpargs

On Unix use:

   osjcfp -dest ../osjcfpout @cfpargs

Note that the argument to -dest is the same as the directory used to
establish the location of the annotated classes in the CLASSPATH
environment variable. You would normally need to create this directory
explicitly, but it should already have been created for you as part of
the ObjectStore installation, so you do not need to do so for this
demo.

Running the osjcfp command line above results in annotated class
definitions being created in osjcfpout.  

The cfpargs file contains the -quietfield option which is used to
suppress warning messages.  Without this option, osjcfp warns that
COM.odi.demo.qport.TradeDate.nDays, COM.odi.demo.qport.Security.all,
and COM.odi.demo.qport.Portfolio.all are static fields that might refer
to persistent objects. You can safely ignore these warnings for this
demo.

The program is run as two Java applications. The Load application
reads the security and portfolio data from the two text files into an
ObjectStore database.  Here is a typical command line:

java -Dport.dbpath=/usr/fred/port.odb COM.odi.demo.qport.Load

Note that the -D option to the java command sets a system property.
The pathname of the database is /usr/fred/port.odb. Be sure to specify
an absolute pathname.

Your configuration might be set up so that the ObjectStore Server
requires a user name and password to run this program. If it is,
you can specify a user name and password on the command line with
the -D option:

java -DCOM.odi.user=your_user_name -DCOM.odi.password=your_password \
     -Dport.dbpath=/usr/fred/port.odb COM.odi.demo.qport.Load

This example assumes your current directory is COM/odi/demo/qport.  If
not, you can set the port.datadir property to the COM/odi/demo/qport
directory, or whichever directory holds the two text files.

The Top application reads objects from a database, and computes and
displays the net asset value of a portfolio over a time span. Here iss
a typical command line:

java -Dport.dbpath=/usr/fred/port.odb COM.odi.demo.qport.Top

The net asset values for each day are printed to the standard output.