|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--dataInput.tsRead
class tsRead
Read a time series file. The format of the file is
date double-value
This class was written with daily financial time series in mind. It needs to be modified to handle intra-day time series or any other time series that has a time stamp as well.
The class is used by instantiating the constructor with the file name for the time series. For example:
tsRead ts = new tsRead( time_series );
The tsRead class reads the time series into a double_vec object.
Once data is read into the object (e.g., the object is constructed) the data is referenced by getting it as an array (double[]) via the getArray function.
Getting the data as an array is inefficient, since the data must be copied into the array first. This course is followed for two reasons:
The size of the input data is not known in advance, so a growable data structure, like double_vec is used.
Although the double_vec data structure works well for storing the input data, it is awkward when it comes to numeric computation, since the only way to reference elements is via the elementAt() function. Compared to the [] operator, this tends to obscure numeric algorithms making the code more difficult to understand. This is a real drawback for the wavelet algorithms, which are already complex enough.
So the input data is referenced via an array, even though we must pay the cost of copying. Although operator overloading can create its own problems, this is a case where operator overloading would be useful, since in C++ double_vec could have been used directly.
You may use this source code without limitation and without fee as long as you include:
This software was written and is copyrighted by Ian Kaplan, Bear Products International, www.bearcave.com, 2001.
This software is provided "as is", without any warrenty or claim as to its usefulness. Anyone who uses this source code uses it at their own risk. Nor is any support provided by Ian Kaplan and Bear Products International.
Please send any bug fixes or suggested source changes to:
iank@bearcave.com
Inner Class Summary | |
private interface |
tsRead.badDataError
class badData : an exception for bad data in the file. |
Field Summary | |
private boolean |
fileOpen
|
(package private) java.io.PushbackInputStream |
pushStream
|
private double_vec |
timeSeries
|
Constructor Summary | |
tsRead(java.lang.String file_name)
tsRead constructor |
Method Summary | |
double[] |
getArray()
getArray |
int |
getSize()
getSize Return the size of the double_vec. |
private boolean |
openStream(java.lang.String name)
|
private boolean |
read_date()
read_date |
private boolean |
read_double(double[] dv)
read_double |
void |
setSize(int size)
setSize |
private boolean |
skip_spaces()
skip_spaces Skip white space characters. |
private void |
time_series_read()
time_series_read |
Methods inherited from class java.lang.Object |
|
Field Detail |
java.io.PushbackInputStream pushStream
private double_vec timeSeries
private boolean fileOpen
Constructor Detail |
public tsRead(java.lang.String file_name)
tsRead constructor
The tsRead constructor is passed a file (or file name path) name. If the open succeeds the time series will be read into the object. The time series is read into a double_vec object which is returned by the getDoubleVec() function.
Method Detail |
private boolean skip_spaces()
private boolean read_date() throws tsRead.badDataError
read_date
Currently dates are skipped. The time series code assumes that dates are continuous and there are no holes in the data.
For consistency sake there is some checking done. The code assumes that dates are composed of numbers or '/' characters.
When this class is called it is assumed that the first character in the stream is a number. The function reads numbers or '/' characters until the end of line is reached or there is a space.
The format for a date is
(number)+ '/' (number)+ / (number)+
private boolean read_double(double[] dv) throws tsRead.badDataError
Read the character string for a floating point value and convert it into a double. The format for a double is
[+|-] (digit)+ '.' (digit)+
The function is passed a reference to an array of doubles. It returns dv[0] with the value (Java has not pass by reference except via objects). If the function reaches EOF, it return false, otherwise true.
private void time_series_read()
time_series_read
Read a time series file into a double_vec object
private boolean openStream(java.lang.String name)
public void setSize(int size)
Set the size of the double_vec. This function is useful if the size needs to be set to the nearest power of two less than or equal to the data size before getting the data as an array. The wavelet algorithms do no work on arrays whose length is not a power of two.
public int getSize()
public double[] getArray()
Return the data in a double[] object.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |