home *** CD-ROM | disk | FTP | other *** search
- /* 10:15 04-Jul-88 (conv.c) Convert RAW Stock Prices to Scaled Prices */
-
- /************************************************************************
- * Copyright(C) 1988 Neural-Ware Inc *
- * 103 Buckskin Court, Sewickley, PA 15143, United States of America *
- * *
- * All rights reserved. No part of this program may be reproduced, *
- * stored in a retrieval system, or tramsmitted, in any form or by any *
- * means, electronic, mechanical, photocopying, recording or otherwise *
- * without the prior written permission of the copyright owner, *
- * Neural-Ware, Inc. *
- ************************************************************************
- */
-
- /************************************************************************
- * *
- * Convert RAW stock prices to SCALED stock prices *
- * *
- ************************************************************************
- To use this program:
-
- CONV input.file output.file
-
- It will take the input file, one data item per input line, and
- re-scale them to the range 0.1 to 0.9. This was used for both
- the stock prediction and noise filtering examples. In the case of
- noise filtering, only the output files are provided.
-
- If no arguments are given, it assumes "sp500.nnz" as input and
- "sp500.in" for output.
- */
-
- #include <stdio.h>
- #undef max
- #undef min
-
- main( ac, av )
- int ac; /* # of input arguments */
- char **av; /* array of pointers to the arguments */
- {
- FILE *ifp; /* input file pointer */
- FILE *ofp; /* output file pointer */
- float flt; /* work number for sscanf */
- double max, min; /* max and min of input */
- double scale, offset; /* computed scale and offset */
- char *ifn, *ofn; /* input file name and output file name */
-
- if ( ac > 2 ) {
- ifn = av[1];
- ofn = av[2];
- } else {
- ifn = "sp500.nnz";
- ofn = "sp500.in";
- }
- ifp = fopen( ifn, "r" ); /* raw input prices */
- ofp = fopen( ofn, "w" ); /* scaled output prices */
-
- if ( ifp == (FILE *)0 ) {
- fprintf( stderr, "Could not open input file <%s>\n", ifn );
- exit( 1 );
- }
-
- if ( ofp == (FILE *)0 ) {
- fprintf( stderr, "Could not open output file <%s>\n", ifn );
- exit( 1 );
- }
-
- /* compute the minimum and maximum price in the input file */
-
- max = 0.0;
- min = 9999999.0;
- while( fscanf( ifp, "%f", &flt ) == 1 ) {
- if ( flt < min ) min = flt;
- if ( flt > max ) max = flt;
- }
-
- /* compute scaling so that new prices vary from 0.1 to 0.9 */
-
- scale = 0.8 / (max - min);
- offset = 0.1 - scale * min;
-
- /* tell the user what scale and offset we are using */
-
- fprintf( stderr, "scale = %.4f, offset = %.4f\n", scale, offset );
-
- /* re-parse the input file and convert prices */
-
- fseek( ifp, 0l, 0 );
- while( fscanf( ifp, "%f", &flt ) == 1 ) {
- fprintf( ofp, "%.3f\n", flt*scale + offset );
- }
-
- /* close the input and output files */
-
- fclose( ifp );
- fclose( ofp );
- }
-