On 7/28/07, Elmer Fittery <[EMAIL PROTECTED]> wrote:
>
> ...
> Now all I have to do is find some J code that will the tab deleated data
> file and turn it into an J array.
>
Easy enough:
NB. Read S&P500 price data from file downloaded from Yahoo Finance
3{.sp500=. <;._2 fread 'C:\Data\SP50019500103-20070727.csv'
+-----------------------------------------+-------------------------------...
|Date,Open,High,Low,Close,Volume,Adj Close|2007-07-27,1482.44,1488.53
,1462...
+-----------------------------------------+-------------------------------...
NB. Each cell is comma-delimited, so cut on that:
$sp500=. <;._1 &> ',',&.>sp500
14485 7
NB. If they were TAB-delimited, the above expression would be:
sp500=. <;._1 &> TAB,&.>sp500
NB. First three rows
3{.sp500
+----------+-------+-------+-------+-------+----------+---------+
|Date |Open |High |Low |Close |Volume |Adj Close|
+----------+-------+-------+-------+-------+----------+---------+
|2007-07-27|1482.44|1488.53|1462.04|1473.17|4784650000|1473.17 |
+----------+-------+-------+-------+-------+----------+---------+
|2007-07-26|1518.09|1518.09|1465.30|1482.66|1531970000|1482.66 |
+----------+-------+-------+-------+-------+----------+---------+
NB. Last three rows (no blank row at end).
_3{.sp500
+----------+-----+-----+-----+-----+-------+-----+
|1950-01-05|16.93|16.93|16.93|16.93|2550000|16.93|
+----------+-----+-----+-----+-----+-------+-----+
|1950-01-04|16.85|16.85|16.85|16.85|1890000|16.85|
+----------+-----+-----+-----+-----+-------+-----+
|1950-01-03|16.66|16.66|16.66|16.66|1260000|16.66|
+----------+-----+-----+-----+-----+-------+-----+
NB. But this ordering is backwards from the way we usually
NB. deal with time series, so flip data while keeping title at top:
3{.sp500=. ({.sp500),|.}.sp500
+----------+-----+-----+-----+-----+-------+---------+
|Date |Open |High |Low |Close|Volume |Adj Close|
+----------+-----+-----+-----+-----+-------+---------+
|1950-01-03|16.66|16.66|16.66|16.66|1260000|16.66 |
+----------+-----+-----+-----+-----+-------+---------+
|1950-01-04|16.85|16.85|16.85|16.85|1890000|16.85 |
+----------+-----+-----+-----+-----+-------+---------+
_3{.sp500
+----------+-------+-------+-------+-------+----------+-------+
|2007-07-25|1511.03|1524.31|1504.87|1517.91|4283200000|1517.91|
+----------+-------+-------+-------+-------+----------+-------+
|2007-07-26|1518.09|1518.09|1465.30|1482.66|1531970000|1482.66|
+----------+-------+-------+-------+-------+----------+-------+
|2007-07-27|1482.44|1488.53|1462.04|1473.17|4784650000|1473.17|
+----------+-------+-------+-------+-------+----------+-------+
--
Devon McCormick, CFA
^me^ at acm.
org is my
preferred e-mail
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm