Stevens Institute Of Technology Assignment 1fe 522 C Program
Stevens Institute Of Technology Assignment 1fe 522 C Programming
Implement solutions for five programming problems involving calculator enhancements, random number generation, a money class, an options pricing class, and file processing of options data. The tasks include modifying a calculator to handle braces and factorials, generating sample moments from different distributions, designing precise financial classes for monetary calculations, implementing the Black & Scholes model for European options, and processing options data from a TSV file to compute and append option prices.
Paper For Above instruction
The assignment encompasses a series of interrelated programming problems aimed at strengthening understanding of C/C++ programming in financial contexts, emphasizing correctness, precision, and file handling. Each problem builds on core programming skills such as expression parsing, object-oriented design, randomness, and file I/O, with an emphasis on accuracy, safety, and usability in real-world applications.
Problem 1: Enhancing a Desk Calculator with Brackets and Factorial
The first problem involves extending a previous calculator implementation to support additional features. Initially, the calculator handles basic arithmetic expressions with parentheses. The task requires updating the grammatical rules and parsing logic to accommodate curly braces {} alongside parentheses () for grouping. This enhancement offers more flexible expression input, aligning with typical mathematical notation where different brackets are often used interchangeably for grouping.
Additionally, the calculator must be extended to support a factorial operator represented by a suffix !. The factorial should bind tighter than multiplication and division, following conventional precedence rules, so that expressions like 78! are interpreted as 7(8!). For the factorial calculation, only integers are valid; thus, for non-integer input, truncation should be applied. The factorial of zero, by definition, is one, ensuring compliance with mathematical standards.
Problem 2: Statistical Sampling from Random Distributions
Using the numeric/random library, generate 1,000 samples from five different random number distributions, such as uniform, normal, exponential, binomial, and gamma distributions. For each distribution, compute the sample mean and standard deviation, representing the first two moments. The results should be compiled into a table, then output to a file, facilitating comparative analysis. This task emphasizes understanding of statistical properties and effective file I/O for data presentation.
Problem 3: Designing a Money Class for Accurate Financial Calculations
Create a Money class to handle monetary computations involving dollars and cents, stored internally as a long int representing total cents. Input and output should be handled in dollar-and-cent format with a dollar sign, ensuring accurate representation and display. The class must implement arithmetic operators: addition, subtraction, multiplication, and division, carefully maintaining cent-level precision and applying the 4/5 rounding rule; that is, values with fractional cents of 0.5 or more should be rounded up, else down.
Further, the class should support I/O operators >/> and for reading from and writing to streams, respectively. Extending functionality, the class should accommodate different currencies, such as USD and EUR, with constructors accepting currency codes. When input includes currency labels, the system must parse and store this information, and output should include the currency for clarity. This design ensures versatility and correctness in computations involving multiple monetary standards.
Problem 4: Implementing a EuropeanOption Class Using Black-Scholes
Develop a EuropeanOption class modeling European call and put options, incorporating properties such as option type, spot price, strike price, interest rate, volatility, and time to maturity. Proper validation must reject invalid inputs. The class must implement a getPrice() method that calculates the option's fair value using the Black & Scholes formula.
The implementation will utilize the cumulative distribution function (CDF) of the standard normal distribution, accessible via existing libraries (e.g., or ). The computational formulas involve calculating the parameters d1 and d2 and applying the Black-Scholes equations for call and put options. Precise handling of parameters and edge cases is critical for accuracy, especially for near-zero time to maturity or extreme volatility.
Problem 5: Processing Option Data from a TSV File and Computing Prices
Create a program that reads at least ten lines of tab-separated values (TSV) containing options data, including option type, spot price, strike, interest rate, volatility, and time to maturity. This data is used to instantiate a vector of EuropeanOption objects. The program then computes the price for each option using the class from Problem 4 and outputs a new file, identical to the input but with an additional column for the option prices.
This process involves robust file parsing, data validation, object creation, iterative calculations, and formatted output. The solution emphasizes the integration of class design with file operations, ensuring the program handles real data effectively and accurately.
References
- Press, W.H., Teukolsky, S.A., Vetterling, W.T., & Flannery, B.P. (2007). Numerical Recipes: The Art of Scientific Computing. 3rd Edition. Cambridge University Press.
- Black, F., & Scholes, M. (1973). The Pricing of Options and Corporate Liabilities. Journal of Political Economy, 81(3), 637-654.
- Johnson, N.L., & Kotz, S. (1970). Distributions in Statistics: Continuous Univariate Distributions. Wiley.
- Lehmann, E.L., & Casella, G. (1998). Theory of Point Estimation. Springer.
- Press, W. H. (2002). Numerical Recipes in C: The Art of Scientific Computing.
- Warwick, K. (2011). Random Number Generation and Monte Carlo Methods. Wiley.
- Hall, P. (2014). The Bootstrap and Edgeworth Expansion. Springer.
- Hull, J.C. (2018). Options, Futures, and Other Derivatives. 10th Edition. Pearson.
- Shreve, S.E. (2004). Stochastic Calculus for Finance II: Continuous-Time Models. Springer.
- Wiener, N. (1938). The Homogeneous Chaos. American Journal of Mathematics.