Quality Money Management : Process Engineering and Best Practices for Systematic Trading and Investment

(Michael S) #1
are still better than more. Managing multiple threads can eat up a large amount of proces-
sor time and create new problems. Namely, multithreading can create conflicts between
threads that are trying to use the same resource. In order to make our multithreaded pro-
grams safe, we may have to control access to different resources or blocks of code or
objects, a process called synchronization. Incorrect synchronization of resources can cre-
ate deadlocks or race conditions. (A deadlock happens when two threads stop responding
because each is waiting for the other to finish. A race condition happens when abnormal
events or results are generated due to an unknown dependence between events in differ-
ent threads.)

22.2. Database Connections


SQL statements that trading/investment systems are most often concerned with are those
that retrieve data, although at times they also need to write, change, or delete data in a
database. SQL statements are simply groups of those words logically arranged to pull
specific data from the data source or manipulate the data in the data source. Computer
programs can send SQL messages to a database in their code, but things called stored
procedures are preferable.
Precompiled stored procedures are a faster way (executionwise) to construct logic that
would otherwise be coded in the business tier, because they are actually stored in the
database. Applications can call the stored procedures directly rather than sending multiple
SQL messages one at a time and waiting for the results.

22.3. Refactoring


Well-written, or “ well-factored, ” code is simple, easy to maintain, suitable, and has no
extraneous features. Nevertheless, later improvements will often be necessary, especially
in complex, performance-driven systems where not all the facts are well understood at
design time. Suboptimal choices are an intrinsic part of the process of engineering com-
plex designs in the real world. Refactoring may also be needed where new user interface
or reporting features are requested by the product team. Sometimes it takes five or six
tries to get a module right. Great designs evolve. Even great software and great trading/
investment systems must be continuously improved over time.
Refactoring means changing code and object organization. When changes are made,
regression tests must be used to ensure that the new code works the same way as the old.
And regression testing is performed, in part, using unit tests. Generally, software engi-
neers start with something that works and improve the low-level design. Once the riskiest
objects are built, the rest of the programming will just be a step-by-step grind through the
Software Architecture Document. Where refactoring is necessary, the development team
can augment the SAD as new and better knowledge and features are added.
To optimize code, a software engineer should follow approved policies and pro-
cedures. Generally, a programmer starts by running the program under a profiler that
monitors execution and indicates where algorithms and objects are consuming time and
memory space, called hot spots. Then the programmer focuses on those hot spots and
applies optimization techniques. After each step, the software engineer will compile,
retest, and rerun the profiler. If performance has not improved, he can back out the change
or make new changes. This process of finding and removing hot spots can continue until
performance satisfies the requirement for the performance quality attribute.^3

208 CHAPTER ◆ 2 2 Build and Document the System

Free download pdf