Student 1 Student 2

#include <stdio.h> #include <stdlib.h> #include <math.h> #include <string.h> #define DATAINPUT 1800 #define FHANDLE "table.txt" void encoding1(double*); void encoding2(double*); void encoding3(double*,int); int vectorsizes[] = {5,25,50,100}; void main(int argc, char *argv[]) { int i; FILE *f; double table[DATAINPUT]; double *in; f = fopen(FHANDLE,"r"); in = table; for(i = 0; i < DATAINPUT; i++){ fscanf(f,"%lf\n", in++); } encoding1(table); encoding2(table); } //input xi corresponds to the adjusted close i days in the past void encoding1(double *table){ int i; int j; int k; FILE *f; char *t; int tableindex; int length; for(k = 0; k < sizeof(vectorsizes)/sizeof(int); k++) { length = vectorsizes[k]; t = calloc(18, sizeof(int)); sprintf(t, "%dencoding1.txt", length); f = fopen(t,"w"); j=0; tableindex = 0; fprintf(f, "\n"); while(tableindex + length * 2 <= DATAINPUT){ for(i = tableindex + length; i < length * 2 + tableindex; i++){ fprintf(f, "%lf, ", table[i]); } for(i = tableindex + length - 1; i >= tableindex; i--){ fprintf(f, "%lf, ", table[i]); } fprintf(f, "\n"); tableindex += length * 2; j++; }

rewind(f); fprintf(f, "%d\n",j);

fclose(f); } } //input xi corresponds to the gain or loss in adjusted closes between i and i+1 days in the past void encoding2(double *table){ int i; int j; int k; FILE *f; char *t; int tableindex; int length; for(k = 0; k < sizeof(vectorsizes)/sizeof(int); k++) { length = vectorsizes[k]; t = calloc(18, sizeof(int)); sprintf(t, "%dencoding2.txt", length); f = fopen(t,"w"); j=0; tableindex = 0; fprintf(f, "\n"); while(tableindex + length * 2 + 1<= DATAINPUT){ for(i = tableindex + length + 1; i < length * 2 + tableindex; i++){ fprintf(f, "%lf, ", table[i]); } for(i = tableindex + length; i >= tableindex; i--){ fprintf(f, "%lf, ", table[i-1] - table[i]); } fprintf(f, "\n"); tableindex += length * 2 + 1; j++; }

rewind(f); fprintf(f, "%d\n",j);

fclose(f); } } //input xi corresponds to the ratio of adjusted closes between i //and i+K days in the past, where K is another parameter to vary void encoding3(double *table, int k){ }


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

#include <stdlib.h> #include <math.h> #include <string.h> #include <iostream> #include <fstream> #define FILENAME "tsxdata.txt" #define DATASIZE 1800 using namespace std; void createAdjustedCloseDataSet(double *inputData); void createAdjustedCloseDifferenceDataSet(double *inputData); void createAdjustedCloseRatioDataSet(double *inputData, int k); int vectorSizes[] = {5,25,50,100}; int main( void ) { ifstream fileIn; double *dataTable = (double*)calloc(DATASIZE, sizeof(double)); fileIn.open(FILENAME); for(int i = 0; i < DATASIZE; i++) { fileIn >> dataTable[i]; } createAdjustedCloseDataSet(dataTable); createAdjustedCloseDifferenceDataSet(dataTable); createAdjustedCloseRatioDataSet(dataTable, 5); createAdjustedCloseRatioDataSet(dataTable, 10); createAdjustedCloseRatioDataSet(dataTable, 15); createAdjustedCloseRatioDataSet(dataTable, 20); createAdjustedCloseRatioDataSet(dataTable, 25); createAdjustedCloseRatioDataSet(dataTable, 50); createAdjustedCloseRatioDataSet(dataTable, 100); int x = 0; } void createAdjustedCloseDataSet(double *inputData) { ofstream outFile; int numVectors = 0; for(int i = 0; i < sizeof(vectorSizes)/sizeof(int); i++) { int vectorLength = vectorSizes[i]; char *filename = (char*)calloc(18, sizeof(char)); sprintf(filename, "adjCloseSet%d.csv", vectorLength); outFile.open(filename); for(int tableIndex = 0; tableIndex + vectorLength * 2 < DATASIZE; tableIndex += vectorLength * 2) { for(int i = tableIndex + vectorLength - 1; i >= tableIndex; i--) { outFile << inputData[i] << ", "; } for(int i = tableIndex + vectorLength; i < vectorLength * 2 + tableIndex; i++) { outFile << inputData[i] << ", "; } outFile << "\n"; numVectors++; } //outFile.seekp(0, ios::beg); //outFile << numVectors << "\n"; outFile.close(); } } void createAdjustedCloseDifferenceDataSet(double *inputData) { ofstream outFile; int numVectors = 0; for(int i = 0; i < sizeof(vectorSizes)/sizeof(int); i++) { int vectorLength = vectorSizes[i]; char *filename = (char*)calloc(22, sizeof(char)); sprintf(filename, "adjCloseDiffSet%d.csv", vectorLength); outFile.open(filename); for(int tableIndex = 0; tableIndex + vectorLength * 2 < DATASIZE; tableIndex += vectorLength * 2) { for(int i = tableIndex + vectorLength - 1; i >= tableIndex; i--) { if(i > 0) outFile << inputData[i] - inputData[i-1] << ", "; else outFile << "0, "; } for(int i = tableIndex + vectorLength; i < vectorLength * 2 + tableIndex; i++) { if(i > 0) outFile << inputData[i] - inputData[i-1] << ", "; else outFile << "0, "; } outFile << "\n"; numVectors++; } //outFile.seekp(0, ios::beg); //outFile << numVectors << "\n"; outFile.close(); } } void createAdjustedCloseRatioDataSet(double *inputData, int k) { ofstream outFile; int numVectors = 0; for(int i = 0; i < sizeof(vectorSizes)/sizeof(int); i++) { int vectorLength = vectorSizes[i]; char *filename = (char*)calloc(26, sizeof(char)); sprintf(filename, "adjCloseRatioSet%d-%d.csv", vectorLength, k); outFile.open(filename); for(int tableIndex = 0; tableIndex + vectorLength * 2 < DATASIZE; tableIndex += vectorLength * 2) { for(int i = tableIndex + vectorLength - 1; i >= tableIndex; i--) { if(i-k > 0) outFile << inputData[i]/inputData[i-k] << ", "; else outFile << "0, "; } for(int i = tableIndex + vectorLength; i < vectorLength * 2 + tableIndex; i++) { if(i-k > 0) outFile << inputData[i]/inputData[i-k] << ", "; else outFile << "0, "; } outFile << "\n"; numVectors++; } //outFile.seekp(0, ios::beg); //outFile << numVectors << "\n"; outFile.close(); } }