assignment16fda

.pdf

School

Northeastern University *

*We aren’t endorsed by this school

Course

6400

Subject

Industrial Engineering

Date

Jan 9, 2024

Type

pdf

Pages

4

Uploaded by vishalbunty01

Report
assignment16fda December 9, 2023 Question 1: Compound Interest Comparison Using Matrix Operations [1]: # Importing necessary libraries import numpy as np import pandas as pd import matplotlib.pyplot as plt # Generate the dataset np . random . seed( 0 ) # For reproducibility num_scenarios = 10 principal_amounts = np . random . uniform( 1000 , 5000 , num_scenarios) annual_rates = np . random . uniform( 0.01 , 0.1 , num_scenarios) years = np . random . randint( 1 , 30 , num_scenarios) # Create a DataFrame data = { 'Principal' : principal_amounts, 'Annual Rate' : annual_rates, 'Years' : years } df = pd . DataFrame(data) # Show the DataFrame print (df . head()) Principal Annual Rate Years 0 3195.254016 0.081255 19 1 3860.757465 0.057601 4 2 3411.053504 0.061124 25 3 3179.532732 0.093304 18 4 2694.619197 0.016393 20 Matrix Representation [2]: matrix_representation = df . values print ( " \n Matrix Representation:" ) print (matrix_representation) 1
Matrix Representation: [[3.19525402e+03 8.12552534e-02 1.90000000e+01] [3.86075747e+03 5.76005428e-02 4.00000000e+00] [3.41105350e+03 6.11240105e-02 2.50000000e+01] [3.17953273e+03 9.33036974e-02 1.80000000e+01] [2.69461920e+03 1.63932452e-02 2.00000000e+01] [3.58357645e+03 1.78416370e-02 2.00000000e+01] [2.75034885e+03 1.18196558e-02 2.00000000e+01] [4.56709200e+03 8.49357861e-02 1.50000000e+01] [4.85465104e+03 8.00341076e-02 8.00000000e+00] [2.53376608e+03 8.83010933e-02 1.00000000e+00]] Compound Interest Calculation [7]: def compound_interest_matrix (principal, rate, time): return principal * ( 1 + rate) ** time future_values = compound_interest_matrix(matrix_representation[:, 0 ], matrix_representation[:, 1 ], matrix_representation[:, 2 ]) df[ 'Future Value' ] = future_values [8]: df [8]: Principal Annual Rate Years Future Value 0 3195.254016 0.081255 19 14097.489180 1 3860.757465 0.057601 4 4830.134008 2 3411.053504 0.061124 25 15032.875885 3 3179.532732 0.093304 18 15837.914842 4 2694.619197 0.016393 20 3730.205881 5 3583.576452 0.017842 20 5104.120595 6 2750.348845 0.011820 20 3478.964670 7 4567.092003 0.084936 15 15513.160187 8 4854.651042 0.080034 8 8987.890731 9 2533.766075 0.088301 1 2757.500390 Interpretation [9]: best_investment = df . loc[df[ 'Future Value' ] . idxmax()] print ( " \n Best Investment Scenario:" ) print (best_investment) average_future_value = df[ 'Future Value' ] . mean() print ( " \n Average Future Value:" , average_future_value) df_doubled_period = df . copy() df_doubled_period[ 'Years' ] = df_doubled_period[ 'Years' ] * 2 2
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help