afoster28 / opt_portfolio_variance

Option portfolio variance in CPP
0 stars 0 forks source link

Create separate test program that calculates a matrix with % differences based on generated output result_matrix.csv and relevant table in output_small.txt #23

Closed afoster28 closed 7 months ago

secoman commented 7 months ago

Formatting_Differencing.txt

afoster28 commented 7 months ago

Nice initial version. I'm getting the following error:

An error occurred: stod

afoster28 commented 7 months ago

Can you make the inputs dynamic, i.e. ask the user to provide the name of the model output and expected output?

Change result to decimal instead of * 100 and limit to 2 decimal places

secoman commented 7 months ago

Updated Formatting_Differencing.txt

afoster28 commented 7 months ago

Doesn't compile - please check

afoster28 commented 7 months ago

Enter the name of the model output CSV file: result_matrix.csv Enter the name of the expected output CSV file: output_small.txt Error converting string to double: stod Error converting string to double: stod Error converting string to double: stod Error converting string to double: stod Error converting string to double: stod Error converting string to double: stod Difference matrix has been saved to difference_matrix.csv

secoman commented 7 months ago

// Improved readMatrixFromCSV (tried to handle errors) needs integrating std::vector<std::vector> readMatrixFromCSV(const std::string& filename) { std::vector<std::vector> matrix; std::ifstream file(filename); std::string line;

while (std::getline(file, line)) {
    std::vector<double> row;
    std::istringstream ss(line);
    std::string value;

    while (std::getline(ss, value, ',')) {
        try {
            row.push_back(std::stod(value));
        } catch (const std::invalid_argument& ia) {
            // Handling or logging invalid argument error
            continue; // Skipping this value
        }
    }

    matrix.push_back(row);
}

return matrix;

}

int main() { std::string inputFilename, expectedFilename; std::cout << "Enter the input CSV filename: "; std::cin >> inputFilename; std::cout << "Enter the expected output filename: "; std::cin >> expectedFilename;

// Use these filenames where needed in the rest of opt_v9

}

afoster28 commented 7 months ago

Still doesn't compile - can you fix and upload the entire script?

secoman commented 7 months ago

Comparison.txt

Having trouble with the error:

Enter model output file name: result_matrix.csv Enter expected output file name: output_small.txt terminate called after throwing an instance of 'std::invalid_argument' what(): stod

secoman commented 7 months ago

diff.txt

Fixed it. It should work.

secoman commented 7 months ago

image difference_matrix.csv

secoman commented 7 months ago

DIFF.xlsx