---Hahn, Harvey wrote: > I've been honing some of my beginning J skills using downloaded stock > market data (DJIA) as a convenient "real" (and of practical interest) > array to practice with (of course, AFTER "getting it right" with small > sample arrays!). I'd like to derive some weekly figures from the daily data, > but the variability of the trading week is a "fly in the ointment", so > one can't just take every so many days of data. > > Is there any way to use a "Sunday" formula to pass against > Monday-through-Saturday data in an array (Yahoo data consists of date, > open, high, low, close, volume, adjusted close
I'm sure others who work with this sort of data all the time will have some clever ideas here but this is how I would attack the problem: Using data downloaded from here: http://finance.yahoo.com/q/hp?s=^DJI +----------+------+------+------+------+-------+---------+ |Date |Open |High |Low |Close |Volume |Adj Close| +----------+------+------+------+------+-------+---------+ |1929-12-31|241.90|249.24|241.90|248.48|2680000|248.48 | +----------+------+------+------+------+-------+---------+ |1929-12-30|238.43|242.95|235.95|241.06|4160000|241.06 | ... +----------+------+------+------+------+--------+---------+ |1929-10-02|342.57|350.19|339.45|344.50|3370000 |344.50 | +----------+------+------+------+------+--------+---------+ |1929-10-01|343.45|345.67|335.99|342.57|4530000 |342.57 | +----------+------+------+------+------+--------+---------+ load 'tables/csv dates' RAWDATA=: readcsv jpath '~home/downloads/table.csv' WKDAYS=: ;: 'Sunday Monday Tuesday Wednesday Thursday Friday Saturday' 'Hdr Data'=: split RAWDATA Dates=: getdate &> {."1 Data Hdr=: }.Hdr Data=: 0". > }."1 Data Days=: todayno Dates FirstSunday=: (todayno - weekday) {:Dates Week=: <.7%~Days-FirstSunday WeekDay=: (weekday Dates) {WKDAYS ,.&.> Dates;(>WeekDay);Week;Data ... |1929 10 15|Tuesday | 2|350.97 354.09 345.58 347.24 3110000 347.24| |1929 10 14|Monday | 2|352.69 358.2 348.94 350.97 2760000 350.97| |1929 10 11|Friday | 1|352.86 358.77 349.64 352.69 3960000 352.69| |1929 10 10|Thursday | 1|346.66 355.63 345.63 352.86 4000000 352.86| |1929 10 9|Wednesday| 1| 345 349.03 338.86 346.66 3160000 346.66| |1929 10 8|Tuesday | 1|345.72 349.67 340.86 345 3760000 345| |1929 10 7|Monday | 1|341.36 348.54 338.86 345.72 4260000 345.72| |1929 10 4|Friday | 0|329.95 333.28 320.45 325.17 5620000 325.17| |1929 10 3|Thursday | 0| 344.5 345.3 327.71 329.95 4750000 329.95| |1929 10 2|Wednesday| 0|342.57 350.19 339.45 344.5 3370000 344.5| |1929 10 1|Tuesday | 0|343.45 345.67 335.99 342.57 4530000 342.57| +----------+---------+--+-------------------------------------------+ You can then use Key (/.) on Week to group your data. (~.Week),.Week >.//. Data NB. Weekly maximums 13 241.9 249.24 241.9 248.48 4160000 248.48 12 240.96 246.35 239.13 240.96 3490000 240.96 11 253.02 253.17 245.03 249.58 5550000 249.58 10 263.46 267.56 257.41 262.2 5020000 262.2 9 254.64 261.52 250.27 260.12 4720000 260.12 8 245.74 246.06 237.41 243.44 3630000 243.44 7 248.49 250.75 243.36 248.49 3140000 248.49 6 235.13 235.13 222.5 228.73 7760000 228.73 5 269.75 269.75 255.43 257.68 7180000 257.68 4 295.18 295.18 264.97 273.51 16410000 273.51 3 326.51 333.01 322.03 326.51 12900000 326.51 2 352.69 358.2 348.94 350.97 4090000 350.97 1 352.86 358.77 349.64 352.86 4260000 352.86 0 344.5 350.19 339.45 344.5 5620000 344.5 'Week';Hdr +----+----+----+---+-----+------+---------+ |Week|Open|High|Low|Close|Volume|Adj Close| +----+----+----+---+-----+------+---------+ ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
