Module: Portfolio and Stock Exchange

exception pyalpha.portfolio.portfolio.InputError(expression, message)[source]

Exception raised for errors in the input.

Attributes:

expression :
Input expression in which the error occurred
message : string
Explanation of the error
class pyalpha.portfolio.portfolio.StockExchange[source]

A StockExchange object handles the database containing portfolio details of users.

Attributes:

users : dictionary
Contains name of the user as the key, with corresponding UserPortfolio object as the value

Methods:

- add_user(self, person_name, initial_balance)
- view_log(self, symbol, start_date, end_date, start_time, end_time)
add_user(person_name='', initial_balance=0)[source]

Adds an user along with his/her balance to the database

view_log(symbol=None, start_date=datetime.date(1, 1, 1), end_date=datetime.date(2016, 11, 22), start_time=datetime.time(0, 0), end_time=datetime.time(23, 59, 59, 999999))[source]
  • View the log of the transactions which occured in the whole stock exchange by all the users
  • All the date and time input parameters should be in the respective datetime.date and datetime.time formats
Returns:pandas.DataFrame object which can be printed to view the log of transactions
class pyalpha.portfolio.portfolio.UserPortfolio(person_name, initial_balance)[source]

A UserPortfolio object will provide access to handle the portfolio of a single person.

Parameters:

person_name : string
Name of the person
initial_balance : float or int
Initial balance in the person’s portfolio

Attributes:

name : string
Name of the person whose portfolio is being handled
balance : float
Current balance in the person’s portfolio

Methods:

- add_funds(self, deposit)
- buy_stock(self, symbol, quantity)
- sell_stock(self, symbol, quantity)
- view_portfolio(self)
- view_log(self, symbol, start_date, end_date, start_time, end_time)
add_funds(deposit)[source]

Increases balance in the account by the specified amount.

buy_stock(symbol, quantity)[source]
  • Buy the given quantity of stock specified by symbol
Returns:
  • True if the transaction is successful
  • False otherwise
sell_stock(symbol, quantity)[source]
  • Sell the given quantity of stock specified by symbol
Returns:
  • True if the transaction is successful
  • False otherwise
view_log(symbol=None, start_date=datetime.date(1, 1, 1), end_date=datetime.date(2016, 11, 22), start_time=datetime.time(0, 0), end_time=datetime.time(23, 59, 59, 999999))[source]
  • View the log of the transactions which occured in the user’s portfolio
  • All the date and time input parameters should be in the respective datetime.date and datetime.time formats
Returns:pandas.DataFrame object which can be printed to view the log of transactions
view_portfolio()[source]
  • View list of stocks owned, their quantities and value
Returns:pandas.DataFrame object which can be printed to view the portfolio of the person