Only the compilation of your submitted code will be tested. No tests have been added yet to check if your code also performs the required tasks. Your final submission before the deadline will be evaluated with automated tests and manually by the instructor for improvement.
In this exercise, we are programming a portfolio that manages financial shares. For this purpose, we define two classes, namely Share
(which represents a share) and Wallet
(which represents the share portfolio).
Share
ClassThe Share
class represents a single financial share and has the following instance variables:
The constructor of the Share
class initializes a share with a given symbol and quantity:
__init__(symbol, quantity)
Wallet
ClassCreate a Python class called Wallet
. It contains methods to add, remove, and retrieve share, as well as calculating the total value of the portfolio based on specified hare prices.
An object of the Wallet
class contains the following instance variable:
Share
class, representing different share in the portfolio.The constructor of the Wallet
class initializes an empty list of share.
__init__()
The Wallet
class contains methods to add and remove share:
# Add a new stock to the portfolio
def add_share(self, symbol, quantity)
# Remove a specific quantity of share from the portfolio
def remove_share(self, symbol, quantity)
For retrieving information about share, the following methods are available:
# Get the quantity of share for a given symbol
def get_share_quantity(self, symbol)
To calculate the total value of the portfolio based on specified stock prices, the class includes:
# Calculate the total value of the portfolio
def get_portfolio_value(self, prices)
Note: The get_portfolio_value
method considers only those share for which prices are specified and calculates the total value by multiplying the quantity of share by their corresponding price. Prices are specified in a list
of pairs (also a List
) with the stock symbol as the first element and the price as the second element.