Stevens Institute of Technology Assignment 1 FE 522 – C++ Programming in Finance Due Date: October 13, 2020 For every problem below, create a different project folder. You should then put all these...

1 answer below »
C++ programing assignment with two problems


Stevens Institute of Technology Assignment 1 FE 522 – C++ Programming in Finance Due Date: October 13, 2020 For every problem below, create a different project folder. You should then put all these folders inside a .zip file with your name before submitting everything in Canvas. Remember to delete the cmake-build-debug folders before doing so. This .zip file should be accompanied by a .pdf file containing a report (one single report for the whole assignment). We do not provide test cases for any of the problems, and these must be provided by you. When providing a solution to a problem, you must be able to present test cases alongside it, otherwise it will not be accepted as a valid solution. If a problem requires input and/or output files, please provide the whole file content (if not large) in the body of the report. If the file is too large to be pleasantly presented in a report (larger than a page), please provide a sample. You should include these files in folders named "input" and "output", respectively, in the root folder of each project. In order for your code to work on any machine (not only yours), use relative paths to these files in your source code: • for input files, use: "../../input/filename.txt" • for output files, use: "../../output/filename.txt" Problem 1 (20 points). Study the documentation in http://en.cppreference.com/w/cpp/ numeric/random. Choose 5 different random number distributions, generate a sample of 10, 000 numbers with each of them, and create a table (output to a file) with their mean, median, and standard deviation. Problem 2 (20 points). Implement the following methods to find the root of a function and test them with a polynomial function of your choice: (a) Bisection method (https://en.wikipedia.org/wiki/Bisection_method). (b) Secant method (https://en.wikipedia.org/wiki/Secant_method). 1 http://en.cppreference.com/w/cpp/numeric/random http://en.cppreference.com/w/cpp/numeric/random https://en.wikipedia.org/wiki/Bisection_method https://en.wikipedia.org/wiki/Secant_method
Answered Same DayOct 05, 2021

Answer To: Stevens Institute of Technology Assignment 1 FE 522 – C++ Programming in Finance Due Date: October...

J Anitha answered on Oct 10 2021
142 Votes
PROBLEM1
1) Uniform real distribution
#include
#include
#include
using namespace std;
int main()
{
double a[10010];
long double sigmax = 0;
long double sigmaxx = 0;
long int n = 10000;
ofstream outf("UD.txt");
random_device rd;
mt19937 mt(r
d());
uniform_real_distribution dist(20.0, 22.0); //range is 20 to 22
for (int i = 0; i < 10000; ++i)
{
a[i] = dist(mt);
}
for (long int j = 0; j < 10000; ++j)
{
sigmax = sigmax + a[j];
sigmaxx = sigmaxx + pow(a[j], 2);
}
for (long int i = 0; i < n - 1; i++)
for (long int j = 0; j < n - i + 1; j++)
{
if (a[j] > a[j + 1])
{
double t;
t = a[j];
a[j] = a[j + 1];
a[j + 1] = t;
}
}
long double Median = a[n / 2];
long double mean = sigmax / n;
long double ss = pow(mean, 2);
long double SD = sqrt((sigmaxx / n) - ss);
outf << "RandomDistributionName" ;
outf << "Median";
outf << "Mean";
outf << "Standard Deviation";
outf << endl;
outf << "Uniform real distribution ";
outf.width(10);
outf << Median;
outf.width(10);
outf << mean;
outf.width(10);
outf << SD;
outf << endl;
outf << "END";
outf.close();
ifstream infile("/UD.txt");
infile >> Median;
infile >> mean;
infile >> SD;
cout << Median << "\t" << mean <<"\t" << SD;
infile.close();
return 0;
}
21.031 21.0176 0.57777    
Content of file UD.txt
Uniform real distribution 21.021 21.0114 0.58081
2. Uniform Int distribution
#include
#include
#include
using namespace std;
int main()
{
long int a[10010];
long double sigmax = 0;
long double sigmaxx = 0;
long int n = 10000;
random_device rd;//Will be used to obtain a seed for the random number engine
mt19937 gen(rd()); //Standard mersenne_twister_engine seeded with rd()
uniform_int_distribution<> distrib(1, 100);
for (long int i = 0; i < 10000; ++i)
{
//Use `distrib` to transform the random unsigned int generated by gen into an int in [1, 6]
//cout << distrib(gen) << ' ';
a[i] = distrib(gen);

}
for (long int j = 0; j < 10000; ++j)
{
sigmax = sigmax + a[j];
sigmaxx = sigmaxx + pow(a[j], 2);
}
for (long int i = 0; i < n - 1; i++)
for (long int j = 0; j < n - i + 1; j++)
{
if (a[j] > a[j + 1])
{
double t;
t = a[j];
a[j] = a[j + 1];
a[j + 1] = t;
}
}
long double Median = a[n / 2];
long double mean = sigmax / n;
long double ss = pow(mean, 2);
long double SD = sqrt((sigmaxx / n) - ss);
ofstream outf("ID.txt");
outf << "RandomDistributionName ";
outf << "Median ";
outf << "Mean ";
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here