Financial Time Series Toolbox | ![]() ![]() |
Create financial time series object from ASCII data file
Syntax
tsobj = ascii2fts(filename, descrow, colheadrow, skiprows) tsobj = ascii2fts(filename, timedata, descrow, colheadrow, skiprows)
Arguments
Description
tsobj = ascii2fts(filename, descrow, colheadrow, skiprows)
creates a financial time series object tsobj
from the ASCII file named filename
. This form of the function can only read a data file without time-of-day information and create a financial time series object without time information. If time information is present in the ASCII file, an error message appears.
The general format of the text data file is
skiprows
is specified.
'ddmmmyy'
or 'ddmmmyyyy'
'mm/dd/yy'
or 'mm/dd/yyyy'
'dd-mmm-yy'
or 'dd-mmm-yyyy'
'mmm.dd,yy'
or 'mmm.dd,yyyy'
tsobj = ascii2fts(filename, timedata, descrow, colheadrow,
skiprows)
creates a financial time series object containing time-of-day data. Set timedata
to 'T'
to create a financial time series object containing time-of-day data.
Examples
Example 1. If your data file contains no description or column header rows
you can create a financial time series object from it with the simplest form of the ascii2fts
function:
myinc = ascii2fts('my_inc.dat');
myinc =
desc: my_inc.dat
freq: Unknown (0)
'dates: (2)' 'series1: (2)' 'series2: (2)' 'series3: (2)'...
'03-Jan-1995' [ 36.7500] [ 36.9063] [ 36.6563]
'04-Jan-1995' [ 37] [ 37.2813] [ 36.6250]
Example 2: If your data file contains description and column header information with the data series immediately following the column header row
International Business Machines Corporation (IBM)
Daily prices (1/3/95 to 4/5/99)
DATE OPEN HIGH LOW CLOSE VOLUME
1/3/95 36.75 36.9063 36.6563 36.875 1167900
1/4/95 37 37.2813 36.625 37.1563 1994700 ...
you must specify the row numbers containing the description and column headers:
ibm = ascii2fts('ibm9599.dat', 1, 3);
ibm =
desc: International Business Machines Corporation (IBM)
freq: Unknown (0)
'dates: (2)' 'OPEN: (2)' 'HIGH: (2)' 'LOW: (2)' ...
'03-Jan-1995' [ 36.7500] [ 36.9063] [ 36.6563]
'04-Jan-1995' [ 37] [ 37.2813] [ 36.6250]
Example 3: If your data file contains rows between the column headers and the data series, e.g.,
Staples, Inc. (SPLS)
Daily prices
DATE OPEN HIGH LOW CLOSE VOLUME
Starting date: 04/08/1996
Ending date: 04/07/1999
4/8/96 19.50 19.75 19.25 19.375 548500
4/9/96 19.75 20.125 19.375 20 1135900 ...
you need to indicate to ascii2fts
the rows in the file that must be skipped. Assume that you have called the data file containing the Staples data above staples.dat
. The command
indicates that the fourth and fifth rows in the file should be skipped in creating the financial time series object:
spls = desc: Staples, Inc. (SPLS) freq: Unknown (0) 'dates: (2)' 'OPEN: (2)' 'HIGH: (2)' 'LOW: (2)' '08-Apr-1996' [ 19.5000] [ 19.7500] [19.2500] '09-Apr-1996' [ 19.7500] [ 20.1250] [19.3750]
Example 4. Create a financial time series object containing time-of-day information.
First create a data file with time information:
dates = ['01-Jan-2001';'01-Jan-2001'; '02-Jan-2001'; ... '02-Jan-2001'; '03-Jan-2001';'03-Jan-2001']; times = ['11:00';'12:00';'11:00';'12:00';'11:00';'12:00']; serial_dates_times = [datenum(dates), datenum(times)]; data = round(10*rand(6,2)); stat = fts2ascii('myfts_file2.txt',serial_dates_times,data, ... {'dates';'times';'Data1';'Data2'},'My FTS with Time');
Now read the data file back and create a financial time series object:
MyFts = ascii2fts('myfts_file2.txt','t',1,2,1) MyFts = desc: My FTS with Time freq: Unknown (0) 'dates: (6)' 'times: (6)' 'Data1: (6)' 'Data2: (6)' '01-Jan-2001' '11:00' [ 9] [ 4] ' " ' '12:00' [ 7] [ 9] '02-Jan-2001' '11:00' [ 2] [ 1] ' " ' '12:00' [ 4] [ 4] '03-Jan-2001' '11:00' [ 9] [ 8] ' " ' '12:00' [ 9] [ 0]
See Also
![]() | adosc | bar, barh | ![]() |