/*----------------------------------------------------------------*/ /* Stock Market Analysis Using the SAS System: Technical Analysis */ /* */ /* SAS Publications order # 55217 */ /* ISBN 1-55544-222-6 */ /* Copyright 1995 by SAS Institute, Cary, NC, USA */ /*----------------------------------------------------------------*/ /* Data Sets, AMEX1, AMEXA, DJ, DJM, and GOLD */ /* AMEX1 data set, Appendix 1 */ data amex1; format day date7.; informat day date7.; input day $ close hi lo vol_adv vol_dec vol_unc up down unc new_hi new_lo; volume=vol_adv+vol_dec+vol_unc; percent=(close-lag(close))/lag(close); label close='Closing Price for Day' hi ='High Price for Day' lo ='Low Price for Day' volume='Trading Volume in Millions of Shares' percent='Percentage Change in Closing Price' vol_adv='Volume on Advancing Stocks' vol_dec='Volume on Declining Stocks' vol_unc='Volume on Unchanged Stocks' up='Number of Stocks Advancing' down='Number of Stocks Declining' unc='Number of Stocks Unchanged'; cards; 02AUG93 437.88 437.92 435.65 7.658 6.825 2.747 260 293 210 18 11 03AUG93 437.29 438.11 436.58 5.003 9.516 4.031 277 295 214 24 9 04AUG93 436.42 437.31 436.14 5.792 13.954 3.164 242 303 221 12 15 05AUG93 435.53 436.46 434.53 4.638 13.711 4.771 238 315 220 13 11 06AUG93 436.34 436.34 434.71 6.144 4.915 7.561 289 247 246 20 11 09AUG93 438.80 439.42 436.25 10.439 6.092 1.679 279 289 216 23 11 10AUG93 439.19 439.21 438.20 5.351 10.348 3.921 288 288 227 23 11 11AUG93 438.87 439.79 438.34 6.257 8.906 7.397 303 256 237 27 12 12AUG93 437.58 439.33 436.81 5.487 10.529 4.384 251 309 225 23 8 13AUG93 439.08 439.08 437.58 10.581 5.389 3.370 281 248 242 26 12 16AUG93 441.33 441.80 438.46 9.950 4.414 3.696 294 301 215 26 10 17AUG93 442.66 443.07 441.25 7.166 5.844 3.300 271 265 259 26 10 18AUG93 446.63 446.63 442.65 12.876 5.541 3.203 327 263 234 43 5 19AUG93 447.96 448.60 446.61 11.458 7.437 5.845 279 292 217 30 8 20AUG93 448.70 449.07 447.81 8.958 6.686 2.276 306 269 222 22 6 23AUG93 448.51 448.71 447.48 6.646 4.552 2.522 257 323 214 25 5 24AUG93 453.20 453.30 448.35 12.436 4.634 6.640 346 248 200 37 8 25AUG93 454.42 455.07 453.04 9.709 6.139 3.522 307 285 222 35 10 26AUG93 454.20 454.69 453.02 8.035 7.957 3.268 292 274 236 29 9 27AUG93 454.99 455.12 453.44 5.923 7.472 3.345 273 276 228 32 2 30AUG93 456.27 456.74 454.95 6.667 4.997 2.176 305 267 222 36 6 31AUG93 458.60 458.64 455.82 9.338 4.985 2.387 323 224 249 37 8 01SEP93 458.97 458.97 457.42 7.566 6.358 3.306 284 293 207 33 7 02SEP93 461.28 461.44 458.97 9.980 9.381 2.719 309 266 232 37 10 03SEP93 461.57 461.78 459.57 6.992 6.344 3.334 298 262 226 38 8 07SEP93 456.28 461.75 456.19 4.588 13.889 3.083 217 378 213 35 7 08SEP93 451.08 456.74 449.31 9.012 8.113 3.335 221 384 223 18 10 09SEP93 453.38 453.61 450.91 9.964 5.391 2.105 305 270 228 13 9 10SEP93 456.06 456.07 452.98 6.860 6.466 3.544 317 258 201 24 9 13SEP93 454.30 456.51 453.59 5.824 11.850 2.276 267 312 225 36 5 14SEP93 452.76 454.33 451.52 7.578 7.220 2.772 231 359 202 18 7 15SEP93 453.74 453.76 451.05 9.015 6.517 3.318 315 278 217 18 11 16SEP93 453.68 454.18 453.21 7.140 7.216 2.874 251 298 208 15 7 17SEP93 452.81 453.85 452.25 5.800 11.942 2.818 295 259 220 26 13 20SEP93 451.05 453.54 450.95 6.163 7.838 5.609 263 310 213 23 9 21SEP93 447.09 451.09 446.56 9.810 12.286 1.734 205 407 181 18 10 22SEP93 450.29 450.29 446.86 10.047 5.693 2.480 357 212 225 17 9 23SEP93 452.71 453.36 450.25 11.258 7.267 4.705 335 235 225 26 7 24SEP93 454.53 454.53 452.54 7.588 5.727 4.165 309 256 224 32 8 27SEP93 456.44 456.44 454.51 8.758 5.834 3.278 303 260 225 21 7 28SEP93 457.12 457.26 456.22 9.096 5.792 4.282 282 269 220 22 6 29SEP93 457.65 457.87 456.66 11.891 6.740 3.699 295 273 234 30 6 30SEP93 460.39 460.39 457.65 20.159 5.502 2.619 400 210 197 26 5 01OCT93 461.59 461.61 460.34 11.179 5.299 3.622 270 302 221 34 4 04OCT93 461.58 462.03 460.84 9.507 4.370 5.553 293 291 222 25 11 05OCT93 461.68 463.63 461.22 12.089 6.398 5.393 332 266 216 30 11 06OCT93 463.36 463.67 461.64 11.885 4.640 4.765 305 252 233 31 8 07OCT93 463.95 463.99 463.31 8.519 5.838 2.063 291 289 218 31 7 08OCT93 464.70 464.70 463.21 7.405 6.392 3.563 284 279 219 31 8 11OCT93 467.59 467.87 464.67 9.156 4.193 2.171 309 249 238 31 9 12OCT93 470.50 470.56 467.58 12.354 5.344 2.532 316 257 234 46 3 13OCT93 475.85 475.87 470.44 12.034 6.011 2.585 323 268 224 46 5 14OCT93 481.65 481.69 475.57 14.788 5.284 4.968 319 292 202 52 2 15OCT93 483.23 484.59 481.62 29.648 6.685 6.607 356 263 214 57 5 18OCT93 481.10 483.62 480.84 11.905 9.358 3.237 313 317 201 45 3 19OCT93 476.10 481.10 475.92 6.618 12.688 2.934 248 361 220 25 6 20OCT93 476.59 477.71 475.80 12.015 6.871 2.874 273 330 207 14 7 21OCT93 477.52 478.10 476.44 7.907 9.147 2.766 254 334 225 18 5 22OCT93 477.25 478.31 476.92 7.638 8.199 3.953 298 293 231 23 4 25OCT93 475.58 477.46 474.93 6.273 6.216 2.821 259 343 202 18 5 26OCT93 473.64 475.58 473.04 6.852 6.854 3.114 258 316 243 12 6 27OCT93 475.06 475.09 473.38 10.355 6.654 2.261 320 261 222 22 8 28OCT93 477.35 477.58 475.06 10.835 6.347 3.128 288 306 228 24 6 29OCT93 481.44 481.44 477.06 12.315 5.175 2.690 426 213 203 35 5 01NOV93 482.57 482.60 480.16 9.838 6.205 3.687 284 323 229 41 7 02NOV93 484.28 484.33 481.33 9.653 5.784 5.403 306 290 249 33 5 03NOV93 481.70 484.59 481.17 10.629 10.481 2.520 233 385 205 30 8 04NOV93 477.53 481.72 477.37 6.603 11.960 3.047 181 436 212 20 11 05NOV93 475.33 477.51 471.61 6.588 9.559 5.073 245 380 224 8 9 08NOV93 476.60 476.60 474.38 9.102 4.933 3.625 343 287 213 21 5 09NOV93 476.02 477.34 475.54 7.256 7.355 2.949 314 307 225 24 7 10NOV93 476.70 476.73 474.99 9.698 7.221 1.791 349 270 218 20 9 11NOV93 477.98 478.38 476.12 10.465 4.746 2.749 337 258 230 29 7 12NOV93 479.60 479.77 478.00 8.014 7.740 3.446 308 298 212 24 11 15NOV93 477.82 480.14 477.54 5.438 7.643 3.819 280 358 206 25 9 16NOV93 473.73 478.05 474.63 4.500 8.495 3.255 220 378 242 13 9 17NOV93 472.54 474.90 471.55 7.019 9.203 3.838 226 381 225 11 15 18NOV93 469.54 472.61 469.19 4.920 9.083 3.467 222 395 219 13 17 19NOV93 467.98 469.70 467.05 6.148 8.205 3.677 263 341 234 10 15 22NOV93 460.88 468.00 460.45 5.373 10.380 1.547 153 499 202 14 20 23NOV93 461.04 461.42 459.87 11.343 6.058 3.009 303 301 221 8 12 24NOV93 463.51 463.53 460.86 5.841 6.513 1.976 329 272 222 7 14 26NOV93 463.47 463.76 462.73 3.581 2.176 1.833 273 187 205 13 1 29NOV93 460.69 463.55 460.42 4.181 11.013 2.236 257 353 219 14 12 30NOV93 460.03 460.78 458.98 8.627 7.388 4.665 326 307 219 12 9 01DEC93 462.77 462.78 460.02 9.072 5.946 5.822 340 289 213 15 10 02DEC93 462.85 463.58 462.36 5.939 6.682 5.929 282 313 238 19 10 03DEC93 465.32 465.32 462.85 9.128 5.199 2.253 314 285 236 22 10 06DEC93 465.82 465.90 465.14 7.175 6.092 3.163 296 321 228 28 8 07DEC93 467.40 467.52 465.51 5.732 6.387 3.641 275 318 245 25 11 08DEC93 468.87 468.87 467.04 11.053 5.325 4.022 304 305 239 19 11 09DEC93 467.31 468.94 466.85 5.239 7.330 5.841 259 353 244 17 13 10DEC93 466.28 467.65 464.87 5.814 6.146 3.530 306 307 234 12 13 13DEC93 464.77 466.41 464.28 5.838 8.291 2.781 242 404 221 15 10 14DEC93 461.83 465.08 461.44 4.939 11.357 2.354 225 409 218 13 16 15DEC93 459.94 461.83 459.17 6.536 7.045 3.819 271 327 249 7 14 16DEC93 461.44 461.47 459.75 6.798 5.865 4.567 278 358 222 5 12 17DEC93 464.20 464.20 461.34 8.573 6.714 4.453 335 283 228 14 9 20DEC93 464.08 464.49 462.99 7.942 6.872 3.666 262 345 250 14 14 21DEC93 460.77 464.47 460.65 3.822 10.974 3.334 239 377 256 8 17 22DEC93 462.83 463.90 460.33 7.688 6.494 3.668 287 353 230 . . 23DEC93 465.32 465.32 462.83 8.536 5.205 2.919 331 279 242 9 9 27DEC93 467.16 467.19 465.32 5.051 3.775 3.144 290 300 234 14 14 28DEC93 470.00 470.00 467.13 7.110 5.748 3.592 328 308 223 16 9 29DEC93 472.16 472.16 469.40 9.567 3.961 3.562 368 261 242 20 6 30DEC93 472.55 472.55 471.50 7.568 5.937 3.355 333 306 246 18 11 31DEC93 477.15 477.34 472.22 10.314 4.247 3.569 427 231 222 19 10 03JAN94 477.24 477.36 475.68 8.450 7.483 1.607 338 321 180 14 3 04JAN94 477.36 477.97 476.47 8.450 7.483 3.337 358 267 213 21 6 05JAN94 478.79 478.82 477.31 12.346 6.322 2.342 336 271 216 16 4 06JAN94 479.00 479.44 477.63 12.326 6.305 3.859 348 282 211 23 2 07JAN94 479.49 479.77 478.18 11.197 5.935 4.338 321 253 246 17 3 10JAN94 478.78 479.98 477.76 8.729 5.999 4.742 318 302 221 20 5 11JAN94 479.37 479.89 478.43 8.376 6.966 3.668 296 316 243 21 1 12JAN94 479.87 479.87 478.34 6.666 6.521 3.293 304 274 245 23 5 13JAN94 480.06 480.24 478.82 7.990 6.894 2.576 310 291 228 22 1 14JAN94 480.88 481.17 480.06 8.487 6.909 3.814 352 247 232 26 4 17JAN94 481.78 481.79 480.47 7.984 4.920 2.625 303 296 214 29 3 18JAN94 481.94 482.40 481.16 8.445 6.263 4.792 279 322 219 21 2 19JAN94 483.28 483.80 481.71 8.555 6.306 3.539 287 327 222 21 6 20JAN94 484.81 484.21 483.19 7.943 8.026 2.911 317 276 235 15 5 21JAN94 484.74 484.95 483.58 9.128 7.515 3.597 347 289 215 29 4 24JAN94 483.37 484.74 482.96 7.144 6.222 4.704 285 334 238 24 4 25JAN94 480.59 483.55 480.18 6.647 7.964 3.249 247 373 213 16 4 26JAN94 481.74 481.78 479.81 7.658 6.286 3.596 313 288 236 17 4 27JAN94 481.86 482.14 481.00 8.882 6.965 3.273 319 282 237 21 4 28JAN94 483.22 483.29 481.59 11.138 4.858 5.644 355 280 211 26 3 31JAN94 485.68 485.91 483.16 14.739 5.648 2.833 388 254 238 41 5 01FEB94 485.99 486.32 485.19 11.007 9.991 3.532 272 342 240 31 5 02FEB94 487.89 488.02 485.85 14.199 6.929 3.202 361 261 210 25 7 03FEB94 487.18 487.97 486.11 8.634 7.093 4.813 289 336 226 27 2 04FEB94 478.29 488.00 477.52 4.691 17.738 1.381 154 524 174 20 8 07FEB94 476.84 478.29 474.42 7.724 8.172 3.304 250 386 204 7 13 08FEB94 477.68 477.95 476.53 7.562 7.649 2.899 323 298 214 15 13 09FEB94 480.59 480.75 477.68 14.079 6.540 2.361 364 267 204 19 8 10FEB94 479.13 481.62 477.47 6.668 9.125 6.687 278 318 229 14 9 11FEB94 477.23 479.16 476.16 4.707 5.222 2.181 220 320 230 5 6 14FEB94 474.91 477.27 474.60 10.506 9.018 1.566 285 353 204 16 6 15FEB94 474.84 475.02 474.13 8.418 9.072 2.500 297 307 216 25 12 16FEB94 475.32 475.73 474.34 9.729 5.688 4.313 317 294 228 20 6 17FEB94 474.46 476.48 473.89 5.958 8.574 4.668 310 314 228 25 5 18FEB94 470.95 475.01 470.46 4.518 10.437 2.435 239 369 222 12 11 22FEB94 472.38 472.41 470.63 7.479 7.621 2.680 271 333 227 10 5 23FEB94 471.74 472.68 471.10 5.502 7.692 3.706 239 343 253 14 9 24FEB94 465.58 471.74 465.25 4.230 11.294 2.816 154 470 208 11 12 25FEB94 467.45 467.47 465.47 8.042 4.649 3.359 281 294 241 10 13 28FEB94 471.34 471.39 467.45 11.261 4.118 3.021 386 233 219 19 8 01MAR94 469.96 471.66 467.93 6.922 7.621 2.827 229 378 227 11 16 02MAR94 466.32 469.96 463.07 13.815 9.333 1.932 186 451 205 6 23 03MAR94 465.65 466.64 465.20 12.092 6.352 2.352 268 315 217 14 13 04MAR94 466.48 466.55 464.91 6.379 8.523 4.118 311 293 226 12 18 07MAR94 469.06 469.34 466.48 7.856 4.251 4.673 345 284 219 14 11 08MAR94 467.68 469.32 467.43 8.438 7.552 3.260 265 346 215 11 12 09MAR94 466.79 468.12 465.77 10.933 8.263 4.144 272 315 249 7 16 10MAR94 464.78 466.99 464.60 8.226 7.371 2.903 265 341 214 11 14 11MAR94 465.98 466.05 463.92 8.814 5.040 2.676 306 312 221 10 18 14MAR94 468.06 468.09 465.97 8.845 3.673 3.512 336 271 247 12 12 15MAR94 468.13 468.60 466.86 6.400 6.762 2.768 306 283 241 19 23 16MAR94 469.82 469.84 467.94 9.041 5.204 3.185 311 274 256 19 14 17MAR94 470.63 470.98 469.14 11.599 6.292 3.749 301 302 239 17 9 18MAR94 472.96 472.98 470.10 12.830 4.558 5.852 344 277 211 25 13 21MAR94 470.77 472.97 469.74 8.566 6.050 4.244 232 380 229 19 13 22MAR94 471.73 471.86 470.63 9.738 8.005 2.937 293 323 229 14 19 23MAR94 473.38 473.46 471.35 10.531 7.976 1.833 319 297 240 15 11 24MAR94 469.66 473.41 468.68 4.733 10.096 3.591 178 460 213 9 16 25MAR94 468.43 470.44 468.20 7.502 5.404 2.794 262 333 229 11 13 28MAR94 462.21 468.51 461.82 3.712 13.823 2.075 208 447 188 12 18 29MAR94 454.43 462.21 454.15 1.872 13.440 1.998 137 522 194 5 18 30MAR94 445.54 454.43 445.31 2.168 15.629 2.953 106 536 202 0 37 31MAR94 443.11 445.65 437.43 10.739 10.779 3.932 212 454 197 3 59 04APR94 434.13 443.11 433.51 2.855 15.307 2.688 128 550 168 4 81 05APR94 440.99 441.04 434.13 13.195 3.242 2.253 487 175 158 2 18 06APR94 440.98 442.50 439.48 6.440 8.061 2.329 321 269 226 4 23 07APR94 441.76 441.80 440.17 7.424 6.182 2.684 324 276 197 5 19 08APR94 441.21 443.02 440.31 5.157 6.005 3.188 265 326 237 8 16 11APR94 440.66 441.56 440.55 5.388 6.956 1.916 264 325 222 5 19 12APR94 439.69 441.29 438.24 4.805 8.238 3.527 253 333 235 7 31 13APR94 437.95 440.32 436.91 4.010 9.887 1.293 193 405 212 4 27 14APR94 437.32 438.13 436.56 5.585 5.758 3.487 239 310 247 5 29 15APR94 438.29 438.35 437.04 6.490 4.983 2.627 277 299 239 5 23 18APR94 434.00 438.92 433.54 3.221 8.120 2.589 179 426 231 8 27 19APR94 431.10 433.99 429.78 4.086 10.249 2.935 203 414 208 3 50 20APR94 427.60 432.44 427.00 3.811 9.681 2.168 202 395 224 2 31 21APR94 431.13 431.23 427.54 7.693 3.268 2.929 364 242 202 4 19 22APR94 433.31 433.36 431.13 9.719 3.958 2.563 307 268 241 6 19 25APR94 435.97 435.99 433.26 5.445 4.240 2.165 349 235 223 6 12 26APR94 438.20 438.20 435.97 9.227 4.518 2.395 341 233 224 10 5 28APR94 438.92 439.47 438.18 12.166 4.623 3.281 306 292 230 2 1 29APR94 439.91 439.92 437.92 6.099 4.478 2.703 323 234 235 1 0 02MAY94 440.20 440.60 438.54 6.483 6.594 2.873 328 252 210 7 9 03MAY94 442.39 442.40 440.11 8.898 5.187 3.625 312 307 208 13 12 04MAY94 443.79 443.79 442.05 7.537 6.226 1.527 267 305 233 9 10 05MAY94 441.70 443.84 441.57 3.709 7.084 3.337 268 307 225 9 4 06MAY94 439.73 441.72 438.14 6.331 6.217 5.352 227 389 201 7 13 09MAY94 435.42 439.73 435.01 3.338 7.887 2.935 185 392 218 3 19 10MAY94 435.19 435.69 433.53 6.178 5.634 2.278 307 281 228 7 19 11MAY94 433.17 435.80 432.72 4.736 8.068 5.526 243 345 211 8 22 12MAY94 433.35 433.93 432.90 6.234 6.765 2.451 291 284 229 9 16 13MAY94 432.57 433.37 432.04 4.681 6.147 3.062 268 305 228 7 17 16MAY94 431.68 433.24 431.44 4.913 5.784 2.193 262 351 194 12 25 17MAY94 431.98 431.99 430.37 6.588 7.160 2.102 275 321 229 6 35 18MAY94 434.90 434.92 431.91 9.799 3.017 2.624 363 249 203 13 18 19MAY94 437.04 437.04 434.38 9.761 3.107 3.342 342 254 233 14 15 20MAY94 438.20 438.20 436.95 7.490 4.895 3.145 311 286 228 12 8 23MAY94 437.64 438.34 437.30 4.447 5.388 2.775 280 334 216 10 12 24MAY94 439.18 439.32 437.64 8.225 4.250 1.955 304 266 226 7 7 25MAY94 439.25 439.25 437.61 11.593 6.098 2.429 250 302 228 10 9 26MAY94 439.62 439.67 438.66 4.540 4.879 14.361 299 267 229 8 13 27MAY94 440.94 440.98 439.00 4.448 6.066 1.876 295 275 217 6 8 ; /* AMEXA data set, p.44 */ data amexa; format day date7.; informat day date7.; input day $ close @@; label close='Closing Price for Day'; cards; 12JUL93 438.10 13JUL93 439.11 14JUL93 438.67 15JUL93 437.98 16JUL93 436.47 19JUL93 433.48 20JUL93 433.79 21JUL93 433.31 22JUL93 431.36 23JUL93 432.05 26JUL93 433.76 27JUL93 434.77 28JUL93 434.78 29JUL93 436.59 30JUL93 437.00 ; /* DJ data set, daily data */ data dj; format day date7.; informat day date7.; input day $ dj_close dj_hi dj_lo vol_adv vol_dec vol_unc up down unc; label dj_close='DJIA Closing Price for Day' dj_hi ='DJIA High Price for Day' dj_lo ='DJIA Low Price for Day' vol_adv='NYSE Volume on Advancing Stocks' vol_dec='NYSE Volume on Declining Stocks' vol_unc='NYSE Volume on Unchanged Stocks' up='NYSE Number of Stocks Advancing' down='NYSE Number of Stocks Declining' unc='NYSE Number of Stocks Unchanged'; /* Volume in Millions */ cards; 03JAN94 3756.60 3790.70 3715.24 115.236 133.587 30.427 902 1318 513 04JAN94 3783.90 3798.25 3718.89 115.236 133.587 77.777 1204 918 614 05JAN94 3798.82 3821.33 3750.41 201.075 144.159 54.796 1196 999 557 06JAN94 3803.88 3843.84 3771.52 158.259 167.197 42.424 1076 1054 595 07JAN94 3820.77 3842.15 3778.83 192.431 100.275 32.214 1280 855 591 10JAN94 3865.51 3874.52 3804.72 207.758 84.105 27.627 1326 852 563 11JAN94 3850.31 3885.21 3823.02 131.075 135.923 38.492 1004 1145 603 12JAN94 3848.63 3876.49 3809.79 137.435 132.201 41.054 1146 956 647 13JAN94 3842.43 3864.67 3808.38 110.482 129.678 37.810 936 1142 660 14JAN94 3867.20 3891.96 3830.62 187.799 84.833 32.278 1245 871 639 17JAN94 3870.29 3896.75 3833.71 104.888 95.109 33.983 994 1071 641 18JAN94 3870.29 3905.19 3840.75 162.593 115.250 31.887 1210 892 629 19JAN94 3884.37 3909.97 3839.34 137.155 139.964 34.251 1144 983 606 20JAN94 3891.96 3915.60 3857.91 140.438 128.206 41.806 1110 960 657 21JAN94 3914.48 3933.33 3875.36 141.996 149.998 54.236 980 1086 690 24JAN94 3912.79 3947.68 3882.11 107.272 157.694 33.024 934 1206 619 25JAN94 3895.34 3937.55 3863.82 108.250 174.008 43.862 883 1202 665 26JAN94 3908.00 3934.74 3863.82 154.858 116.229 33.573 1172 888 689 27JAN94 3926.30 3951.34 3876.77 209.789 85.167 51.544 1329 784 635 28JAN94 3945.43 3971.89 3919.54 182.272 89.459 41.409 1324 770 657 31JAN94 3978.36 4002.84 3937.27 211.084 81.408 30.378 1396 733 636 01FEB94 3964.01 3998.06 3938.12 137.674 145.197 39.639 961 1148 641 02FEB94 3975.54 3997.78 3937.27 179.909 108.668 40.383 1279 851 618 03FEB94 3967.66 3995.52 3932.77 142.962 138.641 36.747 918 1190 650 04FEB94 3871.42 3979.76 3857.63 21.625 339.591 17.164 314 2037 402 07FEB94 3906.32 3923.48 3840.75 173.252 131.276 43.742 1044 1178 526 08FEB94 3906.03 3951.34 3873.67 139.623 131.784 46.773 1172 962 603 09FEB94 3931.92 3956.97 3887.74 168.446 117.907 46.317 1289 850 598 10FEB94 3895.34 3953.59 3882.96 92.537 197.735 36.978 811 1311 617 11FEB94 3894.78 3920.95 3855.94 86.421 102.902 24.417 801 1214 674 14FEB94 3904.06 3935.86 3873.67 116.598 113.538 33.054 1134 1029 601 15FEB94 3928.27 3950.50 3891.40 173.698 87.400 45.692 1198 882 679 16FEB94 3937.27 3964.85 3906.32 132.871 129.054 33.525 1183 965 620 17FEB94 3922.64 3975.82 3894.21 118.128 182.635 39.267 882 1251 638 18FEB94 3887.46 3931.92 3869.73 79.210 172.165 41.835 706 1411 635 22FEB94 3911.66 3928.83 3873.39 160.245 81.572 29.083 1139 1003 626 23FEB94 3891.68 3931.36 3872.83 141.175 128.747 39.988 948 1177 645 24FEB94 3839.90 3895.62 3823.86 62.502 256.166 24.272 442 1795 545 25FEB94 3838.78 3868.89 3811.76 147.335 91.364 34.981 1169 963 626 28FEB94 3832.02 3874.52 3817.95 154.436 84.366 28.808 1457 727 574 01MAR94 3809.23 3848.34 3772.93 75.317 187.671 41.462 716 1449 609 02MAR94 3831.74 3845.25 3741.69 148.468 172.809 39.853 788 1404 578 03MAR94 3824.42 3862.13 3784.74 120.258 133.700 38.002 950 1190 612 04MAR94 3832.30 3868.04 3800.50 178.986 89.943 42.921 1279 829 652 07MAR94 3856.22 3882.40 3824.71 165.090 86.016 34.484 1443 762 572 08MAR94 3851.72 3881.55 3822.45 114.941 149.742 33.437 944 1174 657 09MAR94 3853.41 3874.52 3817.95 151.707 127.404 30.699 1034 1098 651 10MAR94 3830.62 3865.51 3801.63 122.934 178.069 68.367 687 1489 607 11MAR94 3862.70 3872.83 3806.69 173.173 97.274 32.803 1137 962 671 14MAR94 3862.98 3894.21 3835.96 134.449 85.241 40.470 1159 949 697 15MAR94 3849.59 3880.40 3826.85 140.081 124.592 64.587 1138 1000 656 16MAR94 3848.15 3879.53 3819.94 195.983 74.507 36.330 1736 1382 1709 17MAR94 3865.14 3891.34 3821.66 164.043 108.120 31.787 1149 1015 613 18MAR94 3895.65 3911.78 3838.65 192.900 203.139 66.201 1071 1091 623 21MAR94 3864.85 3898.25 3838.65 68.308 148.285 30.797 627 1580 576 22MAR94 3862.55 3896.23 3840.66 145.867 100.274 36.949 1189 925 655 23MAR94 3869.46 3901.41 3839.80 132.838 112.753 39.009 1159 945 657 24MAR94 3821.09 3865.42 3792.58 69.563 206.685 27.552 520 1739 525 25MAR94 3774.73 3845.85 3764.66 79.705 141.184 28.791 860 1198 684 28MAR94 3762.35 3793.45 3719.74 82.864 181.239 23.257 652 1567 574 29MAR94 3699.02 3771.86 3689.23 18.219 259.515 23.896 280 2034 470 30MAR94 3626.75 3718.88 3612.36 62.048 304.675 23.797 357 2041 403 31MAR94 3635.96 3673.10 3544.12 150.987 204.924 43.389 752 1532 524 04APR94 3593.35 3633.08 3520.80 45.664 280.848 17.878 376 2121 318 05APR94 3675.41 3698.15 3625.02 327.411 25.997 13.482 2152 315 352 06APR94 3679.73 3722.34 3643.16 149.689 122.702 29.609 1268 956 585 07APR94 3696.26 3712.83 3642.59 167.363 82.446 39.471 1370 761 649 08APR94 3674.26 3717.15 3644.03 75.131 157.284 31.675 800 1406 597 11APR94 3688.83 3720.66 3651.35 129.517 80.618 33.045 1168 1022 599 12APR94 3681.69 3722.14 3661.17 78.029 140.509 39.452 872 1258 653 13APR94 3661.47 3704.30 3616.85 77.497 172.937 28.996 696 1505 598 14APR94 3663.25 3693.59 3625.77 130.848 118.738 31.984 932 1224 640 15APR94 3661.47 3699.24 3631.13 140.437 130.424 38.389 1022 1098 648 18APR94 3620.42 3679.61 3593.35 74.694 176.861 19.925 625 1648 527 19APR94 3619.82 3670.39 3567.18 103.662 188.279 31.809 749 1491 564 20APR94 3598.71 3662.66 3546.65 116.608 216.862 33.080 835 1417 549 21APR94 3652.54 3673.96 3582.94 277.169 75.012 26.589 1573 704 511 22APR94 3648.68 3690.32 3621.01 145.506 125.957 24.317 1282 930 570 25APR94 3705.78 3721.25 3635.29 172.761 57.964 32.825 1552 667 573 26APR94 3699.54 3733.15 3669.79 145.615 113.995 28.510 1268 913 616 ; /* DJM data set, Appendix 2 */ data djm; format date monyy.; informat date monyy.; input date $ djiam @@; label djiam='Monthly DJIA Index Price'; /* Survey of Current Business */ cards; jan83 1064.29 feb83 1087.43 mar83 1129.58 apr83 1168.43 may83 1212.86 jun83 1221.47 jul83 1213.93 aug83 1189.21 sep83 1237.04 oct83 1252.20 nov83 1250.00 dec83 1257.64 jan84 1258.89 feb84 1164.46 mar84 1161.97 apr84 1152.71 may84 1143.42 jun84 1121.14 jul84 1113.27 aug84 1212.82 sep84 1213.51 oct84 1199.30 nov84 1211.30 dec84 1188.96 jan85 1238.16 feb85 1283.23 mar85 1268.83 apr85 1266.36 may85 1279.40 jun85 1314.00 jul85 1343.17 aug85 1326.18 sep85 1317.95 oct85 1351.58 nov85 1432.88 dec85 1517.02 jan86 1534.86 feb86 1652.73 mar86 1757.35 apr86 1807.05 may86 1801.80 jun86 1867.70 jul86 1809.92 aug86 1843.45 sep86 1813.47 oct86 1817.04 nov86 1883.65 dec86 1924.07 jan87 2065.13 feb87 2202.34 mar87 2292.61 apr87 2302.64 may87 2291.11 jun87 2384.02 jul87 2481.72 aug87 2655.01 sep87 2570.80 oct87 2224.59 nov87 1931.86 dec87 1910.07 jan88 1947.35 feb88 1980.65 mar88 2044.31 apr88 2036.13 may88 1988.91 jun88 2104.94 jul88 2104.22 aug88 2051.29 sep88 2080.06 oct88 2144.31 nov88 2099.04 dec88 2148.58 jan89 2234.68 feb89 2304.30 mar89 2283.11 apr89 2348.91 may89 2439.55 jun89 2494.90 jul89 2554.03 aug89 2691.11 sep89 2693.41 oct89 2692.01 nov89 2642.49 dec89 2728.47 jan90 2679.24 feb90 2614.18 mar90 2700.13 apr90 2708.26 may90 2793.81 jun90 2894.82 jul90 2934.23 aug90 2681.89 sep90 2550.69 oct90 2460.54 nov90 2518.56 dec90 2610.92 jan91 2587.60 feb91 2863.04 mar91 2920.11 apr91 2925.53 may91 2928.42 jun91 2968.13 jul91 2978.18 aug91 3006.08 sep91 3010.35 oct91 3019.73 nov91 2986.12 dec91 2958.64 jan92 3227.06 feb92 3257.27 mar92 3247.41 apr92 3294.08 may92 3376.78 jun92 3337.79 jul92 3329.40 aug92 3307.45 sep92 3293.92 oct92 3198.69 nov92 3238.49 dec92 3303.15 jan93 3277.71 feb93 3367.26 mar93 3440.73 apr93 3423.62 may93 3478.17 jun93 3513.81 jul93 3529.43 aug93 3597.01 sep93 3592.28 oct93 3625.80 nov93 3674.69 dec93 3743.62 jan94 3868.36 feb94 3905.61 ; /* GOLD data set, Appendix 3 */ data gold; format day date7.; informat day date7.; input day $ gold @@; label gold='COMEX Gold Spot Closing Price for Day'; cards; 03JAN94 393.70 04JAN94 394.10 05JAN94 391.10 06JAN94 389.20 07JAN94 386.40 10JAN94 385.00 11JAN94 388.00 12JAN94 386.30 13JAN94 390.00 14JAN94 389.50 17JAN94 391.60 18JAN94 393.10 19JAN94 392.30 20JAN94 387.50 21JAN94 381.40 24JAN94 381.10 25JAN94 381.40 26JAN94 384.50 27JAN94 377.40 28JAN94 376.90 31JAN94 381.60 01FEB94 384.10 02FEB94 384.70 03FEB94 387.30 04FEB94 386.60 07FEB94 378.90 08FEB94 382.30 09FEB94 384.00 10FEB94 382.00 11FEB94 380.00 14FEB94 383.90 15FEB94 383.80 16FEB94 383.60 17FEB94 382.80 18FEB94 380.30 22FEB94 378.00 23FEB94 377.70 24FEB94 376.50 25FEB94 378.60 28FEB94 381.40 01MAR94 378.30 02MAR94 377.80 03MAR94 377.30 04MAR94 377.60 07MAR94 375.90 08MAR94 376.70 09MAR94 379.20 10MAR94 387.30 11MAR94 385.30 14MAR94 386.40 15MAR94 386.90 16MAR94 384.90 17MAR94 382.40 18MAR94 387.10 21MAR94 385.80 22MAR94 389.20 23MAR94 387.00 24MAR94 391.60 25MAR94 391.00 28MAR94 388.00 29MAR94 386.00 30MAR94 386.10 31MAR94 391.80 04APR94 386.30 05APR94 384.40 06APR94 384.90 07APR94 383.90 08APR94 384.20 11APR94 377.90 12APR94 378.50 13APR94 378.20 14APR94 378.60 15APR94 377.70 18APR94 376.80 19APR94 371.50 20APR94 372.20 21APR94 373.10 22APR94 370.60 25APR94 373.40 26APR94 373.90 28APR94 375.60 29APR94 376.60 02MAY94 376.20 03MAY94 375.60 04MAY94 376.60 05MAY94 373.60 06MAY94 383.40 09MAY94 381.20 10MAY94 378.80 11MAY94 381.80 12MAY94 379.90 13MAY94 380.70 16MAY94 383.00 17MAY94 381.40 18MAY94 382.00 19MAY94 381.40 20MAY94 385.90 23MAY94 389.60 24MAY94 387.10 25MAY94 386.60 26MAY94 383.80 27MAY94 384.70 ; /* ---------------------------------------------------------- */ /* Chapter 1 */ /* Chapter 1, Example 1 */ /* The following example code appears on p.4 */ /* Use the AMEX1 data set, Appendix 1 */ /* Note: To use the AMEX1 data set submit the example */ /* code of Appendix 1, which creates the AMEX1 */ /* data set. */ proc print data=amex1(obs=5) label; var day close hi lo volume; title 'Printing the AMEX1 Data Set'; title2 'First Five Observations'; run; /* End of Example Code to Create Example 1, Chapter 1 */ /* The following example code appears on p.6 */ /* Subsetting the AMEX1 Data Set */ data amex1a; set amex1 (obs=25); close_d=dif(close); run; /* The following example code appears on p.6 */ /* Subsetting the AMEX1 Data Set */ data amex1b; set amex1 (drop=new_hi new_lo); run; /* The following example code appears on p.6 */ /* Subsetting the AMEX1 Data Set */ data amex1c; set amex1 (keep=close hi lo); run; /* The following example code appears on p.6 */ /* Concatenating Data Sets */ data amex_as; set amex_aug amex_sep; run; /* The following example code appears on p.7 */ /* Match Merging AMEX1, DJ, and GOLD Data Sets */ data close; merge amex1 dj gold; by day; run; /* The following example code appears on p.7 */ /* Using PROC SQL to subset a data set. */ proc sql; title 'Large Advancing Volume Days'; select day from amex1 where vol_adv>10; /* Chapter 1, Example 2 */ /* The following example code appears on p.8 */ /* Use the AMEX1 data set, Appendix 1 */ /* Transposing a data set. */ proc transpose data=amex1 (obs=5) out=amex_t1; var close hi lo; run; proc print data=amex_t1; title 'Printing a Transposed Data Set'; title2; run; /* End of Example Code to Create Example 2, Chapter 1 */ /* The following example code appears on p.8 */ /* Creating a SAS data view. */ /* Note: To use these statements you must specify */ /* a data set (the xx), a name for the data */ /* (the yy), and complete the INFILE, INPUT, */ /* and additional DATA step statements. */ data xx / view=yy; infile ... ; input ...; additional DATA step statements run; /* The following example code appears on p.9 */ /* Example code to produce a scatterplot. */ proc plot data=amex1 vpct=150; plot close*day; run; /* Chapter 1, Example 3 */ /* The following example code appears on p.10 */ /* Producing a customized scatterplot. */ /* Use the AMEX1 data set, Appendix 1. */ proc plot data=amex1 vpct=250; where day < '07sep93'd; plot hi * day = '+' close * day = '*' lo * day = '-' / overlay haxis = '02aug93'd to '06sep93'd by 7 vaxis = 432 to 464 by 4 href= '15aug93'd vref= 434 441; title 'AMEX Index versus Day'; title2 'High, Low, and Closing Price'; title3 'Customized and Overlaid Scatter Plot'; run; /* End of Example Code to Create Example 3, Chapter 1 */ /* The following example code appears on p.12 */ /* Example code to produce a timeplot. */ proc timeplot data=amex1; plot hi='+' close='*' lo='-' / overlay; id day; run; /* Chapter 1, Example 4 */ /* The following example code appears on p.13 */ /* Producing a customized timeplot. */ /* Use the AMEX1 data set, Appendix 1. */ proc timeplot data=amex1; where day < '04sep93'd; plot lo close hi / overlay axis=434 to 464 hiloc pos=35 ref=441 452; id day; title3 'Customized Time Plot'; run; /* End of Example Code to Create Example 4, Chapter 1 */ /* The following example code appears on p.14 */ /* Creating horizontal bar charts. */ proc chart data=amex1; hbar volume close; run; /* Chapter 1, Display 1 */ /* The following example code appears on p.15 */ /* Creating a high-resolution vertical bar chart. */ /* Use the AMEX1 data set, Appendix 1. */ data amex2; set amex1 (obs=25); day1=weekday(day); run; proc format; value wk_day 2='Mon' 3='Tues' 4='Wed' 5='Thurs' 6='Fri'; run; /* GOPTIONS statement to produce high-resolution */ /* graphs as much as possible like those in book. */ goptions reset=global gunit=pct cback=white border htitle=6 htext=3 ftext=swissb colors=(black); proc gchart data=amex2; format day1 wk_day.; vbar day1 / type=mean sumvar=volume; title 'Vertical Bar Chart'; run; quit; /* Chapter 1, Display 2 */ /* The following example code appears on p.17 */ /* Subsetting the AMEX1 data set. */ data amex2; set amex1 (obs=25); run; /* GOPTIONS statement to produce high-resolution */ /* graphs as much as possible like those in book. */ goptions reset=global gunit=pct cback=white border htitle=6 htext=3 ftext=swissb colors=(black); /* Creating a high-resolution plot. */ proc gplot data=amex2; plot close * day; symbol1 v=C h=2.5 i=join l=1 font=swissb; title 'AMEX Index Closing Price versus Day'; run; quit; /* End of Example Code to Create Display 2, Chapter 1 */ /* The following example code appears on pp.17-18 */ /* Storing GPLOT output. */ /* Point to a permanent library. */ libname glib 'pathname'; /* Using the GOUT= option to store the plot. */ proc gplot data=amex2 gout=glib.graphs; /* Naming the stored plot. */ plot close*day / name='graph1'; /* Chapter 1, Example 5 */ /* The following example code appears on p.17 */ /* Subsetting the AMEX1 data set. */ data amex2; set amex1 (obs=25); run; /* The following example code appears on p.18 */ /* Creating a data set for a high-low-close plot. */ data amex2a; set amex2; value=hi; output; value=lo; output; value=close; output; run; proc print data=amex2a (obs=6); var day value; title 'Observations from Data Set for Plotting'; run; /* End of Example Code to Create Example 5, Chapter 1 */ /* Chapter 1, Display 3 */ /* The following example code appears on p.17 */ /* Subsetting the AMEX1 data set. */ data amex2; set amex1 (obs=25); run; /* The following example code appears on p.18 */ /* Creating a data set for a high-low-close plot. */ data amex2a; set amex2; value=hi; output; value=lo; output; value=close; output; run; /* GOPTIONS statement to produce high-resolution */ /* graphs as much as possible like those in book. */ goptions reset=global gunit=pct cback=white border htitle=6 htext=3 ftext=swissb colors=(black); /* The following example code appears on p.20 */ /* Creating a high-resolution high-low-close plot. */ proc gplot data=amex2a; plot value * day / vaxis=axis1 haxis=axis2; symbol1 i=hiloc l=2 font=swissb; axis1 label=('Price') order=(434 to 464 by 5); axis2 label=('Day') order=('01aug93'd to '05sep93'd by 7); title 'AMEX Index versus Day'; title2 'High, Low, and Close'; run; quit; /* End of Example Code to Create Display 3, Chapter 1 */ /* Chapter 1, Display 4 */ /* The following example code appears on p.17 */ /* Subsetting the AMEX1 data set. */ data amex2; set amex1 (obs=25); run; /* The following example code appears on p.18 */ /* Creating a data set for a high-low-close plot. */ data amex2a; set amex2; value=hi; output; value=lo; output; value=close; output; run; /* GOPTIONS statement to produce high-resolution */ /* graphs as much as possible like those in book. */ goptions reset=global gunit=pct cback=white border htitle=6 htext=3 ftext=swissb colors=(black); /* The following example code appears on p.21 */ /* Adding another axis to a high-low-close plot. */ proc gplot data=amex2a; plot value * day / vaxis=axis1 haxis=axis2; plot2 volume * day / vaxis=axis3; symbol1 i=hiloc l=2 font=swissb; symbol2 v=none i=needle; axis1 label=('Price') order=(434 to 464 by 5) offset=(21, 0) major=(n=5 h=-2); axis2 label=('Day') order=('01aug93'd to '05sep93'd by 7); axis3 label=('Volume') order=(9 to 25 by 4) offset=(1.0, 40); title 'AMEX Index Price and Volume versus Day'; run; quit; /* End of Example Code to Create Display 4, Chapter 1 */ /* Chapter 1, Example 6 */ /* The following example code appears on p.17 */ /* Subsetting the AMEX1 data set. */ data amex2; set amex1 (obs=25); run; /* The following example code appears on p.23 */ /* Univariate analysis of data. */ proc univariate data=amex2 normal plot; var percent; title2 'AMEX Index Capital Gains'; title3; title4; run; /* End of Example Code to Create Example 6, Chapter 1 */ /* Chapter 1, Example 7 */ /* The following example code appears on p.17 */ /* Subsetting the AMEX1 data set. */ data amex2; set amex1 (obs=25); run; /* The following example code appears on p.27 */ /* Calculating and Testing Pearson Correlation Coeffients */ proc corr data=amex2 nosimple; var hi lo close volume; title2 'AMEX Index Correlation Matrix'; run; /* End of Example Code to Create Example 7, Chapter 1 */ /* The following example code appears on p.28 */ /* General form of a %LET statement. */ %let macro-variable=value; /* The following example code appears on p.29 */ /* Specifying a macro variable. */ %let dsname=AMEX1; proc print data=&dsname label; var day close hi lo volume; title "Printing the &dsname Data Set"; run; proc plot data=&dsname vpct=150; plot close * day; title "Plotting the &dsname Data Set"; run; proc timeplot data=&dsname; plot hi='+' close='*' lo='-' / overlay; id day; title "Timeplot of the &dsname Data Set"; run; proc univariate data=&dsname normal plot; var close; title "Normality Test for the &dsname Data Set"; run; proc corr data=&dsname; var hi lo close volume; title2 "Correlation Data for the &dsname Data Set"; run; /* The following example code appears on pp.29-30 */ /* Using multiple macro variables. */ %let dsname=AMEX1; %let start='01aug93'd; %let end='05sep93'd; proc print data=&dsname label; where &start < day < &end; var day close hi lo volume; title "Printing the &dsname Data Set"; run; proc plot data=&dsname vpct=150; where &start < day < &end; plot close * day; title "Plotting the &dsname Data Set"; run; /* The following example code appears on p.30 */ /* Using automatic macro variables. */ %let dsname=AMEX1; %let start='01aug93'd; %let end='05sep93'd; %let analyst=John T. Doe; proc print data=&dsname label; where &start < day < &end; var day close hi lo volume; title "Printing the &dsname Data Set"; title2 "Report Prepared at &systime on &sysday, &sysdate"; title3 "Prepared by &analyst"; run; /* The following example code appears on p.30 */ /* General form for creating a SAS macro. */ %macro macro-name; macro-text; %mend macro-name; /* The following example code appears on p.31 */ /* Creating a SAS software macro. */ %let dsname=AMEX1; %let start='01aug93'd; %let end='05sep93'd; %macro printit; proc print data=&dsname label; where &start < day < &end; var day close hi lo volume; title "Printing the &dsname Data Set"; title2 "Report Prepared at &systime on &sysday, &sysdate"; run; %mend printit; %printit /* ----------------------------------------------------------- */ /* Chapter 2 */ /* Chapter 2, Display 1 */ /* Creating the DJM Data Set */ /* DJM data set, Appendix 2 */ data djm; format date monyy.; informat date monyy.; input date $ djiam @@; label djiam='Monthly DJIA Index Price'; /* Survey of Current Business */ cards; jan83 1064.29 feb83 1087.43 mar83 1129.58 apr83 1168.43 may83 1212.86 jun83 1221.47 jul83 1213.93 aug83 1189.21 sep83 1237.04 oct83 1252.20 nov83 1250.00 dec83 1257.64 jan84 1258.89 feb84 1164.46 mar84 1161.97 apr84 1152.71 may84 1143.42 jun84 1121.14 jul84 1113.27 aug84 1212.82 sep84 1213.51 oct84 1199.30 nov84 1211.30 dec84 1188.96 jan85 1238.16 feb85 1283.23 mar85 1268.83 apr85 1266.36 may85 1279.40 jun85 1314.00 jul85 1343.17 aug85 1326.18 sep85 1317.95 oct85 1351.58 nov85 1432.88 dec85 1517.02 jan86 1534.86 feb86 1652.73 mar86 1757.35 apr86 1807.05 may86 1801.80 jun86 1867.70 jul86 1809.92 aug86 1843.45 sep86 1813.47 oct86 1817.04 nov86 1883.65 dec86 1924.07 jan87 2065.13 feb87 2202.34 mar87 2292.61 apr87 2302.64 may87 2291.11 jun87 2384.02 jul87 2481.72 aug87 2655.01 sep87 2570.80 oct87 2224.59 nov87 1931.86 dec87 1910.07 jan88 1947.35 feb88 1980.65 mar88 2044.31 apr88 2036.13 may88 1988.91 jun88 2104.94 jul88 2104.22 aug88 2051.29 sep88 2080.06 oct88 2144.31 nov88 2099.04 dec88 2148.58 jan89 2234.68 feb89 2304.30 mar89 2283.11 apr89 2348.91 may89 2439.55 jun89 2494.90 jul89 2554.03 aug89 2691.11 sep89 2693.41 oct89 2692.01 nov89 2642.49 dec89 2728.47 jan90 2679.24 feb90 2614.18 mar90 2700.13 apr90 2708.26 may90 2793.81 jun90 2894.82 jul90 2934.23 aug90 2681.89 sep90 2550.69 oct90 2460.54 nov90 2518.56 dec90 2610.92 jan91 2587.60 feb91 2863.04 mar91 2920.11 apr91 2925.53 may91 2928.42 jun91 2968.13 jul91 2978.18 aug91 3006.08 sep91 3010.35 oct91 3019.73 nov91 2986.12 dec91 2958.64 jan92 3227.06 feb92 3257.27 mar92 3247.41 apr92 3294.08 may92 3376.78 jun92 3337.79 jul92 3329.40 aug92 3307.45 sep92 3293.92 oct92 3198.69 nov92 3238.49 dec92 3303.15 jan93 3277.71 feb93 3367.26 mar93 3440.73 apr93 3423.62 may93 3478.17 jun93 3513.81 jul93 3529.43 aug93 3597.01 sep93 3592.28 oct93 3625.80 nov93 3674.69 dec93 3743.62 jan94 3868.36 feb94 3905.61 ; /* GOPTIONS statement to produce high-resolution */ /* graphs as much as possible like those in book. */ goptions reset=global gunit=pct cback=white border htitle=6 htext=3 ftext=swissb colors=(black); /* The following example code appears on p.36 */ /* Creating a high-resolution plot of DJIA. */ proc gplot data=djm; plot djiam*date / vaxis=axis1 haxis=axis2; symbol1 i=join l=1 font=swissb; axis1 order=(1000 to 4000 by 500); axis2 label=('Time') order=('01jan83'd to '01jan94'd by yr); title 'Dow Jones Industrial Average'; run; quit; /* End of Example Code to Create Display 1, Chapter 2 */ /* Chapter 2, Example 1 */ /* The following example code appears on p.38 */ /* Estimating time-series components for DJIA. */ /* Use the DJM data set. */ proc x11 data=djm noprint; monthly charts=none date=date; var djiam; pdweights mon=1 tue=1 wed=1 thu=1 fri=1; output out=djm_out1 a1=djiam1 d10=seasonal d11=adjust d12=trend d13=irreg; run; proc print data=djm_out1(obs=15); var date djiam1 trend adjust seasonal irreg; title 'Dow Jones Industrial Average'; title2 'Original, Adjusted, and Components'; run; /* End of Example Code to Create Example 1, Chapter 2 */ /* Chapter 2, Display 2 */ /* The following example code appears on p.38 */ /* Estimating time-series components for DJIA. */ /* Use the DJM data set. */ proc x11 data=djm noprint; monthly charts=none date=date; var djiam; pdweights mon=1 tue=1 wed=1 thu=1 fri=1; output out=djm_out1 a1=djiam1 d10=seasonal d11=adjust d12=trend d13=irreg; run; /* GOPTIONS statement to produce high-resolution */ /* graphs as much as possible like those in book. */ goptions reset=global gunit=pct cback=white border htitle=6 htext=3 ftext=swissb colors=(black); /* The following example code appears on p.39 */ /* Plotting the DJIA and the Trend Component. */ proc gplot data=djm_out1; where date > '31dec89'd; plot djiam1 * date trend * date / overlay vaxis=axis1 haxis=axis2; symbol1 i=join l=1 font=swissb; symbol2 i=join l=20 font=swissb; axis1 order=(2400 to 4000 by 400) minor=(number=3); axis2 label=('Time') order=('01jan90'd to '01jan94'd by semiannual) minor=(number=5); title 'DJIA and Trend Component'; run; quit; /* End of Example Code to Create Display 2, Chapter 2 */ /* Chapter 2, Display 3 */ /* The following example code appears on p.38 */ /* Estimating time-series components for DJIA. */ /* Use the DJM data set. */ proc x11 data=djm noprint; monthly charts=none date=date; var djiam; pdweights mon=1 tue=1 wed=1 thu=1 fri=1; output out=djm_out1 a1=djiam1 d10=seasonal d11=adjust d12=trend d13=irreg; run; /* GOPTIONS statement to produce high-resolution */ /* graphs as much as possible like those in book. */ goptions reset=global gunit=pct cback=white border htitle=6 htext=3 ftext=swissb colors=(black); /* The following example code does not appear in the book. */ /* Plotting the Seasonal Component of the DJIA. */ /* The high-resolution plot appears on p.40 */ proc gplot data=djm_out1; plot seasonal * date / vaxis=axis1 haxis=axis2 vref=94 105; symbol1 i=join l=1 font=swissb; axis1 order=(85 to 115 by 5) minor=(number=4); axis2 label=('Time') order=('01jan83'd to '01jan94'd by yr); title 'Seasonal Component of DJIA'; run; quit; /* End of Example Code to Create Display 3, Chapter 2 */ /* Chapter 2, Display 4 */ /* The following example code appears on p.38 */ /* Estimating time-series components for DJIA. */ /* Use the DJM data set. */ proc x11 data=djm noprint; monthly charts=none date=date; var djiam; pdweights mon=1 tue=1 wed=1 thu=1 fri=1; output out=djm_out1 a1=djiam1 d10=seasonal d11=adjust d12=trend d13=irreg; run; /* GOPTIONS statement to produce high-resolution */ /* graphs as much as possible like those in book. */ goptions reset=global gunit=pct cback=white border htitle=6 htext=3 ftext=swissb colors=(black); /* The following example code does not appear in the book. */ /* Plotting the Irregular Component of the DJIA. */ /* The high-resolution plot appears on p.41 */ proc gplot data=djm_out1; plot irreg * date / vaxis=axis1 haxis=axis2; symbol1 i=join l=1 font=swissb; axis1 order=(85 to 115 by 5) minor=(number=4); axis2 label=('Time') order=('01jan83'd to '01jan94'd by yr); title 'Irregular Component of DJIA'; run; quit; /* End of Example Code to Create Display 4, Chapter 2 */ /* Chapter 2, Example 2 */ /* The following example code appears on p.44 */ /* Creating the AMEXA Data Set */ data amexa; format day date7.; informat day date7.; input day $ close @@; label close='Closing Price for Day'; cards; 12JUL93 438.10 13JUL93 439.11 14JUL93 438.67 15JUL93 437.98 16JUL93 436.47 19JUL93 433.48 20JUL93 433.79 21JUL93 433.31 22JUL93 431.36 23JUL93 432.05 26JUL93 433.76 27JUL93 434.77 28JUL93 434.78 29JUL93 436.59 30JUL93 437.00 ; /* The following example code appears on pp.44-45 */ /* Merging Data Sets and Creating Moving Averages */ /* Use the AMEX1 and AMEXA data sets. */ data amex3; set amexa amex1 (obs=25); ma10=(close+lag(close)+lag2(close)+lag3(close)+lag4(close) +lag5(close)+lag6(close)+lag7(close)+lag8(close) +lag9(close))/10; wma10=(10*close+9*lag(close)+8*lag2(close)+7*lag3(close) +6*lag4(close)+5*lag5(close)+4*lag6(close) +3*lag7(close)+2*lag8(close)+lag9(close))/55; /* Exponential Smoothing Weight */ w1=.6; retain esma1; /* Starting Value in Series */ if _n_ = 1 then esma1=close; /* Single Exponential Smoothing */ else esma1=w1*close+(1-w1)*esma1; w2=.75; retain esma2; /* Starting Values in Series */ if _n_ le 2 then esma2=esma1; /* Double Exponential Smoothing */ else esma2=w2*esma1+(1-w2)*esma2; run; proc print data=amex3 (firstobs=10 obs=20); var day close ma10 wma10 esma1 esma2; title 'AMEX Index Closing Price'; title2 'and Moving Averages'; run; /* End of Example Code to Create Example 2, Chapter 2 */ /* Chapter 2, Display 5 */ /* The following example code appears on p.44 */ /* Creating the AMEXA Data Set */ data amexa; format day date7.; informat day date7.; input day $ close @@; label close='Closing Price for Day'; cards; 12JUL93 438.10 13JUL93 439.11 14JUL93 438.67 15JUL93 437.98 16JUL93 436.47 19JUL93 433.48 20JUL93 433.79 21JUL93 433.31 22JUL93 431.36 23JUL93 432.05 26JUL93 433.76 27JUL93 434.77 28JUL93 434.78 29JUL93 436.59 30JUL93 437.00 ; /* The following example code appears on pp.44-45 */ /* Merging Data Sets and Creating Moving Averages */ /* Use the AMEX1 and AMEXA data sets. */ data amex3; set amexa amex1 (obs=25); ma10=(close+lag(close)+lag2(close)+lag3(close)+lag4(close) +lag5(close)+lag6(close)+lag7(close)+lag8(close) +lag9(close))/10; wma10=(10*close+9*lag(close)+8*lag2(close)+7*lag3(close) +6*lag4(close)+5*lag5(close)+4*lag6(close) +3*lag7(close)+2*lag8(close)+lag9(close))/55; /* Exponential Smoothing Weight */ w1=.6; retain esma1; /* Starting Value in Series */ if _n_ = 1 then esma1=close; /* Single Exponential Smoothing */ else esma1=w1*close+(1-w1)*esma1; w2=.75; retain esma2; /* Starting Values in Series */ if _n_ le 2 then esma2=esma1; /* Double Exponential Smoothing */ else esma2=w2*esma1+(1-w2)*esma2; run; /* GOPTIONS statement to produce high-resolution */ /* graphs as much as possible like those in book. */ goptions reset=global gunit=pct cback=white border htitle=6 htext=3 ftext=swissb colors=(black); /* The following example code appears on p.46 */ /* Plotting the AMEX Index and 10-day Simple MA */ proc gplot data=amex3; where '22jul93'd < day < '26aug93'd; plot close * day ma10 * day / overlay vaxis=axis1 haxis=axis2; symbol1 v=C h=2.5 i=join l=1 font=swissb; symbol2 v=S h=2.5 i=join l=1 font=swissb; axis1 label=('Price') order=(430 to 450 by 5); axis2 label=('Day') order=('26jul93'd to '25aug93'd by 7); title '10-Day Simple Moving Average'; title2 'and AMEX Index Closing Price'; run; quit; /* End of Example Code to Create Display 5, Chapter 2 */ /* Chapter 2, Display 6 */ /* The following example code appears on p.44 */ /* Creating the AMEXA Data Set */ data amexa; format day date7.; informat day date7.; input day $ close @@; label close='Closing Price for Day'; cards; 12JUL93 438.10 13JUL93 439.11 14JUL93 438.67 15JUL93 437.98 16JUL93 436.47 19JUL93 433.48 20JUL93 433.79 21JUL93 433.31 22JUL93 431.36 23JUL93 432.05 26JUL93 433.76 27JUL93 434.77 28JUL93 434.78 29JUL93 436.59 30JUL93 437.00 ; /* The following example code appears on pp.44-45 */ /* Merging Data Sets and Creating Moving Averages */ /* Use the AMEX1 and AMEXA data sets. */ data amex3; set amexa amex1 (obs=25); ma10=(close+lag(close)+lag2(close)+lag3(close)+lag4(close) +lag5(close)+lag6(close)+lag7(close)+lag8(close) +lag9(close))/10; wma10=(10*close+9*lag(close)+8*lag2(close)+7*lag3(close) +6*lag4(close)+5*lag5(close)+4*lag6(close) +3*lag7(close)+2*lag8(close)+lag9(close))/55; /* Exponential Smoothing Weight */ w1=.6; retain esma1; /* Starting Value in Series */ if _n_ = 1 then esma1=close; /* Single Exponential Smoothing */ else esma1=w1*close+(1-w1)*esma1; w2=.75; retain esma2; /* Starting Values in Series */ if _n_ le 2 then esma2=esma1; /* Double Exponential Smoothing */ else esma2=w2*esma1+(1-w2)*esma2; run; /* GOPTIONS statement to produce high-resolution */ /* graphs as much as possible like those in book. */ goptions reset=global gunit=pct cback=white border htitle=6 htext=3 ftext=swissb colors=(black); /* The following example code does not appear in the book. */ /* Plotting the AMEX Index and 10-day Weighted MA */ proc gplot data=amex3; where '22jul93'd < day < '26aug93'd; plot close * day wma10 * day / overlay vaxis=axis1 haxis=axis2; symbol1 v=C h=3 i=join l=1 font=swissb; symbol2 v=W h=3 i=join l=1 font=swissb; axis1 label=('Price') order=(430 to 450 by 5); axis2 label=('Day') order=('26jul93'd to '25aug93'd by 7); title '10-Day Weighted Moving Average'; title2 'and AMEX Index Closing Price'; run; quit; /* End of Example Code to Create Display 6, Chapter 2 */ /* Chapter 2, Display 7 */ /* The following example code appears on p.44 */ /* Creating the AMEXA Data Set */ data amexa; format day date7.; informat day date7.; input day $ close @@; label close='Closing Price for Day'; cards; 12JUL93 438.10 13JUL93 439.11 14JUL93 438.67 15JUL93 437.98 16JUL93 436.47 19JUL93 433.48 20JUL93 433.79 21JUL93 433.31 22JUL93 431.36 23JUL93 432.05 26JUL93 433.76 27JUL93 434.77 28JUL93 434.78 29JUL93 436.59 30JUL93 437.00 ; /* The following example code appears on pp.44-45 */ /* Merging Data Sets and Creating Moving Averages */ /* Use the AMEX1 and AMEXA data sets. */ data amex3; set amexa amex1 (obs=25); ma10=(close+lag(close)+lag2(close)+lag3(close)+lag4(close) +lag5(close)+lag6(close)+lag7(close)+lag8(close) +lag9(close))/10; wma10=(10*close+9*lag(close)+8*lag2(close)+7*lag3(close) +6*lag4(close)+5*lag5(close)+4*lag6(close) +3*lag7(close)+2*lag8(close)+lag9(close))/55; /* Exponential Smoothing Weight */ w1=.6; retain esma1; /* Starting Value in Series */ if _n_ = 1 then esma1=close; /* Single Exponential Smoothing */ else esma1=w1*close+(1-w1)*esma1; w2=.75; retain esma2; /* Starting Values in Series */ if _n_ le 2 then esma2=esma1; /* Double Exponential Smoothing */ else esma2=w2*esma1+(1-w2)*esma2; run; /* GOPTIONS statement to produce high-resolution */ /* graphs as much as possible like those in book. */ goptions reset=global gunit=pct cback=white border htitle=6 htext=3 ftext=swissb colors=(black); /* The following example code does not appear in the book. */ /* Plotting the AMEX Index and Exponentially Smoothed MA */ proc gplot data=amex3; where '22jul93'd < day < '26aug93'd; plot close * day esma1 * day / overlay vaxis=axis1 haxis=axis2; symbol1 v=C h=3 i=join l=1 font=swissb; symbol2 v=E h=3 i=join l=1 font=swissb; axis1 label=('Price') order=(430 to 450 by 5); axis2 label=('Day') order=('26jul93'd to '25aug93'd by 7); title 'Exponentially Smoothed Moving Average'; title2 'and AMEX Index Closing Price'; run; quit; /* End of Example Code to Create Display 7, Chapter 2 */ /* Chapter 2, Example 3 */ /* The following example code appears on p.44 */ /* Creating the AMEXA Data Set */ data amexa; format day date7.; informat day date7.; input day $ close @@; label close='Closing Price for Day'; cards; 12JUL93 438.10 13JUL93 439.11 14JUL93 438.67 15JUL93 437.98 16JUL93 436.47 19JUL93 433.48 20JUL93 433.79 21JUL93 433.31 22JUL93 431.36 23JUL93 432.05 26JUL93 433.76 27JUL93 434.77 28JUL93 434.78 29JUL93 436.59 30JUL93 437.00 ; /* The following example code appears on pp.44-45 */ /* Merging Data Sets and Creating Moving Averages */ /* Use the AMEX1 and AMEXA data sets. */ data amex3; set amexa amex1 (obs=25); ma10=(close+lag(close)+lag2(close)+lag3(close)+lag4(close) +lag5(close)+lag6(close)+lag7(close)+lag8(close) +lag9(close))/10; wma10=(10*close+9*lag(close)+8*lag2(close)+7*lag3(close) +6*lag4(close)+5*lag5(close)+4*lag6(close) +3*lag7(close)+2*lag8(close)+lag9(close))/55; /* Exponential Smoothing Weight */ w1=.6; retain esma1; /* Starting Value in Series */ if _n_ = 1 then esma1=close; /* Single Exponential Smoothing */ else esma1=w1*close+(1-w1)*esma1; w2=.75; retain esma2; /* Starting Values in Series */ if _n_ le 2 then esma2=esma1; /* Double Exponential Smoothing */ else esma2=w2*esma1+(1-w2)*esma2; run; /* The following example code appears on p.49 */ /* Creating a Centered Moving Average */ proc expand data=amex3 out=amex_out method=none; id day; convert close = lag2 / transform=(lag 2); convert close = lag1 / transform=(lag 1); convert close; convert close = lead1 / transform=(lead 1); convert close = lead2 / transform=(lead 2); convert close = cma5 / transform=(movave 5); run; proc print data=amex_out (obs=20); var day lag2 lag1 close lead1 lead2 cma5 ; title 'AMEX Index Closing Price'; title2; run; /* End of Example Code to Create Example 3, Chapter 2 */ /* The following example code appears on p.50 */ /* Creating a Centered Moving Average */ /* Use the AMEX3 data set, created on pp.44-45 */ data amex3_sm; /* Creating a Lead Variable */ set amex3 (firstobs=2); close1=close; /* Creating a 3-Day Centered Moving Average */ set amex3; close_cm=(lag(close)+close+close1)/3; run; proc print data=amex3_sm; var day close close1 close_cm; run; /* Chapter 2, Display 8 */ /* The following example code appears on p.44 */ /* Creating the AMEXA Data Set */ data amexa; format day date7.; informat day date7.; input day $ close @@; label close='Closing Price for Day'; cards; 12JUL93 438.10 13JUL93 439.11 14JUL93 438.67 15JUL93 437.98 16JUL93 436.47 19JUL93 433.48 20JUL93 433.79 21JUL93 433.31 22JUL93 431.36 23JUL93 432.05 26JUL93 433.76 27JUL93 434.77 28JUL93 434.78 29JUL93 436.59 30JUL93 437.00 ; /* The following example code appears on pp.44-45 */ /* Merging Data Sets and Creating Moving Averages */ /* Use the AMEX1 and AMEXA data sets. */ data amex3; set amexa amex1 (obs=25); ma10=(close+lag(close)+lag2(close)+lag3(close)+lag4(close) +lag5(close)+lag6(close)+lag7(close)+lag8(close) +lag9(close))/10; wma10=(10*close+9*lag(close)+8*lag2(close)+7*lag3(close) +6*lag4(close)+5*lag5(close)+4*lag6(close) +3*lag7(close)+2*lag8(close)+lag9(close))/55; /* Exponential Smoothing Weight */ w1=.6; retain esma1; /* Starting Value in Series */ if _n_ = 1 then esma1=close; /* Single Exponential Smoothing */ else esma1=w1*close+(1-w1)*esma1; w2=.75; retain esma2; /* Starting Values in Series */ if _n_ le 2 then esma2=esma1; /* Double Exponential Smoothing */ else esma2=w2*esma1+(1-w2)*esma2; run; /* The following example code appears on p.49 */ /* Creating a Centered Moving Average */ proc expand data=amex3 out=amex_out method=none; id day; convert close = lag2 / transform=(lag 2); convert close = lag1 / transform=(lag 1); convert close; convert close = lead1 / transform=(lead 1); convert close = lead2 / transform=(lead 2); convert close = cma5 / transform=(movave 5); run; /* GOPTIONS statement to produce high-resolution */ /* graphs as much as possible like those in book. */ goptions reset=global gunit=pct cback=white border htitle=6 htext=3 ftext=swissb colors=(black); /* The following example code appears on p.50 */ /* Plotting a Centered Moving Average */ proc gplot data=amex_out; where '22jul93'd < day < '26aug93'd; plot close * day cma5 * day / overlay vaxis=axis1 haxis=axis2; symbol1 v=C h=2.5 i=join l=1 font=swissb; symbol2 v=M h=2.5 i=join l=1 font=swissb; axis1 label=('Price') order=(430 to 450 by 5); axis2 label=('Day') order=('26jul93'd to '25aug93'd by 7); title 'AMEX Index Closing Price'; title2 'and 5-day Centered Moving Average'; run; quit; /* End of Example Code to Create Display 8, Chapter 2 */ /* Chapter 2, Example 4 */ /* The following example code appears on p.52 */ /* Creating a Simple 10-Day Moving Average */ /* Use the AMEX3 data set, created on pp.44-45 */ proc macontrol data=amex3; machart close*day / span=10 outtable=ma_out1; title 'AMEX Index Closing Price'; title2 '10-Day Simple Moving Average'; run; /* End of Example Code to Create Example 4, Chapter 2 */ /* Chapter 2, Example 5 */ /* The following example code appears on p.52 */ /* Creating a Simple 10-Day Moving Average */ /* Use the AMEX3 data set, created on pp.44-45 */ proc macontrol data=amex3; machart close*day / span=10 outtable=ma_out1; title 'AMEX Index Closing Price'; title2 '10-Day Simple Moving Average'; run; proc print data=ma_out1 (firstobs=26 obs=35); title 'AMEX Index Closing Price'; title2 'Table from PROC MACONTROL'; run; /* End of Example Code to Create Example 5, Chapter 2 */ /* Chapter 2, Display 9 */ /* The following example code appears on p.55 */ /* Creating a Simple 10-Day Moving Average */ /* Use the AMEX3 data set, created on pp.44-45 */ /* GOPTIONS statement to produce high-resolution */ /* graphs as much as possible like those in book. */ goptions reset=global gunit=pct cback=white border htitle=6 htext=3 ftext=swissb colors=(black); proc macontrol data=amex3 graphics; ewmachart close*day / weight=.2; title 'Exponentially Weighted Moving Average'; title2 'AMEX Index Closing Price'; run; /* End of Example Code to Create Display 9, Chapter 2 */ /* Chapter 2, Display 10 */ /* The following example code appears on p.56 */ /* Creating a Simple 10-Day Moving Average */ /* Use the AMEX3 data set, created on pp.44-45 */ data amex3a; set amexa amex1; close_d=dif(close); run; /* GOPTIONS statement to produce high-resolution */ /* graphs as much as possible like those in book. */ goptions reset=global gunit=pct cback=white border htitle=6 htext=3 ftext=swissb colors=(black); proc macontrol data=amex3a graphics; where '11feb94'd < day < '10apr94'd; machart close_d*day / span=1 alpha=.10; title 'First Difference AMEX Index Close'; run; /* End of Example Code to Create Display 10, Chapter 2 */ /* ----------------------------------------------------------- */ /* Chapter 3 */ /* Chapter 3, Example 1 */ /* The following example code appears on pp.63-64 */ /* Use AMEX1, DJ, and GOLD data sets. */ data close; merge amex1 dj gold; by day; where day > '31dec93'd; run; proc forecast data=close method=stepar interval=weekday outest=est_out1 outestall lead=10 out=pred1; where day < '26mar94'd; var dj_close close gold; id day; run; proc forecast data=close method=expo nstart=8 interval=weekday weight=.2 trend=3 outest=est_out2 outestall lead=10 out=pred2; where day < '26mar94'd; var dj_close close gold; id day; run; proc print data=est_out1; var _type_ dj_close close gold; title 'Goodness-of-Fit and Theil Statistics'; title2 'Stepwise Autoregressive Models'; run; /* End of Example Code to Create Example 1, Chapter 3 */ /* Chapter 3, Example 2 */ /* The following example code appears on pp.63-64 */ /* Use AMEX1, DJ, and GOLD data sets. */ data close; merge amex1 dj gold; by day; where day > '31dec93'd; run; proc forecast data=close method=stepar interval=weekday outest=est_out1 outestall lead=10 out=pred1; where day < '26mar94'd; var dj_close close gold; id day; run; /* The following example code appears on p.67 */ proc print data=pred1; title 'Stepwise Autoregressive Model Forecasts'; title2 'DJIA, AMEX, and Gold'; run; /* The following example code appears on pp.63-64 */ /* Use AMEX1, DJ, and GOLD data sets. */ data close; merge amex1 dj gold; by day; where day > '31dec93'd; run; proc forecast data=close method=expo nstart=8 interval=weekday weight=.2 trend=3 outest=est_out2 outestall lead=10 out=pred2; where day < '26mar94'd; var dj_close close gold; id day; run; /* The following example code appears on p.68 */ proc print data=pred2; title 'Exponential Smoothing Model Forecasts'; title2 'DJIA, AMEX, and Gold'; run; /* End of Example Code to Create Example 2, Chapter 3 */ /* Chapter 3, Display 1 */ /* GOPTIONS statement to produce high-resolution */ /* graphs as much as possible like those in book. */ goptions reset=global gunit=pct cback=white border htitle=6 htext=3 ftext=swissb colors=(black); /* The following example code appears on p.72 */ /* Plotting the AMEX Index CLosing Price */ /* Use the AMEX1 Data Set, Appendix 1 */ proc gplot data=amex1; where '31dec93'd < day < '26mar94'd; plot close * day / vaxis=axis1 haxis=axis2; symbol1 v=C h=3 i=join l=1 font=swissb; axis1 label=('Price') order=(460 to 490 by 5); axis2 label=('Day') order=('31dec93'd to '05apr94'd by 14); title 'AMEX Index Closing Price'; run; quit; /* End of Example Code to Create Display 1, Chapter 3 */ /* Chapter 3, Example 3 */ /* The following example code appears on p.73 */ /* Use the AMEX1 Data Set, Appendix 1 */ proc arima data=amex1; where '31dec93'd < day < '26mar94'd; identify var=close; title 'AMEX Index Closing Price'; run; /* End of Example Code to Create Example 3, Chapter 3 */ /* Chapter 3, Example 4 */ /* The following example code appears on p.75 */ /* Use the AMEX1 Data Set, Appendix 1 */ data amex4; set amex1; where '31dec93'd < day < '26mar94'd; run; %dftest(amex4, close, ar=2, dlag=1, outstat=am_out1); proc print data=am_out1; var _type_ _name_ intercep _pvalue_; title 'Dickey-Fuller Unit Root Test'; title2 'AMEX Index Closing Price'; run; /* End of Example Code to Create Example 4, Chapter 3 */ /* Chapter 3, Example 5 */ /* The following example code appears on p.77 */ /* Use the AMEX1 Data Set, Appendix 1 */ proc arima data=amex1; where '31dec93'd < day < '26mar94'd; identify var=close(1); title 'AMEX Index Closing Price'; title2 'First Difference'; run; /* End of Example Code to Create Example 5, Chapter 3 */ /* Chapter 3, Example 6 */ /* The following example code appears on p.75 */ /* Use the AMEX1 Data Set, Appendix 1 */ data amex4; set amex1; where '31dec93'd < day < '26mar94'd; run; /* The following example code appears on p.79 */ %dftest(amex4, close, ar=2, dif=(1), dlag=1, outstat=am_out2); proc print data=am_out2; var _type_ _name_ intercep _pvalue_; title 'Dickey-Fuller Unit Root Test'; title2 'AMEX Index Closing Price'; title3 'First Differences'; run; /* End of Example Code to Create Example 6, Chapter 3 */ /* Chapter 3, Example 7 */ /* The following example code appears on p.81 */ /* Use the AMEX1 Data Set, Appendix 1 */ proc arima data=amex1; where '27feb94'd < day < '26mar94'd; identify var=close(1) noprint; estimate; estimate noint noprint; estimate p=1 noprint; estimate q=1 noprint; estimate p=1 q=1 noprint; title 'Random Model of AMEX Index Closing Price'; title2 'First Difference'; run; /* End of Example Code to Create Example 7, Chapter 3 */ /* Chapter 3, Example 8 */ /* The following example code appears on p.85 */ /* Use the AMEX1 Data Set, Appendix 1 */ proc arima data=amex1; where '27feb94'd < day < '26mar94'd; identify var=close(1) noprint; /* Estimating the Random Walk Model */ estimate noint noprint; forecast lead=6 id=day interval=weekday alpha=.05 noprint out=out1(rename=(forecast=f_random l95=l95_r u95=u95_r)); /* Estimating the ARIMA (1,1,1) Model */ estimate p=1 q=1 noprint; forecast lead=6 id=day interval=weekday alpha=.05 noprint out=out2(rename=(forecast=f_arima l95=l95_a u95=u95_a)); run; proc print data=out1 (firstobs=15); title 'Forecasts of AMEX Index Closing Price'; title2 'Random (0,1,0) Model'; run; proc print data=out2 (firstobs=15); title2 'ARIMA (1,1,1) Model'; run; /* End of Example Code to Create Example 8, Chapter 3 */ /* Chapter 3, Display 2 */ /* The following example code appears on p.85 */ /* Use the AMEX1 Data Set, Appendix 1 */ proc arima data=amex1; where '27feb94'd < day < '26mar94'd; identify var=close(1) noprint; /* Estimating the Random Walk Model */ estimate noint noprint; forecast lead=6 id=day interval=weekday alpha=.05 noprint out=out1(rename=(forecast=f_random l95=l95_r u95=u95_r)); /* Estimating the ARIMA (1,1,1) Model */ estimate p=1 q=1 noprint; forecast lead=6 id=day interval=weekday alpha=.05 noprint out=out2(rename=(forecast=f_arima l95=l95_a u95=u95_a)); run; /* The following example code appears on p.87 */ /* Use the AMEX1 Data Set, Appendix 1, and */ /* the OUT1 Data Set Created on p.85 */ data amex4a; merge out1 amex1; by day; if day < '26mar94'd then f_random = .; if day > '26mar94'd then close =.; run; proc sort data=amex4a out=amex4b; by day; run; /* GOPTIONS statement to produce high-resolution */ /* graphs as much as possible like those in book. */ goptions reset=global gunit=pct cback=white border htitle=6 htext=3 ftext=swissb colors=(black); proc gplot data=amex4b; where '27feb94'd < day < '05apr94'd; plot close * day u95_r * day l95_r * day f_random * day / vaxis=axis1 haxis=axis2 overlay href='26mar94'd; symbol1 v=C h=3 i=join l=1 font=swissb; symbol2 v=none i=join l=2; symbol3 v=none i=join l=2; symbol4 v=F h=2.5 font=swissb; axis1 label=('Price') order=(440 to 480 by 5); axis2 label=('Day 26MAR94') order=('27feb94'd to '05apr94'd by 7); title 'AMEX Index Closing Price'; title2 'Random (0,1,0) Model with 95% C.I.'; run; quit; /* End of Example Code to Create Display 2, Chapter 3 */ /* Chapter 3, Display 3 */ /* The following example code appears on p.85 */ /* Use the AMEX1 Data Set, Appendix 1 */ proc arima data=amex1; where '27feb94'd < day < '26mar94'd; identify var=close(1) noprint; /* Estimating the Random Walk Model */ estimate noint noprint; forecast lead=6 id=day interval=weekday alpha=.05 noprint out=out1a(rename=(forecast=f_random l95=l95_r u95=u95_r)); /* Estimating the ARIMA (1,1,1) Model */ estimate p=1 q=1 noprint; forecast lead=6 id=day interval=weekday alpha=.05 noprint out=out2(rename=(forecast=f_arima l95=l95_a u95=u95_a)); run; /* The following example code appears on p.87 */ /* Use the AMEX1 Data Set, Appendix 1, and */ /* the OUT1A Data Set Created above */ data amex4a1; merge out1a amex1; by day; if day < '26mar94'd then f_random = .; if day > '28mar94'd then close =.; run; proc sort data=amex4a1 out=amex4b1; by day; run; /* GOPTIONS statement to produce high-resolution */ /* graphs as much as possible like those in book. */ goptions reset=global gunit=pct cback=white border htitle=6 htext=3 ftext=swissb colors=(black); /* The following example code does not appear in the book. */ proc gplot data=amex4b1; where '27feb94'd < day < '05apr94'd; plot close * day u95_r * day l95_r * day f_random * day / vaxis=axis1 haxis=axis2 overlay href='26mar94'd; symbol1 v=C h=3 i=join l=1 font=swissb; symbol2 v=none i=join l=2; symbol3 v=none i=join l=2; symbol4 v=F h=3 font=swissb; axis1 label=('Price') order=(440 to 480 by 5); axis2 label=('Day 28MAR94') order=('27feb94'd to '05apr94'd by 7); title 'AMEX Index Closing Price'; title2 'Random (0,1,0) Model with 95% C.I.'; run; quit; /* End of Example Code to Create Display 3, Chapter 3 */ /* Chapter 3, Display 4 */ /* The following example code appears on p.85 */ /* Use the AMEX1 Data Set, Appendix 1 */ proc arima data=amex1; where '27feb94'd < day < '26mar94'd; identify var=close(1) noprint; /* Estimating the Random Walk Model */ estimate noint noprint; forecast lead=6 id=day interval=weekday alpha=.05 noprint out=out1b(rename=(forecast=f_random l95=l95_r u95=u95_r)); /* Estimating the ARIMA (1,1,1) Model */ estimate p=1 q=1 noprint; forecast lead=6 id=day interval=weekday alpha=.05 noprint out=out2(rename=(forecast=f_arima l95=l95_a u95=u95_a)); run; /* The following example code appears on p.87 */ /* Use the AMEX1 Data Set, Appendix 1, and */ /* the OUT1B Data Set Created above */ data amex4a2; merge out1b amex1; by day; if day < '26mar94'd then f_random = .; if day > '29mar94'd then close =.; run; proc sort data=amex4a2 out=amex4b2; by day; run; /* GOPTIONS statement to produce high-resolution */ /* graphs as much as possible like those in book. */ goptions reset=global gunit=pct cback=white border htitle=6 htext=3 ftext=swissb colors=(black); /* The following example code does not appear in the book. */ proc gplot data=amex4b2; where '27feb94'd < day < '05apr94'd; plot close * day u95_r * day l95_r * day f_random * day / vaxis=axis1 haxis=axis2 overlay href='26mar94'd; symbol1 v=C h=3 i=join l=1 font=swissb; symbol2 v=none i=join l=2; symbol3 v=none i=join l=2; symbol4 v=F h=3 font=swissb; axis1 label=('Price') order=(440 to 480 by 5); axis2 label=('Day 29MAR94') order=('27feb94'd to '05apr94'd by 7); title 'AMEX Index Closing Price'; title2 'Random (0,1,0) Model with 95% C.I.'; run; quit; /* End of Example Code to Create Display 4, Chapter 3 */ /* Chapter 3, Display 5 */ /* The following example code appears on p.85 */ /* Use the AMEX1 Data Set, Appendix 1 */ proc arima data=amex1; where '27feb94'd < day < '26mar94'd; identify var=close(1) noprint; /* Estimating the Random Walk Model */ estimate noint noprint; forecast lead=6 id=day interval=weekday alpha=.05 noprint out=out1c(rename=(forecast=f_random l95=l95_r u95=u95_r)); /* Estimating the ARIMA (1,1,1) Model */ estimate p=1 q=1 noprint; forecast lead=6 id=day interval=weekday alpha=.05 noprint out=out2(rename=(forecast=f_arima l95=l95_a u95=u95_a)); run; /* The following example code appears on p.87 */ /* Use the AMEX1 Data Set, Appendix 1, and */ /* the OUT1C Data Set Created above */ data amex4a3; merge out1c amex1; by day; if day < '26mar94'd then f_random = .; if day > '30mar94'd then close =.; run; proc sort data=amex4a3 out=amex4b3; by day; run; /* GOPTIONS statement to produce high-resolution */ /* graphs as much as possible like those in book. */ goptions reset=global gunit=pct cback=white border htitle=6 htext=3 ftext=swissb colors=(black); /* The following example code does not appear in the book. */ proc gplot data=amex4b3; where '27feb94'd < day < '05apr94'd; plot close * day u95_r * day l95_r * day f_random * day / vaxis=axis1 haxis=axis2 overlay href='26mar94'd; symbol1 v=C h=3 i=join l=1 font=swissb; symbol2 v=none i=join l=2; symbol3 v=none i=join l=2; symbol4 v=F h=3 font=swissb; axis1 label=('Price') order=(440 to 480 by 5); axis2 label=('Day 30MAR94') order=('27feb94'd to '05apr94'd by 7); title 'AMEX Index Closing Price'; title2 'Random (0,1,0) Model with 95% C.I.'; run; quit; /* End of Example Code to Create Display 5, Chapter 3 */ /* Chapter 3, Display 6 */ /* The following example code appears on p.85 */ /* Use the AMEX1 Data Set, Appendix 1 */ proc arima data=amex1; where '27feb94'd < day < '26mar94'd; identify var=close(1) noprint; /* Estimating the Random Walk Model */ estimate noint noprint; forecast lead=6 id=day interval=weekday alpha=.05 noprint out=out1d(rename=(forecast=f_random l95=l95_r u95=u95_r)); /* Estimating the ARIMA (1,1,1) Model */ estimate p=1 q=1 noprint; forecast lead=6 id=day interval=weekday alpha=.05 noprint out=out2(rename=(forecast=f_arima l95=l95_a u95=u95_a)); run; /* The following example code appears on p.87 */ /* Use the AMEX1 Data Set, Appendix 1, and */ /* the OUT1D Data Set Created above */ data amex4a4; merge out1d amex1; by day; if day < '26mar94'd then f_random = .; if day > '31mar94'd then close =.; run; proc sort data=amex4a4 out=amex4b4; by day; run; /* GOPTIONS statement to produce high-resolution */ /* graphs as much as possible like those in book. */ goptions reset=global gunit=pct cback=white border htitle=6 htext=3 ftext=swissb colors=(black); /* The following example code does not appear in the book. */ proc gplot data=amex4b4; where '27feb94'd < day < '05apr94'd; plot close * day u95_r * day l95_r * day f_random * day / vaxis=axis1 haxis=axis2 overlay href='26mar94'd; symbol1 v=C h=3 i=join l=1 font=swissb; symbol2 v=none i=join l=2; symbol3 v=none i=join l=2; symbol4 v=F h=3 font=swissb; axis1 label=('Price') order=(440 to 480 by 5); axis2 label=('Day 31MAR94') order=('27feb94'd to '05apr94'd by 7); title 'AMEX Index Closing Price'; title2 'Random (0,1,0) Model with 95% C.I.'; run; quit; /* End of Example Code to Create Display 6, Chapter 3 */ /* Chapter 3, Example 9 */ /* The following example code appears on p.85 */ /* Use the AMEX1 Data Set, Appendix 1 */ proc arima data=amex1; where '27feb94'd < day < '26mar94'd; identify var=close(1) noprint; /* Estimating the Random Walk Model */ estimate noint noprint; forecast lead=6 id=day interval=weekday alpha=.05 noprint out=out1(rename=(forecast=f_random l95=l95_r u95=u95_r)); /* Estimating the ARIMA (1,1,1) Model */ estimate p=1 q=1 noprint; forecast lead=6 id=day interval=weekday alpha=.05 noprint out=out2(rename=(forecast=f_arima l95=l95_a u95=u95_a)); run; /* The following example code appears on p.91 */ /* Use the AMEX1 Data Set, Appendix 1, and */ /* the OUT1 Data Set Created on p.85 */ data amex4c; merge out1 amex1; by day; if day < '26mar94'd then f_random = .; if f_random ge 0 and close ge 0 then resid=f_random-close; n=4; me=resid/n; mae=abs(resid)/n; mpe=(100/n)*(resid/close); mape=(100/n)*abs(resid/close); run; proc means data=amex4c sum; /* Forecast Period of Interest, 3/28-3/31 */ where '27mar94'd < day < '01apr94'd; var me mpe mape mae; title 'AMEX Index Closing Price'; title2 'Goodness-of-Fit Statistics for Forecasts'; run; /* End of Example Code to Create Example 9, Chapter 3 */ /* Chapter 3, Example 10 */ /* The following example code appears on p.93 */ /* Use the AMEX1 Data Set, Appendix 1 */ data amex5; set amex1; if day > '22mar94'd then dummy=1; else dummy=0; run; proc arima data=amex5; where '27feb94'd < day < '29mar94'd; identify var=close(1) crosscorr=(dummy); estimate noint input=(dummy); run; proc arima data=amex5; where '27feb94'd < day < '30mar94'd; identify var=close(1) crosscorr=(dummy); estimate noint input=(dummy); run; /* End of Example Code to Create Example 10, Chapter 3 */ /* Chapter 3, Example 11 */ /* The following example code appears on p.93 */ /* Use the AMEX1 Data Set, Appendix 1 */ data amex5; set amex1; if day > '22mar94'd then dummy=1; else dummy=0; run; /* The following example code appears on pp.94-95 */ data amex5a; set amex5; if day > '29mar94'd then close=.; run; proc arima data=amex5a; where '27feb94'd < day < '29mar94'd; identify var=close(1) crosscorr=(dummy) noprint; estimate noint input=(dummy) outest=model1 outcorr outcov noprint; where '27feb94'd < day < '01apr94'd; forecast lead=2 id=day interval=weekday alpha=.05 out=out3(rename=(forecast=f_inter l95=l95_i u95=u95_i)) noprint; run; proc print data=out3; where '25mar94'd < day < '01apr94'd; var day close f_inter l95_i u95_i residual; title 'Intervention Model Forecasts'; title2 'AMEX Index Closing Price'; run; /* End of Example Code to Create Example 11, Chapter 3 */ /* ----------------------------------------------------------- */ /* Chapter 4 */ /* Chapter 4, Display 1 */ /* GOPTIONS statement to produce high-resolution */ /* graphs as much as possible like those in book. */ goptions reset=global gunit=pct cback=white border htitle=6 htext=3 ftext=swissb colors=(black); /* The following example code appears on p.100 */ /* Use the AMEX1 Data Set, Appendix 1 */ proc gplot data=amex1; plot close * day / vaxis=axis1 haxis=axis2 vref=460 480 href='29mar94'd; symbol1 v=C h=3 i=join l=1 font=swissb; axis1 label=('Price') order=(420 to 500 by 10) minor=(n=1); axis2 label=('Day') order=('19feb94'd to '16apr94'd by 7) minor=(n=6); title 'AMEX Index Closing Price'; title2 'Buy and Sell Limits'; run; /* End of Example Code to Create Display 1, Chapter 4 */ /* Chapter 4, Display 2 */ /* The following example code appears on p.103 */ /* Use the AMEX1 Data Set, Appendix 1 */ data amex6; set amex1; /* 10-Day Moving Average */ ma10=(close+lag(close)+lag2(close)+lag3(close) +lag4(close)+lag5(close)+lag6(close) +lag7(close)+lag8(close)+lag9(close))/10; /* 5-Day Weighted Moving Average */ maw5=(5*close+4*lag(close)+3*lag2(close)+2*lag3(close) +lag4(close))/15; /* Single Exponential Weighting */ w=.085; retain ewma; if _n_ = 1 then ewma=close; else ewma=w*close+(1-w)*ewma; run; /* GOPTIONS statement to produce high-resolution */ /* graphs as much as possible like those in book. */ goptions reset=global gunit=pct cback=white border htitle=6 htext=3 ftext=swissb colors=(black); proc gplot data=amex6; plot close * day ma10 * day / vaxis=axis1 haxis=axis2 overlay href='25mar94'd; symbol1 v=C h=3 i=join l=1 font=swissb; symbol2 v=none i=join l=21; axis1 label=('Price') order=(420 to 500 by 10) minor=(n=1); axis2 label=('Day') order=('19feb94'd to '16apr94'd by 7) minor=(n=6); title 'AMEX Index Closing Price'; title2 '10-day Simple Moving Average'; run; /* End of Example Code to Create Display 2, Chapter 4 */ /* Chapter 4, Display 3 */ /* GOPTIONS statement to produce high-resolution */ /* graphs as much as possible like those in book. */ goptions reset=global gunit=pct cback=white border htitle=6 htext=3 ftext=swissb colors=(black); /* The following example code does not appears in the book. */ /* Use the AMEX6 Data Set, Created on p.103 */ proc gplot data=amex6; plot close * day ewma * day / vaxis=axis1 haxis=axis2 overlay href='24mar94'd; symbol1 v=C h=3 i=join l=1 font=swissb; symbol2 v=none i=join l=21; axis1 label=('Price') order=(420 to 480 by 10) minor=(n=1); axis2 label=('Day') order=('19feb94'd to '16apr94'd by 7) minor=(n=6); title 'AMEX Index Closing Price'; title2 'Exponentially Weighted Moving Average'; run; quit; /* End of Example Code to Create Display 3, Chapter 4 */ /* Chapter 4, Example 1 */ /* The following example code appears on p.103 */ /* Use the AMEX1 Data Set, Appendix 1 */ data amex6; set amex1; /* 10-Day Moving Average */ ma10=(close+lag(close)+lag2(close)+lag3(close) +lag4(close)+lag5(close)+lag6(close) +lag7(close)+lag8(close)+lag9(close))/10; /* 5-Day Weighted Moving Average */ maw5=(5*close+4*lag(close)+3*lag2(close)+2*lag3(close) +lag4(close))/15; /* Single Exponential Weighting */ w=.085; retain ewma; if _n_ = 1 then ewma=close; else ewma=w*close+(1-w)*ewma; run; /* The following example code appears on p.106 */ data amex6a; set amex6; if close ge ma10 then action='Buy '; if close < ma10 then action='Sell'; if action ne lag(action) then output; run; proc print data=amex6a (firstobs=10); var day close ma10 action; title 'Simple 10-Day Moving Average'; title2 'AMEX Index Buy and Sell Signals'; run; /* Exponentially Weighted Moving Average Buy and Sell Signals */ data amex6a1; set amex6; if close ge ewma then action1='Buy '; if close < ewma then action1='Sell'; if action1 ne lag(action1) then output; run; proc print data=amex6a1 (firstobs=10); var day close ewma action1; title 'Exponentially Weighted Moving Average'; title2 'AMEX Index Buy and Sell Signals'; run; /* End of Example Code to Create Example 1, Chapter 4 */ /* Chapter 4, Display 4 */ /* GOPTIONS statement to produce high-resolution */ /* graphs as much as possible like those in book. */ goptions reset=global gunit=pct cback=white border htitle=6 htext=3 ftext=swissb colors=(black); /* The following example code appears on p.108 */ /* Use the AMEX6 Data Set, Created on p.103, Ch 4, Ex 1 */ proc gplot data=amex6; plot close * day ewma * day / overlay vaxis=axis1 haxis=axis2; plot2 vol_dec * day / vaxis=axis3; symbol1 v=C h=3 i=join l=1 font=swissb; symbol2 v=none i=join l=21; symbol3 v=none i=needle; axis1 label=('Price') order=(420 to 480 by 10) offset=(21, 0) minor=(n=1); axis2 label=('Day') order=('19feb94'd to '16apr94'd by 7) minor=(n=6); axis3 label=('Volume') order=(2 to 18 by 4) offset=(1.0, 33); title 'AMEX Index Closing Price'; title2 'Declining Volume'; run; quit; /* End of Example Code to Create Display 4, Chapter 4 */ /* Chapter 4, Display 5 */ /* The following example code appears on p.103 */ /* Use the AMEX1 Data Set, Appendix 1 */ data amex6; set amex1; /* 10-Day Moving Average */ ma10=(close+lag(close)+lag2(close)+lag3(close) +lag4(close)+lag5(close)+lag6(close) +lag7(close)+lag8(close)+lag9(close))/10; /* 5-Day Weighted Moving Average */ maw5=(5*close+4*lag(close)+3*lag2(close)+2*lag3(close) +lag4(close))/15; /* Single Exponential Weighting */ w=.085; retain ewma; if _n_ = 1 then ewma=close; else ewma=w*close+(1-w)*ewma; run; /* The following example code appears on p.111 */ data amex6b; set amex6; /* Difference Oscillator */ am_osc=close-ma10; /* Ratio Oscillator */ /* Centered Around the Value of 100 */ am_oscr=100*close/ma10; /* Percentage Difference Oscillator */ /* Centered Around the Value of 0 */ am_oscd=100*(close-ma10)/ma10; /* Difference Oscillator of 2 Moving Averages */ am_osce=maw5-ewma; run; /* GOPTIONS statement to produce high-resolution */ /* graphs as much as possible like those in book. */ goptions reset=global gunit=pct cback=white border htitle=6 htext=3 ftext=swissb colors=(black); /* The following example code appears on pp.111-112 */ proc gplot data=amex6b; plot close * day ma10 * day / overlay vaxis=axis1 haxis=axis2 href='24mar94'd; plot2 am_osc * day / vaxis=axis3 vref=0; symbol1 v=C h=3 i=join l=1 font=swissb; symbol2 v=none i=join l=20; symbol3 v=none i=join l=1; axis1 label=('Price') order=(420 to 480 by 10) offset=(28, 0) minor=(n=1); axis2 label=('Day') order=('19feb94'd to '16apr94'd by 7) minor=(n=6); axis3 label=('OSC') order=(-25 to 10 by 5) offset=(1.0, 28) minor=(h=-2); title 'AMEX Difference Oscillator'; title2 'Closing Price and 10-Day Moving Average'; run; quit; /* End of Example Code to Create Display 5, Chapter 4 */ /* Chapter 4, Display 6 */ /* GOPTIONS statement to produce high-resolution */ /* graphs as much as possible like those in book. */ goptions reset=global gunit=pct cback=white border htitle=6 htext=3 ftext=swissb colors=(black); /* The following example code does not appears in the book. */ /* Use the AMEX6B Data Set, Created on p.111, Ch 4, Display 5 */ proc gplot data=amex6b; plot close * day ma10 * day / vaxis=axis1 haxis=axis2 overlay href='24mar94'd; plot2 am_oscr * day / vaxis=axis3 vref=100; symbol1 v=C h=3 i=join l=1 font=swissb; symbol2 v=none i=join l=20; symbol3 v=none i=join l=1; axis1 label=('Price') order=(420 to 480 by 10) offset=(28, 0) minor=(n=1); axis2 label=('Day') order=('19feb94'd to '16apr94'd by 7) minor=(n=6); axis3 label=('OSCR') order=(94 to 104 by 2) offset=(1.0, 28) minor=(h=-2 n=1); title 'AMEX Ratio Oscillator'; title2 'Closing Price and 10-Day Moving Average'; run; quit; /* End of Example Code to Create Display 6, Chapter 4 */ /* Chapter 4, Display 7 */ /* GOPTIONS statement to produce high-resolution */ /* graphs as much as possible like those in book. */ goptions reset=global gunit=pct cback=white border htitle=6 htext=3 ftext=swissb colors=(black); /* The following example code does not appears in the book. */ /* Use the AMEX6B Data Set, Created on p.111, Ch 4, Display 5 */ proc gplot data=amex6b; plot close * day ma10 * day / vaxis=axis1 haxis=axis2 overlay href='29mar94'd; plot2 am_oscr * day / vaxis=axis3 vref=97 100 103; symbol1 v=C h=3 i=join l=1 font=swissb; symbol2 v=none i=join l=20; symbol3 v=none i=join l=1; axis1 label=('Price') order=(420 to 480 by 10) offset=(28, 0) minor=(n=1); axis2 label=('Day') order=('19feb94'd to '16apr94'd by 7) minor=(n=6); axis3 label=('OSCR') order=(94 to 104 by 2) offset=(1.0, 28) minor=(h=-2 n=1); title 'Bands Around Oscillator Reference Value'; title2 'Closing Price and 10-Day Moving Average'; run; quit; /* End of Example Code to Create Display 7, Chapter 4 */ /* Chapter 4, Display 8 */ /* GOPTIONS statement to produce high-resolution */ /* graphs as much as possible like those in book. */ goptions reset=global gunit=pct cback=white border htitle=6 htext=3 ftext=swissb colors=(black); /* The following example code does not appears in the book. */ /* Use the AMEX6B Data Set, Created on p.111, Ch 4, Display 5 */ proc gplot data=amex6b; plot am_osce * day / vaxis=axis1 haxis=axis2 vref=0 href='25mar94'd; symbol1 v= i=join l=1 font=swissb; axis1 label=('OSCE') order=(-20 to 2 by 2) minor=(n=1); axis2 label=('Day') order=('19feb94'd to '16apr94'd by 7) minor=(n=6); title 'Complex Oscillator from Two Moving Averages'; title2 '5-Day Weighted Moving Average AMEX Close'; title3 'Exponentially Weighted Moving Average'; run; quit; /* End of Example Code to Create Display 8, Chapter 4 */ /* Chapter 4, Example 2 */ /* Chapter 4, Display 9 */ /* Chapter 4, Display 10 */ /* The following example code appears on p.103 */ /* Use the AMEX1 Data Set, Appendix 1 */ data amex6; set amex1; /* 10-Day Moving Average */ ma10=(close+lag(close)+lag2(close)+lag3(close) +lag4(close)+lag5(close)+lag6(close) +lag7(close)+lag8(close)+lag9(close))/10; /* 5-Day Weighted Moving Average */ maw5=(5*close+4*lag(close)+3*lag2(close)+2*lag3(close) +lag4(close))/15; /* Single Exponential Weighting */ w=.085; retain ewma; if _n_ = 1 then ewma=close; else ewma=w*close+(1-w)*ewma; run; /* The following example code appears on p.106 */ data amex6a; set amex6; if close ge ma10 then action='Buy '; if close < ma10 then action='Sell'; if action ne lag(action) then output; run; /* GOPTIONS statement to produce high-resolution */ /* graphs as much as possible like those in book. */ goptions reset=global gunit=pct cback=white border htitle=6 htext=3 ftext=swissb colors=(black); /* The following example code appears on p.115 */ /* Produces Output 4.2, Display 4.9, and Display 4.10 */ proc macontrol data=amex6b graphics; where '14feb94'd < day < '15apr94'd; machart am_osc*day / span=1 mu0=0 alpha=.01 tableall; title 'Difference Oscillator'; title2 'AMEX Index Closing Price'; run; /* End of Example Code to Create */ /* Chapter 4, Example 2 */ /* Chapter 4, Display 9 */ /* Chapter 4, Display 10 */ /* Chapter 4, Example 3 */ /* The following example code appears on p.118 */ /* Use the AMEX6B Data Set, Created in Ch 4, Display 4.5, p.111 */ proc means data=amex6b; where '04feb94'd < day < '26mar94'd; var close; title 'Series Standard Deviations 2/5 - 3/25'; run; /* End of Example Code to Create Example 3, Chapter 4 */ /* Chapter 4, Display 11 */ /* The following example code appears on p.103 */ /* Use the AMEX1 Data Set, Appendix 1 */ data amex6; set amex1; /* 10-Day Moving Average */ ma10=(close+lag(close)+lag2(close)+lag3(close) +lag4(close)+lag5(close)+lag6(close) +lag7(close)+lag8(close)+lag9(close))/10; /* 5-Day Weighted Moving Average */ maw5=(5*close+4*lag(close)+3*lag2(close)+2*lag3(close) +lag4(close))/15; /* Single Exponential Weighting */ w=.085; retain ewma; if _n_ = 1 then ewma=close; else ewma=w*close+(1-w)*ewma; run; /* The following example code appears on p.111 */ data amex6b; set amex6; /* Difference Oscillator */ am_osc=close-ma10; /* Ratio Oscillator */ /* Centered Around the Value of 100 */ am_oscr=100*close/ma10; /* Percentage Difference Oscillator */ /* Centered Around the Value of 0 */ am_oscd=100*(close-ma10)/ma10; /* Difference Oscillator of 2 Moving Averages */ am_osce=maw5-ewma; run; /* The following example code appears on p.119 */ data amex6c; set amex6b; /* Length of Moving Average */ n=10; /* Rolling Variance for AMEX CLOSE */ am_var=((close-ma10)**2+(lag(close)-ma10)**2+ (lag2(close)-ma10)**2+(lag3(close)-ma10)**2+ (lag4(close)-ma10)**2+(lag5(close)-ma10)**2+ (lag6(close)-ma10)**2+(lag7(close)-ma10)**2+ (lag8(close)-ma10)**2+(lag9(close)-ma10)**2)/(n-1); /* Standard Deviations from PROC MEANS */ /* 2/5/94 - 3/25/94 */ am_std=4.2137743; /* Bands */ /* Plus and Minus a Specified Value (K) */ k=15; ma_hi1=ma10+k; ma_lo1=ma10-k; /* Plus and Minus a Specified Percentage (KP) */ kp=.04; ma_hi2=ma10*(1+kp); ma_lo2=ma10*(1-kp); /* + and - a Multiple (M) of the Rolling Standard Deviation */ m=2; ma_hi3=ma10+m*sqrt(am_var); ma_lo3=ma10-m*sqrt(am_var); /* + and - a Multiple (M) of the Standard Deviation */ ma_hi4=ma10+m*am_std; ma_lo4=ma10-m*am_std; run; /* GOPTIONS statement to produce high-resolution */ /* graphs as much as possible like those in book. */ goptions reset=global gunit=pct cback=white border htitle=6 htext=3 ftext=swissb colors=(black); /* The following example code appears on p.120 */ proc gplot data=amex6c; plot close * day ma_hi1 * day ma_lo1 * day ma10 * day / vaxis=axis1 haxis=axis2 overlay; symbol1 v=C h=3 i=join l=1 font=swissb; symbol2 v=none i=join l=1; symbol3 v=none i=join l=1; symbol4 v=none i=join l=20; axis1 label=('Price') order=(420 to 500 by 10) minor=(n=1); axis2 label=('Day') order=('19feb94'd to '16apr94'd by 7) minor=(n=6); title 'Plus & Minus Specified Value Banded Plot'; title2 'AMEX Index Closing Price'; run; quit; /* End of Example Code to Create Display 11, Chapter 4 */ /* Chapter 4, Display 12 */ /* GOPTIONS statement to produce high-resolution */ /* graphs as much as possible like those in book. */ goptions reset=global gunit=pct cback=white border htitle=6 htext=3 ftext=swissb colors=(black); /* The following example code does not appears in the book. */ /* Use the AMEX6C Data Set, Created on p.119, Ch 4, Display 11 */ proc gplot data=amex6c; plot close * day ma_hi2 * day ma_lo2 * day ma10 * day / overlay vaxis=axis1 haxis=axis2; symbol1 v=C h=3 i=join l=1 font=swissb; symbol2 v=none i=join l=1; symbol3 v=none i=join l=1; symbol4 v=none i=join l=20; axis1 label=('Price') order=(420 to 500 by 10) minor=(n=1); axis2 label=('Day') order=('19feb94'd to '16apr94'd by 7) minor=(n=6); title 'Plus & Minus Percentage Banded Plot'; title2 'AMEX Index Closing Price'; run; /* End of Example Code to Create Display 12, Chapter 4 */ /* Chapter 4, Display 13 */ /* GOPTIONS statement to produce high-resolution */ /* graphs as much as possible like those in book. */ goptions reset=global gunit=pct cback=white border htitle=6 htext=3 ftext=swissb colors=(black); /* The following example code does not appears in the book. */ /* Use the AMEX6C Data Set, Created on p.119, Ch 4, Display 11 */ proc gplot data=amex6c; plot close * day ma_hi3 * day ma_lo3 * day ma10 * day / overlay vaxis=axis1 haxis=axis2; symbol1 v=C h=3 i=join l=1 font=swissb; symbol2 v=none i=join l=1; symbol3 v=none i=join l=1; symbol4 v=none i=join l=20; axis1 label=('Price') order=(420 to 500 by 10); axis2 label=('Day') order=('19feb94'd to '16apr94'd by 7) minor=(n=6); title 'Rolling Standard Deviation Banded Plot'; title2 'AMEX Index Closing Price'; run; /* End of Example Code to Create Display 13, Chapter 4 */ /* Chapter 4, Display 14 */ /* GOPTIONS statement to produce high-resolution */ /* graphs as much as possible like those in book. */ goptions reset=global gunit=pct cback=white border htitle=6 htext=3 ftext=swissb colors=(black); /* The following example code does not appears in the book. */ /* Use the AMEX6C Data Set, Created on p.119, Ch 4, Display 11 */ proc gplot data=amex6c; plot close * day ma_hi4 * day ma_lo4 * day ma10 * day / overlay vaxis=axis1 haxis=axis2; symbol1 v=C h=3 i=join l=1 font=swissb; symbol2 v=none i=join l=1; symbol3 v=none i=join l=1; symbol4 v=none i=join l=20; axis1 label=('Price') order=(420 to 500 by 10); axis2 label=('Day') order=('19feb94'd to '16apr94'd by 7) minor=(n=6); title 'Standard Deviation Banded Plot'; title2 'AMEX Index Closing Price'; run; /* End of Example Code to Create Display 14, Chapter 4 */ /* Chapter 4, Example 4 */ /* The following example code appears on p.85 */ /* Use the AMEX1 Data Set, Appendix 1 */ proc arima data=amex1; where '27feb94'd < day < '26mar94'd; identify var=close(1) noprint; /* Estimating the Random Walk Model */ estimate noint noprint; forecast lead=6 id=day interval=weekday alpha=.05 noprint out=out1(rename=(forecast=f_random l95=l95_r u95=u95_r)); /* Estimating the ARIMA (1,1,1) Model */ estimate p=1 q=1 noprint; forecast lead=6 id=day interval=weekday alpha=.05 noprint out=out2(rename=(forecast=f_arima l95=l95_a u95=u95_a)); run; proc print data=out1 (firstobs=15); title 'Forecasts of AMEX Index Closing Price'; title2 'Random (0,1,0) Model'; run; /* End of Example Code to Create Example 4, Chapter 4 */ /* Chapter 4, Display 15 */ /* The following example code appears on p.85 */ /* Use the AMEX1 Data Set, Appendix 1 */ proc arima data=amex1; where '27feb94'd < day < '26mar94'd; identify var=close(1) noprint; /* Estimating the Random Walk Model */ estimate noint noprint; forecast lead=6 id=day interval=weekday alpha=.05 noprint out=out1d(rename=(forecast=f_random l95=l95_r u95=u95_r)); /* Estimating the ARIMA (1,1,1) Model */ estimate p=1 q=1 noprint; forecast lead=6 id=day interval=weekday alpha=.05 noprint out=out2(rename=(forecast=f_arima l95=l95_a u95=u95_a)); run; /* The following example code appears on p.87 */ /* Use the AMEX1 Data Set, Appendix 1, and */ /* the OUT1D Data Set Created above */ data amex4a4; merge out1d amex1; by day; if day < '26mar94'd then f_random = .; if day > '31mar94'd then close =.; run; proc sort data=amex4a4 out=amex4b4; by day; run; /* GOPTIONS statement to produce high-resolution */ /* graphs as much as possible like those in book. */ goptions reset=global gunit=pct cback=white border htitle=6 htext=3 ftext=swissb colors=(black); /* The following example code does not appears in the book. */ proc gplot data=amex4b4; where '27feb94'd < day < '05apr94'd; plot close * day u95_r * day l95_r * day f_random * day / vaxis=axis1 haxis=axis2 overlay href='28mar94'd; symbol1 v=C h=3 i=join l=1 font=swissb; symbol2 v=none i=join l=2; symbol3 v=none i=join l=2; symbol4 v=F h=3 font=swissb; axis1 label=('Price') order=(440 to 480 by 5); axis2 label=('Day') order=('27feb94'd to '05apr94'd by 7) minor=(n=6); title 'AMEX Index Closing Price'; title2 'Random Walk (0,1,0) Model with 95% C.I.'; run; quit; /* End of Example Code to Create Display 15, Chapter 4 */ /* ----------------------------------------------------------- */ /* Chapter 5 */ /* Chapter 5, Example 1 */ /* The following example code appears on p.103 */ /* Use the AMEX1 Data Set, Appendix 1 */ data amex6; set amex1; /* 10-Day Moving Average */ ma10=(close+lag(close)+lag2(close)+lag3(close) +lag4(close)+lag5(close)+lag6(close) +lag7(close)+lag8(close)+lag9(close))/10; /* 5-Day Weighted Moving Average */ maw5=(5*close+4*lag(close)+3*lag2(close)+2*lag3(close) +lag4(close))/15; /* Single Exponential Weighting */ w=.085; retain ewma; if _n_ = 1 then ewma=close; else ewma=w*close+(1-w)*ewma; run; /* The following example code appears on p.130 */ data amex7a; set amex6; /* Sum of Stocks Advancing, Declining */ tot_up + up; tot_down + down; /* Advance-Decline Ratio */ adr = up/down; /* Simple 10-Day Moving Average */ adr_ma10=(adr+lag(adr)+lag2(adr)+lag3(adr)+lag4(adr)+lag5(adr) +lag6(adr)+lag7(adr)+lag8(adr)+lag9(adr))/10; /* Advance-Decline Line */ y=up-down; adl=y+lag(y); adl_ma3=(adl+lag(adl)+lag2(adl))/3; /* Absolute Breadth Index */ abi = abs(up-down); /* Breadth Advance-Decline Indicator */ up_ma3 = (up+lag(up)+lag2(up))/3; badi = up_ma3/(up+down); /* STIX, Short-Term Market Breadth Indicator */ tix = up/(up+down); stix = .09*tix+.91*lag(tix); /* Schultz Advances/Total Issues Traded (ATI) */ /* Declining/Total Issues Traded (DTI) */ ati = up/(up+down+unc); dti = down/(up+down+unc); /* Unchanged Issues Index (UII) */ uii = unc/(up+down+unc); /* Adv/Dec Noncumulator aka Hughes Breadth Index */ ad = (up-down)/(up+down+unc); run; proc print data=amex7a (obs=20); var day tot_up tot_down adr adl abi badi stix ati dti uii ad; title 'Advancing and Declining Stock Indicators'; title2 'American Stock Exchange (AMEX)'; run; /* End of Example Code to Create Example 1, Chapter 5 */ /* Chapter 5, Display 1 */ /* GOPTIONS statement to produce high-resolution */ /* graphs as much as possible like those in book. */ goptions reset=global gunit=pct cback=white border htitle=6 htext=3 ftext=swissb colors=(black); /* The following example code appears on p.133 */ /* Use the AMEX7A Data Set, Created on p.130, Ch 5, Ex 1 */ proc gplot data=amex7a; where day < '20sep93'd; plot close * day / vaxis=axis1 haxis=axis2; plot2 adl * day / vaxis=axis3 vref=0; symbol1 v=C h=3 i=join l=1 font=swissb; symbol2 i=join l=1 font=swissb; axis1 label=('Closing Price') order=(434 to 464 by 5) offset=(28, 0) major=(n=5 h=-2); axis2 label=('Day') order=('08aug93'd to '19sep93'd by 7) minor=(n=6); axis3 label=('ADL') order=(-325 to 150 by 75) offset=(1.0, 25) minor=(n=2 h=-2); title 'AMEX Index and Advance-Decline Line'; run; quit; /* End of Example Code to Create Display 1, Chapter 5 */ /* Chapter 5, Display 2 */ /* GOPTIONS statement to produce high-resolution */ /* graphs as much as possible like those in book. */ goptions reset=global gunit=pct cback=white border htitle=6 htext=3 ftext=swissb colors=(black); /* The following example code appears on p.135 */ /* Use the AMEX7A Data Set, Created on p.130, Ch 5, Ex 1 */ proc gplot data=amex7a; where day < '20sep93'd; plot close * day / vaxis=axis1 haxis=axis2; plot2 adl_ma3 * day / vaxis=axis3 vref=0; symbol1 v=C h=3 i=join l=1 font=swissb; symbol2 i=join l=1 font=swissb; axis1 label=('Closing Price') order=(434 to 464 by 5) offset=(28, 0) major=(n=5 h=-2); axis2 label=('Day') order=('08aug93'd to '19sep93'd by 7) minor=(n=6); axis3 label=('ADL') order=(-325 to 150 by 75) offset=(1.0, 25) minor=(n=2 h=-2); title '3-Day Moving Average of Advance-Decline Line'; title2 'AMEX Index'; run; quit; /* End of Example Code to Create Display 2, Chapter 5 */ /* Chapter 5, Display 3 */ /* GOPTIONS statement to produce high-resolution */ /* graphs as much as possible like those in book. */ goptions reset=global gunit=pct cback=white border htitle=6 htext=3 ftext=swissb colors=(black); /* The following example code does not appears in the book. */ /* Use the AMEX7A Data Set, Created on p.130, Ch 5, Ex 1 */ proc gplot data=amex7a; where '27feb94'd < day < '05apr94'd; plot close * day / vaxis=axis1 haxis=axis2 href='16mar94'd; plot2 badi * day / vaxis=axis3; symbol1 v=C h=3 i=join l=1 font=swissb; symbol2 i=join l=1 font=swissb; axis1 label=('Closing Price') order=(440 to 480 by 10) offset=(25, 0) major=(n=5 h=-2); axis2 label=('Day') order=('27feb94'd to '03apr94'd by 7); axis3 label=('BADI') order=(.1 to .6 by .1) offset=(1.0, 28) minor=(n=1 h=-2); title 'Breadth Advance-Decline Indicator'; title2 'AMEX Index'; run; quit; /* End of Example Code to Create Display 3, Chapter 5 */ /* Chapter 5, Display 4 */ /* GOPTIONS statement to produce high-resolution */ /* graphs as much as possible like those in book. */ goptions reset=global gunit=pct cback=white border htitle=6 htext=3 ftext=swissb colors=(black); /* The following example code does not appears in the book. */ /* Use the AMEX7A Data Set, Created on p.130, Ch 5, Ex 1 */ proc gplot data=amex7a; where '27feb94'd < day < '05apr94'd; plot close * day / vaxis=axis1 haxis=axis2 href='22mar94'd; plot2 stix * day / vaxis=axis3; symbol1 v=C h=3 i=join l=1 font=swissb; symbol2 i=join l=1 font=swissb; axis1 label=('Closing Price') order=(440 to 480 by 10) offset=(25, 0) major=(n=5 h=-2); axis2 label=('Day') order=('27feb94'd to '03apr94'd by 7) minor=(n=6); axis3 label=('BADI') order=(.15 to .65 by .1) offset=(1.0, 28) minor=(n=1 h=-2); title 'Short-Term Market Breath Indicator, STIX'; title2 'AMEX Index'; run; quit; /* End of Example Code to Create Display 4, Chapter 5 */ /* Chapter 5, Example 2 */ /* The following example code appears on p.103 */ /* Use the AMEX1 Data Set, Appendix 1 */ data amex6; set amex1; /* 10-Day Moving Average */ ma10=(close+lag(close)+lag2(close)+lag3(close) +lag4(close)+lag5(close)+lag6(close) +lag7(close)+lag8(close)+lag9(close))/10; /* 5-Day Weighted Moving Average */ maw5=(5*close+4*lag(close)+3*lag2(close)+2*lag3(close) +lag4(close))/15; /* Single Exponential Weighting */ w=.085; retain ewma; if _n_ = 1 then ewma=close; else ewma=w*close+(1-w)*ewma; run; /* The following example code appears on pp.140-141 */ data amex7b; set amex6; /* Sum of VOL_ADV and VOL_DEC */ tot_adv + vol_adv; tot_dec + vol_dec; /* Cumulative Volume Indicator */ vol_dif=vol_adv-vol_dec; retain cvi; if _n_ = 1 then cvi=vol_dif; else cvi=vol_dif+cvi; /* Variables for Plotting */ cvi_5ma=(cvi+lag(cvi)+lag2(cvi)+lag3(cvi)+lag4(cvi))/5; cvi_osc=cvi-cvi_5ma; /* Upside-Downside Ratio (UDR) */ udr = vol_adv/vol_dec; /* Intermediate Calculations for PVI and NVI */ volume=vol_adv+vol_dec+vol_unc; vol_1=lag(volume); p_close=100*(close-lag(close))/lag(close); /* Positive Volume Index (PVI) */ retain pvi; if _n_ = 1 then pvi = 100; else do; if volume le vol_1 then pvi=pvi; else pvi=pvi+p_close; end; /* Negative Volume Index (NVI) */ retain nvi; if _n_ = 1 then nvi = 100; else do; if volume ge vol_1 then nvi=nvi; else nvi=nvi+p_close; end; /* Moving Averages of PVI and NVI for Plotting */ pvi_5ma=(pvi+lag(pvi)+lag2(pvi)+lag3(pvi)+lag4(pvi))/5; nvi_5ma=(nvi+lag(nvi)+lag2(nvi)+lag3(nvi)+lag4(nvi))/5; /* Volume Percent Change */ vpc=(volume-lag(volume))/lag(volume); /* Volume Oscillator */ vol_ma3=(volume+lag(volume)+lag2(volume))/3; w1=.05; retain vol_exp; if _n_ = 1 then vol_exp=volume; else vol_exp=w1*volume+(1-w1)*vol_exp; vol_osc=vol_ma3-vol_exp; run; proc print data=amex7b (obs=30 firstobs=10); var day close volume vpc vol_adv vol_dec vol_dif; title 'Basic AMEX Index Volume Indicators'; run; /* End of Example Code to Create Example 2, Chapter 5 */ /* Chapter 5, Example 3 */ /* The following example code appears on p.141 */ /* Use the AMEX7B Data Set, Created on pp.140-141, Ch 5, Ex 2 */ proc print data=amex7b (obs=30 firstobs=10); var day close cvi udr nvi pvi; title 'Complex AMEX Index Volume Indicators'; run; /* End of Example Code to Create Example 3, Chapter 5 */ /* Chapter 5, Display 5 */ /* GOPTIONS statement to produce high-resolution */ /* graphs as much as possible like those in book. */ goptions reset=global gunit=pct cback=white border htitle=6 htext=3 ftext=swissb colors=(black); /* The following example code does not appears in the book. */ /* Use the AMEX7B Data Set, Created on pp.140-141, Ch 5, Ex 2 */ proc gplot data=amex7b; where day < '20sep93'd; plot close * day / vaxis=axis1 haxis=axis2 href='18aug93'd '07sep93'd; plot2 pvi * day pvi_5ma * day / overlay vaxis=axis3; symbol1 v=C h=3 i=join l=1 font=swissb; symbol2 v=P h=3 i=join l=1 font=swissb; symbol3 i=join l=20 font=swissb; axis1 label=('Closing Price') order=(434 to 464 by 10) offset=(25, 0) major=(n=5 h=-2); axis2 label=('Day') order=('08aug93'd to '19sep93'd by 7) minor=(n=6); axis3 label=('PVI') order=(99 to 103 by 1) offset=(1.0, 28) major=(n=5 h=-2); title 'PVI as a Supporting Crossover Model'; title2 'AMEX Index'; run; quit; /* End of Example Code to Create Display 5, Chapter 5 */ /* Chapter 5, Display 6 */ /* GOPTIONS statement to produce high-resolution */ /* graphs as much as possible like those in book. */ goptions reset=global gunit=pct cback=white border htitle=6 htext=3 ftext=swissb colors=(black); /* The following example code does not appears in the book. */ /* Use the AMEX7B Data Set, Created on pp.140-141, Ch 5, Ex 2 */ proc gplot data=amex7b; where day < '20sep93'd; plot close * day / vaxis=axis1 haxis=axis2 href='16aug93'd '07sep93'd; plot2 cvi * day cvi_5ma * day / overlay vaxis=axis3; symbol1 v=C h=3 i=join l=1 font=swissb; symbol2 v=V h=3 i=join l=1 font=swissb; symbol3 i=join l=1 font=swissb; axis1 label=('Closing Price') order=(434 to 464 by 10) offset=(25, 0) major=(n=5 h=-2); axis2 label=('Day') order=('08aug93'd to '19sep93'd by 7) minor=(n=6); axis3 label=('CVI') order=(-25 to 25 by 10) offset=(1.0, 28) minor=(n=1 h=-2); title 'CVI as a Supporting Crossover Model'; title2 'AMEX Index'; run; quit; /* End of Example Code to Create Display 6, Chapter 5 */ /* Chapter 5, Display 7 */ /* GOPTIONS statement to produce high-resolution */ /* graphs as much as possible like those in book. */ goptions reset=global gunit=pct cback=white border htitle=6 htext=3 ftext=swissb colors=(black); /* The following example code does not appears in the book. */ /* Use the AMEX7B Data Set, Created on pp.140-141, Ch 5, Ex 2 */ proc gplot data=amex7b; where '27feb94'd < day < '05apr94'd; plot close * day ewma * day / overlay vaxis=axis1 haxis=axis2 href='24mar94'd; plot2 cvi_osc * day / vaxis=axis3 vref=0; symbol1 v=C h=3 i=join l=1 font=swissb; symbol2 i=join l=1 font=swissb; symbol3 i=join l=1 font=swissb; axis1 label=('Closing Price') order=(440 to 480 by 10) offset=(25, 0) major=(n=5 h=-2); axis2 label=('Day') order=('27feb94'd to '03apr94'd by 7) minor=(n=6); axis3 label=('CVI') order=(-25 to 25 by 10) offset=(1.0, 28) minor=(n=1 h=-2); title 'CVI Oscillator as Supporting Evidence'; title2 'AMEX Index Crossover Model'; run; quit; /* End of Example Code to Create Display 7, Chapter 5 */ /* Chapter 5, Display 8 */ /* GOPTIONS statement to produce high-resolution */ /* graphs as much as possible like those in book. */ goptions reset=global gunit=pct cback=white border htitle=6 htext=3 ftext=swissb colors=(black); /* The following example code does not appears in the book. */ /* Use the AMEX7B Data Set, Created on pp.140-141, Ch 5, Ex 2 */ proc gplot data=amex7b; where '27feb94'd < day < '05apr94'd; plot close * day / vaxis=axis1 haxis=axis2; plot2 nvi * day nvi_5ma * day / overlay vaxis=axis3 haxis=axis2 href='18aug93'd '07sep93'd; symbol1 v=C h=3 i=join l=1 font=swissb; symbol2 v=N h=3 i=join l=1 font=swissb; symbol3 i=join l=20 font=swissb; axis1 label=('Closing Price') order=(440 to 480 by 10) offset=(25, 0) major=(n=5 h=-2); axis2 label=('Day') order=('27feb94'd to '03apr94'd by 7) minor=(n=6); axis3 label=('NVI') order=(97 to 101 by 1) offset=(1.0, 28) minor=(n=1 h=-2); title 'NVI as a Supporting Crossover Model'; title2 'AMEX Index'; run; quit; /* End of Example Code to Create Display 8, Chapter 5 */ /* Chapter 5, Example 4 */ /* The following example code appears on p.103 */ /* Use the AMEX1 Data Set, Appendix 1 */ data amex6; set amex1; /* 10-Day Moving Average */ ma10=(close+lag(close)+lag2(close)+lag3(close) +lag4(close)+lag5(close)+lag6(close) +lag7(close)+lag8(close)+lag9(close))/10; /* 5-Day Weighted Moving Average */ maw5=(5*close+4*lag(close)+3*lag2(close)+2*lag3(close) +lag4(close))/15; /* Single Exponential Weighting */ w=.085; retain ewma; if _n_ = 1 then ewma=close; else ewma=w*close+(1-w)*ewma; run; /* The following example code appears on p.148 */ data amex7c; set amex6; /* Rate of Change (ROC) */ roc100 = 100*close/lag(close); /* Baseline 100 */ roc = 100*close/lag(close) - 100; /* Baseline Zero */ /* 10-Day Difference */ roc_10 = dif10(roc100); /* Stochastics (S) */ s = 100*(close-lo)/(hi-lo); /* 3-Day Simple Moving Average (S_MA) */ s_ma = (s+lag(s)+lag2(s))/3; /* Twice Smoothed 3-Day Simple Moving Average (S_MA_2) */ s_ma_2 = (s_ma+lag(s_ma)+lag2(s_ma))/3; /* Lane's Stochastic (LS, K, D) */ min_lo=min(of lo, lag(lo), lag2(lo), lag3(lo), lag4(lo)); max_hi=max(of hi, lag(hi), lag2(hi), lag3(hi), lag4(hi)); dif_cl=close-min_lo; /* If CLOSE=HI, LS=100 */ dif_hl=max_hi-min_lo; /* If CLOSE=LO, LS=0 */ ls=100*dif_cl/dif_hl; k=(ls+lag(ls)+lag2(ls))/3; d=(k+lag(k)+lag2(k))/3; /* 3-Period Moving Average of D */ d_ma=(d+lag(d)+lag2(d))/3; /* Oscillator Form */ osc=k-d; /* OSC > 0, Buy & OSC < 0, Sell */ /* Alternative Form of Lane's Stochastic: KA,DA */ ka=100*dif_cl/dif_hl; da=100*(dif_cl+lag(dif_cl)+lag2(dif_cl))/ (dif_hl+lag(dif_hl)+lag2(dif_hl)); run; proc print data=amex7c (obs=20); var day close roc100 roc roc_10 s s_ma s_ma_2; title 'Rate of Change Indicators for Price Data'; title2 'Basic Stochastic Indicators'; title3 'American Stock Exchange (AMEX)'; run; /* End of Example Code to Create Example 4, Chapter 5 */ /* Chapter 5, Example 5 */ /* The following example code appears on p.148 */ /* Use the AMEX7C Data Set, Created on p.148, Ch 5, Ex 4 */ proc print data=amex7c (obs=10); var day hi close lo min_lo max_hi dif_cl dif_hl ls k d d_ma; title 'Lane''s Stochastic Indicator'; title2 'American Stock Exchange (AMEX)'; title3; run; /* End of Example Code to Create Example 5, Chapter 5 */ /* Chapter 5, Display 9 */ /* GOPTIONS statement to produce high-resolution */ /* graphs as much as possible like those in book. */ goptions reset=global gunit=pct cback=white border htitle=6 htext=3 ftext=swissb colors=(black); /* The following example code does not appears in the book. */ /* Use the AMEX7C Data Set, Created on p.148, Ch 5, Ex 4 */ proc gplot data=amex7c; where '27feb94'd < day < '05apr94'd; plot ls * day / vaxis=axis1 haxis=axis2 href='21mar94'd; plot2 k * day d * day / overlay vaxis=axis3; symbol1 v=L h=3 i=join l=1 font=swissb; symbol2 v=K h=2.5 i=join l=1 font=swissb; symbol3 v=D h=2.5 i=join l=3 font=swissb; axis1 label=('LS') order=(0 to 100 by 20) offset=(25, 0) major=(n=5 h=-2); axis2 label=('Day') order=('27feb94'd to '03apr94'd by 7) minor=(n=6); axis3 label=('K,D') order=(0 to 100 by 20) offset=(1.0, 28) minor=(n=1 h=-2); title 'Stochastics: LS, K, and D'; title2 'AMEX Index'; run; quit; /* End of Example Code to Create Display 9, Chapter 5 */ /* Chapter 5, Display 10 */ /* GOPTIONS statement to produce high-resolution */ /* graphs as much as possible like those in book. */ goptions reset=global gunit=pct cback=white border htitle=6 htext=3 ftext=swissb colors=(black); /* The following example code does not appears in the book. */ /* Use the AMEX7C Data Set, Created on p.148, Ch 5, Ex 4 */ proc gplot data=amex7c; where '27feb94'd < day < '05apr94'd; plot close * day / vaxis=axis1 haxis=axis2 href='21mar94'd; plot2 k * day d * day / overlay vaxis=axis3 vref=15 85; symbol1 v=C h=3 i=join l=1 font=swissb; symbol2 v=K h=2.5 i=join l=1 font=swissb; symbol3 v=D h=2.5 i=join l=3 font=swissb; axis1 label=('Closing Price') order=(440 to 480 by 10) offset=(25, 0) major=(n=5 h=-2); axis2 label=('Day') order=('27feb94'd to '03apr94'd by 7) minor=(n=6); axis3 label=('K,D') order=(0 to 100 by 20) offset=(1.0, 28) minor=(n=1 h=-2); title 'Stochastics Overbought-Oversold Lines'; title2 'AMEX Index'; run; quit; /* End of Example Code to Create Display 10, Chapter 5 */ /* Chapter 5, Example 6 */ /* GOLD data set, Appendix 3 */ data gold; format day date7.; informat day date7.; input day $ gold @@; retain start; if day = '03jan94'd then start=gold; rsi_g =gold/start; label gold='COMEX Gold Spot Closing Price for Day'; cards; 03JAN94 393.70 04JAN94 394.10 05JAN94 391.10 06JAN94 389.20 07JAN94 386.40 10JAN94 385.00 11JAN94 388.00 12JAN94 386.30 13JAN94 390.00 14JAN94 389.50 17JAN94 391.60 18JAN94 393.10 19JAN94 392.30 20JAN94 387.50 21JAN94 381.40 24JAN94 381.10 25JAN94 381.40 26JAN94 384.50 27JAN94 377.40 28JAN94 376.90 31JAN94 381.60 01FEB94 384.10 02FEB94 384.70 03FEB94 387.30 04FEB94 386.60 07FEB94 378.90 08FEB94 382.30 09FEB94 384.00 10FEB94 382.00 11FEB94 380.00 14FEB94 383.90 15FEB94 383.80 16FEB94 383.60 17FEB94 382.80 18FEB94 380.30 22FEB94 378.00 23FEB94 377.70 24FEB94 376.50 25FEB94 378.60 28FEB94 381.40 01MAR94 378.30 02MAR94 377.80 03MAR94 377.30 04MAR94 377.60 07MAR94 375.90 08MAR94 376.70 09MAR94 379.20 10MAR94 387.30 11MAR94 385.30 14MAR94 386.40 15MAR94 386.90 16MAR94 384.90 17MAR94 382.40 18MAR94 387.10 21MAR94 385.80 22MAR94 389.20 23MAR94 387.00 24MAR94 391.60 25MAR94 391.00 28MAR94 388.00 29MAR94 386.00 30MAR94 386.10 31MAR94 391.80 04APR94 386.30 05APR94 384.40 06APR94 384.90 07APR94 383.90 08APR94 384.20 11APR94 377.90 12APR94 378.50 13APR94 378.20 14APR94 378.60 15APR94 377.70 18APR94 376.80 19APR94 371.50 20APR94 372.20 21APR94 373.10 22APR94 370.60 25APR94 373.40 26APR94 373.90 28APR94 375.60 29APR94 376.60 02MAY94 376.20 03MAY94 375.60 04MAY94 376.60 05MAY94 373.60 06MAY94 383.40 09MAY94 381.20 10MAY94 378.80 11MAY94 381.80 12MAY94 379.90 13MAY94 380.70 16MAY94 383.00 17MAY94 381.40 18MAY94 382.00 19MAY94 381.40 20MAY94 385.90 23MAY94 389.60 24MAY94 387.10 25MAY94 386.60 26MAY94 383.80 27MAY94 384.70 ; /* The following example code appears on p.152 */ proc print data=gold (obs=10); title 'Relative Strength of Gold over Time'; run; /* End of Example Code to Create Example 6, Chapter 5 */ /* Chapter 5, Example 7 */ /* The following example code appears on p.153 */ /* Use the AMEX1 Data Set, Appendix 1 */ /* and the Gold Data Set, Appendix 3 */ data am_gold; merge amex1 gold; by day; where day > '31dec93'd; /* Relative Strength Index (RSI) */ /* Relative to the AMEX */ rsi_gold=gold/close; /* Single Exponential Smoothing */ w1=.1; retain gold_exp; if _n_ = 1 then gold_exp=gold; else gold_exp=w1*gold+(1-w1)*gold_exp; run; proc print data=am_gold (obs=15); var day gold close rsi_gold; title 'Relative Strength of Gold to AMEX Close'; run; /* End of Example Code to Create Example 7, Chapter 5 */ /* Chapter 5, Display 11 */ /* GOPTIONS statement to produce high-resolution */ /* graphs as much as possible like those in book. */ goptions reset=global gunit=pct cback=white border htitle=6 htext=3 ftext=swissb colors=(black); /* The following example code does not appears in the book. */ /* Use the AM_GOLD Data Set, Created on p.143, Ch 5, Ex 7 */ proc gplot data=am_gold; where '31dec93'd < day < '14may94'd; plot gold * day gold_exp * day / overlay vaxis=axis1 haxis=ax