pyrtfolio.Stock

class pyrtfolio.Stock.Stock(stock_symbol, stock_country, purchase_date, num_of_shares, cost_per_share)

Stock is a support class of pyrtfolio which validates the Stocks before adding them to StockPortfolio.

This class is a support class to validate the Stocks before finally adding them to the portfolio created in StockPortfolio since the historical data of the introduced Stock needs to be retrieved and, so on, it will error if the introduced Stock is not valid.

stock_symbol

symbol of the Stock that is going to be added to the StockPortfolio.

Type:str
stock_country

country from where the specified stock_symbol is, so to validate it.

Type:str
purchase_date

date when the shares of the introduced stock were bought, formatted as dd/mm/yyyy.

Type:str
num_of_shares

amount of shares bought of the specified Stock in the specified date.

Type:int
cost_per_share

price of every share of the Stock in the specified date.

Type:float
valid

either True or False if the Stock is valid or not, respectively.

Type:boolean
__init__(stock_symbol, stock_country, purchase_date, num_of_shares, cost_per_share)

This is the init method of Stock class which is launched every time the user instances it.

This method is the init method of this class, Stock, and its main function is to init all the attributes contained in it, as previously defined when the function add_stock() was called from StockPortfolio. The specified values in this class are going to be accessed through the self operator whenever the validation function is called, since it is the main function of this class, validating Stocks.

Parameters:
  • stock_symbol (str) – symbol of the Stock that is going to be added to the StockPortfolio.
  • stock_country (str) – country from where the specified stock_symbol is, so to validate it.
  • purchase_date (str) – date when the shares of the introduced stock were bought, formatted as dd/mm/yyyy.
  • num_of_shares (int) – amount of shares bought of the specified Stock in the specified date.
  • cost_per_share (float) – price of every share of the Stock in the specified date.
__weakref__

list of weak references to the object (if defined)

validate()

Method used to validate that the introduced Stock is valid before adding it to the StockPortfolio.

This method is the one in charge of the validation of the introduced Stock via checking the introduced data with the one indexed in investpy, so to check if the data match. Also, the introduced parameters are checked in order to determine if the type is correct of those values is correct, if not, an exception will be raised. The result of this function is just setting either True or False to the self.valid value if the Stock is valid or not, respectively.