PureBytes Links
Trading Reference Links
|
Subject:
Re: TL_Optomization Using TradeLab
Date:
Mon, 08 Jun 98 17:19:54 -0500
From:
Scientific Approaches <sci@xxxxxxxxxx>
To:
TradeLab Mail List <TradeLab@xxxxxxxxxx>
> One of my principal complaints with TradeStation is that
> optomization is cumbersome and takes far too long:
>
> - I am using a 300 MHz Pentium II and computing time to
> optomize a group of futures takes hours or even days
> depending on how many cases you want to run. Hours? Days?
> I didn't think anything took that long on a PC. - process of
> optomizing is awkward because user first has to open chart
> and then apply the system and indicate the exact optomization
> to be done on each of the parameters.
>
> Any idea of how much quicker optomizations will run using
> TradeLab?
That is highly dependent on the way user programs are written. Visual
Basic 5.0 programs can be compiled to native code (Machine Language)
using the MS Visual C++ 5.0 compiler that is included in the Visual
Basic package. They can be almost as fast as programs written in
Machine Language if properly written. No computer program can run
faster than a properly written Machine Language program.
However, Visual Basic was designed to be unusually easy to use. To
achieve that objective the developers made it extraordinarily tolerant
of mistakes and poor programming practices. A properly written VB
program can run a 1,000 times faster than one that does the same thing
that is not properly written.
Visual Basic has many speed advantages compared to Easy Language. It
isn't possible to accurately quantize the difference in a general case,
because differences are highly dependent upon the functions being
performed and the way programs are written.
Easy Language supports only a floating decimal point numeric data type.
It is known to C and C++ programmers as a "float" and to Visual Basic
programers as "Single Precision." Variables of that type are stored as
32- bit numbers (4 bytes) ranging in value from -3.402823 * 10^38 to
-1.401298 * 10 ^-45 for negative values and from 1.401298 * 10^-45 to
3.402823 * 10^38 for positive values. That provides a large number
range with six digit accuracy (plus a seventh digit that may or may not
be correct), but it is very inefficient where that accuracy and number
range isn't needed.
Easy Language floating-point numbers are stored in memory using IEEE
32-bit floating-point format. Each floating-point value consists of
three parts: the sign, the exponent, and the mantissa. The sign takes 1
bit, the exponent takes 8 bits, and the mantissa uses the remaining 23
bits plus an additional implied bit.
Consider the multiplication of -4 times 12. To do that manually, you
might write:
12
x -4
--
-48
However, if you do that in Easy Language, TradeStation will multiply:
Sign
Bit Mantissa Base Exponent
0 (0)00000000000000000001100 * 10 ^ 00000000
x 1 (0)00000000000000000000100 * 10 ^ 00000000
----------------------------------------------
Even though it only is necessary to multiply 2 by -4 and 1 by -4 to get
the answer manually, TradeStation will multiply all those mantissa
digits by each other, sum all the resulting products, and then will
unnecessarily calculate a zero exponent for the final answer. Very
little of that workload will be productive. It mostly will involve
repetitively multiplying zero by zero and summing zero results.
TradeStation will go through all that even if an Easy Language program
multiplies 1 times 1.
Visual Basic will do the same thing if you use its Single Precision data
type to multiply two small integers, but there is no need to. Unlike
Easy Language, VB has an Integer data type that has fewer numeric
digits, no sign bit, and no exponent bits. It supports signed integers,
but the sign is implied from a number range, so there is no need for a
special sign bit. There is no need for exponent digits, because there
isn't a floating decimal point. That provides is a considerable
calculation speed advantage, because the number of operations increases
rapidly with the number of digits in
multiplication. Not only that, but computer CPU's can multiply integers
themselves, so there is no need to waste time calling, waiting for, and
processing return data from the math coprocessor.
The net result of all this is that VB can multiply -4 by 12 much faster
than Easy Language, but only if a VB programmer knows to use an Integer
data type . If Single Precision is used, VB will be almost as slow as
EL. The same is true of many other operations. VB programs can run
much faster than EL programs, but only if a programmer makes use of what
is available. Even where they don't, there is still some speed
advantage, but not nearly as much.
I just multiplied -4 * 12 with Singles and with Integers a million times
using a Pentium/180 to see what the speed difference is. This what I
measured:
A million multiplications using Singles took.: 0.609 seconds
A million multiplications using Integers took: 0.281 seconds
0.609 / 0.281 = 2.167
Visual Basic therefore is able to perform that operation in less than
half the time required by Easy Language.
How difficult is it to use an Integer data type in VB? Not very. You
can declare that all variables in a program are of Integer data type
with a single compiler directive at the beginning of a program or you
can individually declare a variable type for each variable, like this:
Dim NetProfit as Single
Dim NumTrades as Integer
Dim Len as Integer
"Dim" is an abbreviation of "Dimension." It tells the compiler you are
declaring the number of digits (the bit dimension) to use for a
variable.
Visual Basic not only has the advantage of shorter variables for greater
speed, it also has longer variables for greater precision. That can be
very important in long historical back-test runs where round-off errors
can cause big mistates.
VB has a Double-Precision floating-point variable type that stores
64-bit numbers (8 bytes) ranging in value from -1.79769313486232 *
10^308 to -4. 94065645841247 * 10^-324 for negative values and from
4.94065645841247 * 10^ -324 to 1.79769313486232 * 10^308 for positive
values.
There are several other data types. It has a Long Integer data type
that has a much larger number range than the short Integer type has. It
has a Currency data type useful for calculations involving money and for
other fixed-point calculations in which accuracy is particularly
important.
Currency variables are stored as 64-bit numbers (8 bytes) in a two's
complement integer format, and are scaled by 10,000 to give a
fixed-point number with 15 digits to the left of the decimal point and 4
digits to the
right. This representation provides a range of
-922,337,203,685,477.5808 to
922,337,203,685,477.5807.
There is a Double-Precision floating-point data type that is stored in
memory using IEEE 64-bit floating-point format. Each floating-point
value consists of three parts: the sign, the exponent, and the mantissa.
In a Double-Precision number, the sign takes 1 bit, the exponent takes
11 bits, and the mantissa uses the remaining 52 bits plus an additional
implied bit.
There are other data types to select from in addition to these. If none
of the standard data types is just right for what you are trying to
accomplish, you even can define your own. A knowledgeable VB programmer
can select high -precision data types where precision is important and
high speed data types where speed is important. An Easy Language
programmer is stuck with Single Precision Floating Point variables that
often are either unnecessarily slow or unnecessarily inaccurate.
One of the marvelous things about Visual Basic is that beginning
programmers don't need to know about any of this to write programs that
run faster than those written in Easy Language. Beginners can handicap
the programs they write so they are only slightly faster than Easy
Language programs by typing
:
DefSng A-Z
at the beginning. That tells the compiler "I don't want to be bothered
with selecting individual data types. I want you to define all my
numeric variables that have names beginning with any of the letters of
the alphabet between A and Z as Singles. Their programs will run faster
than Easy Language programs even with that handicapping, because the MS
Visual C++ compiler used by VB is much more sophisticated than the Easy
Language compiler. Later, when they learn about data types, they can
remove the handicap and gain both speed and precision improvements in
those places where each is most important.
> Will it be possible to start the optomization using Visual
> Basic so that the user can set up the optomization once
> and then apply it to each of the futures to be optomized?
Yes. TradeLab user programs request historic data from the server as
they need it without user intervention. They can automatically request
data and run back-tests or optimizations on lists of symbols. The lists
can be any length. They can be saved and re-used. That process can be
started by a user or programmed to occur automatically at a scheduled
time each day or each weekend.
User programs run in different memory process spaces from the TradeLab
program and from the server if WinNT is used, so programming errors or
other problems in user programs will rarely, if ever, crash TradeLab or
the server. It is possible to crash the WinNT operating system, but
that rarely happens unless someone knows how and does it on purpose.
That makes it safe to back-test and optimize TradeLab trading systems
during a trading day. Furthermore, because WinNT is a true multitasking
system, optimizations running in the background can not hog the
processor beyond their time slice and bog everything else down.
-Bob Brickey
Scientific Approaches
sci@xxxxxxxxxx
|