An investor’s stock portfolio consists of four Exchange Traded Funds (SPY, QQQ, EEM, and VXX). Write a program that requests the amount invested in each fund as input and then displays the total amount invested and each fund’s percentage of the total amount invested

Respuesta :

Answer:

The solution code is written in Python 3

  1. SPY = float(input("Enter SPY Amount: "))
  2. QQQ = float(input("Enter QQQ Amount: "))
  3. EEM = float(input("Enter EEM Amount: "))
  4. VXX = float(input("Enter VXX Amount: "))
  5. totalAmount = SPY + QQQ + EEM + VXX
  6. print("Total amount invested: $" + str(totalAmount))
  7. print("Percentage invested for SPY: " + str(SPY / totalAmount * 100) + "%")
  8. print("Percentage invested for QQQ: " + str(QQQ / totalAmount * 100) + "%")
  9. print("Percentage invested for EEM: " + str(EEM / totalAmount * 100) + "%")
  10. print("Percentage invested for VXX: " + str(VXX / totalAmount * 100) + "%")

Explanation:

Firstly, let's declare four variables, SPY, QQQ, EEM and VXX and use input() function to prompt user to input the amount invested in each fund (Line 1 - 4).

Next, sum up all the funds' amount and assign the total to totalAmount variable (Line 6).

Next display the total amount invested and the percentage invested for each fund using print function (Line 7 - 11). Please note the formula to calculate the percentage of investment is

(fund / totalAmount ) * 100

ACCESS MORE
ACCESS MORE
ACCESS MORE
ACCESS MORE