Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

junglebooboo

Help with python stock portfolio tracker first meeting with objects on my own

  • one year ago
  • one year ago

  • This Question is Open
  1. junglebooboo
    Best Response
    You've already chosen the best response.
    Medals 0

    Hi I'm trying to make a python stock portfolio tracker, so far I have made two attempts, and got stuck at both of them, any tips? #1 # Stock portfolio tracker import datetime def welcome(): print "Welcome to the stock portfolio tracker" print "Let's hope it works this time" class Stock(object): # Creates and saves a portfolio of stocks def __init__(self, date, price, number_of_shares): # Initialises the portfolio and takes three arguments self.date = date self.price = price self.number_of_shares = number_of_shares def __str__(self): # Creates a string representation of the portfolio # and prints requested values return "date purchased :%s, Price: %s, Number_of_shares %s" %( self.date, self.price, self.number_of_shares) def getPurchaseValue(self): # Computes the purchase value as price per share x number of shares return (self.price * self.number_of_shares) def getSaleValue(self, salePrice): # Computes the sale value as price per share * shares return (self.salePrice * number_of_shares) class Portfolio(Stock): # Creates a portfolio of collected stocks def __init__(self, stockName): self.stockName = stockName portfolio = [] def addStock(self): newStock = raw_input('What is the company ticker?') name = raw_input('Enter the ticker of the stock to add') price = raw_input('Enter the price of the stock') shares = raw_input('How many shares to add?') newstock[name, price, shares] def main(): welcome() MSFT = Stock(10,10,10) print MSFT

    • one year ago
  2. junglebooboo
    Best Response
    You've already chosen the best response.
    Medals 0

    #2 # New attempt at creating a portfolio of stocks class DataBook(object): def __init__(self, price, shares, date): self.price = price self.shares = shares self.date = date self.get_info() def get_info(self): sf = \ """ price = %s shares = %s date = %s """ return sf %(self.price, self.shares, self.date) def main(): name_dic = {} ticker = raw_input("What is the company's ticker?") price = int(raw_input('What was the price?')) shares = raw_input('how many shares did you buy?') date = raw_input(' When did you buy it?') name_dic[ticker] = DataBook(price, shares, date) main()

    • one year ago
  3. junglebooboo
    Best Response
    You've already chosen the best response.
    Medals 0

    Any feedback will be greatly appreciated=)

    • one year ago
  4. rsmith6559
    Best Response
    You've already chosen the best response.
    Medals 1

    In Stock.getSaleValue() where does self.salePrice come from? In Portfolio.addStock, what is newstock[name, price, shares]? Square brackets are for lists, parentheses are for functions. DataBook.get_info has a formatted string, but no variables substituted in. main() looks like it would be setting up a dictionary, but name_dic is a list. Advice: Develop you classes independently. It helps to develop/debug them one at a time, and if you're hoping to reuse them it forces you to make them separate.

    • one year ago
    • Attachments:

See more questions >>>

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.