C++ programming
Part II: Programming (50 points) Question 3 (10 points) In main create two double arrays of size 100 named Notionals and PaymentYears . The aim of this project is to create a tool to calculate the net present value (NPV) of a sequence of future to store the sequence of cash-flows and years to payment Then write some code to request these cash-flows and years to payment from the user. Note that you will only loop NumberOf Cashflows times and not 100, cash-flows such as: the full size of the arrays (so most of the array is left unused). Use a sensible name for the loop variable, f15,000 f15,000 f15,000 f15,000 like int iCashFlow. Question 4 (10 points) Create a variable called NPVOfCashFlows and initialise it to zero. Then in a loop calculate the present value (PV) of each cash-flow (with formula (2)) and add to NPVOfCashFlows as in 3 T (in years) formula (3). Display the PV of each of the cash-flows and then the net PV, NPVOfCashFlows. Question 5 (10 points) Calculate the effective duration of the sequence of cash-flows. This is defined as f14,126.47 = 15,000 x e-3x2% ONPV/ar f14,411.84 = 15,000 x e-2x2% V = - NPV (4) f14,702.98 = 15,000 x e-1x2% To calculate (4) I suggest you calculate ON PV/Or in the same loop in which you calculate the NPV. Note L15,000.00 = 15,000 x e-0x2% that by differentiating (3) we get: ONPV NPV = $58,241.29 ar FYI: the duration is meant to represent some form of average of the different dates Ti,. .., In weighted . We will use continuously compounded interest, r. This means that the discount factor to T years is according to the PV of the cash paid on that date. It only makes sense if cash-flows N, are positive as defined as: otherwise you could have NPV=0 and (4) would break down.] Df = e-TT. (1) where r is the (continuously compounded) interest rate. Screenshot . Although in the real world supply and demand forces make interest rates to different dates be different, You should aim at producing a program that displays input/output as follows: we will assume that all interest rates are the same value, r, so as to simplify the exercise. . The present value of a single cash-flow of EN paid at time T years is then NPV CALCULATOR PV = N . Df = N . e-T. (2) Please provide the number of cash-flows (between 1 and 100) : 4 If you have a sequence of n cash-flows N1, . . . Nn to Ti, ..., In years then the formula to calculate the net present value, NPV, is: INPUT DATA FOR CALCULATIONS NPV = > Nie-Thi. Please provide the interest rate () : 2 (3) Please provide information for cash-flow 0 Notional: 15000 Make sure that you follow best coding policies such as: do not use non-const global variables, use Years to Payment : 0 nformative file and variable names, use of const whenever possible, appropriate choice of data type (int, Please provide information for cash-flow 1 double etc), consistent indentation, new lines and spacing. You do not need to have more than one . cpp Notional: 15000 file or any header files for this project. Years to Payment : 1 Please provide information for cash-flow 2 Question 1 (10 points) Write a function named GetNumberOfCashflows that asks the user how many cash- Notional: 15000 flows they would like to price. The user should be told that the number of cash-flows must be between 1 Years to Payment: 2 and 100. The function should have type Please provide information for cash-flow 3 Notional: 15000 int GetNumberOfCashflows () Years to Payment: 3 In main () call this function, assign its result to a variable named NumberOf Cashflows and exit the program PRESENT VALUE REPORT with an informative error message if the number provided is not between 1 and 100 (both included). PV for cash-flow 0 is: 15000 To avoid the use of magic numbers you should save the number 100 as a const int global variable named PV for cash-flow 1 is: 14703 laximumNumberOfCashFlows and avoid explicit use of the number 100 elsewhere in your program PV for cash-flow 2 is: 14411.8 PV for cash-flow 3 is: 14126.5 Question 2 (10 points) In main () write some code to get the interest rate from the user and save it in a The NPV of the sequence of cash-flows is 58241.3 variable called InterestRate. Then write a function named GetDiscountFactor that implements formula The effective duration of the sequence of cash-flows is 1.475 1). It should have signature: Press any key to continue . . . double GetDiscountFactor (double InterestRate, double YearsToPayment) 3