Exemple #1
0
    def test_add_stock(self):
        p1 = Portfolio(first_name="Julin", last_name="Patel")
        p1.add_stock("APPL", 1, 170)
        p1.add_stock("SPY", 2, 270)

        self.assertEqual(p1.stock_tick_opt, {"APPL": 1, "SPY": 2})
        self.assertEqual(p1.stock_tick_avg, {"APPL": 170, "SPY": 270})
Exemple #2
0
    def test_sell_stock(self):
        p5 = Portfolio(first_name="James", last_name="Doland")
        p5.add_stock("T", 1, 170)
        p5.add_stock("SPHD", 2, 270)

        p5.sell_stock("SPHD", 1)

        self.assertEqual(p5.stock_tick_opt, {"T": 1.0, "SPHD": 1.0})
        self.assertEqual(p5.stock_tick_avg, {"T": 170.0, "SPHD": 270.0})
Exemple #3
0
    def test_get_stock_opt(self):
        p1 = Portfolio(first_name="Julin", last_name="Patel")
        p1.add_stock("APPL", 1, 170)
        p1.add_stock("SPY", 2, 270)

        self.assertIsNotNone(p1.get_stock_opt())
Exemple #4
0
def main():
    fl_name = True
    while fl_name:
        print("Welcome! Lets start by creating your portfolio: \n")
        first_name = input("Please enter your first name: ")
        first = True
        while first:
            for char in first_name:
                if not char.isalpha():
                    print("Please enter only Alpha characters. \n")
                    first_name = input("Please enter your first name: ")
                else:
                    first = False
        last_name = input("Please enter your last name: ")
        last = True
        while last:
            for char in last_name:
                if not char.isalpha():
                    print("Please enter only Alpha characters. \n")
                    last_name = input("Please enter your last name: ")
                else:
                    last = False

        new_portfolio = Portfolio(first_name, last_name)
        fl_name = False
        main_menu = True
        while main_menu:
            print("Main Menu: \n")
            print("1. Manually Add a Stock \n")
            print("2. Manually Sell a Stock \n")
            print("3. Import stock profile from Robinhood \n")
            print("4. View Portfolio \n")
            print("5. Exit Program \n")

            try:
                user_selection = int(input("Selection: "))
                if user_selection == 1:
                    ticker = input("Please enter in ticker symbol: ")
                    num_shares = input("Please enter in number of share(s): ")
                    avg_cost = input(
                        "Please enter in the average cost per share: ")
                    new_portfolio.add_stock(ticker, num_shares, avg_cost)
                elif user_selection == 2:
                    ticker = input("Please enter in ticker symbol: ")
                    num_shares = input("Please enter in number of share(s): ")
                    new_portfolio.sell_stock(ticker, num_shares)
                elif user_selection == 3:
                    username = input(
                        "Please enter your Robinhood account username: "******" Password Error!")
                    try:
                        new_portfolio.get_robin_data(username, str(password))
                    except Exception as e:
                        print(e, "Account information invalid. \n")
                elif user_selection == 4:
                    new_portfolio.get_portfolio()
                elif user_selection == 5:
                    print("Thank You for using this program! \n")
                    break
                else:
                    print("Your input is incorrect. \n")
            except Exception as e:
                print(e, "Incorrect input")