class Security: def __init__(self, name, ticker, weight, country, region, currency, price, totalshares, eps, dps): self.name = name self.ticker = ticker self.weight = weight self.country = country self.region = region self.currency = currency self.price = price self.tso = totalshares #tso: total shares outstanding self.eps = eps self.dps = dps def toString(self): return self.ticker + ': ' + self.name fruitfolio = [] # a portfolio of only the juiciest holdings fruitfolio.append(Security("Avocado Assets", "GUAC LN", 15.23, 'UK', 'Europe', 'GBP', 200.03, 13.7, 5.92, 25.37)) fruitfolio.append(Security("Banana Billings", "BAN US", 13.29, 'USA', 'NA', 'USD', 93.44, 16.9, -3.61, 0)) fruitfolio.append(Security("Coconut Corp", "COCO US", 11.07, 'USA', 'NA', 'USD', 1335.07, 2.3, 10.96, 112.32)) fruitfolio.append(Security("Daikon Deliveries", "CH00989", 10.74, 'China', 'Asia', 'CNY', 34.47, 35.7, 1.17, 0)) fruitfolio.append(Security("Eggplant Enterprises", "EGGY JP", 9.25, 'Japan', 'Asia', 'JPY', 18160, 28.5, 417.67, 2008)) fruitfolio.append(Security("Fig Factories US", "FIGS US", 7.94, 'USA', 'NA', 'USD', 22.35, 40.8, -0.01, 0)) fruitfolio.append(Security("Grape Group UK", "GG LN", 7.72, 'UK', 'Europe', 'GBP', 47.35, 51, -0.69, 0.07)) fruitfolio.append(Security("Honeycrisp Holdings", 'HONY US', 6.65, 'USA', 'NA', 'USD', 103.05, 100.35, 0.47, 2.03)) fruitfolio.append(Security("Imbe Intelligence", "IMBE US", 6.38, 'USA', 'NA', 'USD', 72.47, 25.05, 2.43, 0)) fruitfolio.append(Security("Jackfruit Jets", "CH00123", 6.03, 'China', 'Asia', 'CNY', 68.87, 13.5, -2.34, 0)) fruitfolio.append(Security("Kiwi Konglomerate", "KIWI LN", 5.7, 'UK', 'Europe', 'GBP', 2.77, 50.2, 0.09, 0)) fxToUsdDictionary = {'USD': 1, 'GBP': .85, 'CNY': 6.35, 'JPY': 0.015} for security in fruitfolio: print(security.toString()) """ Give the position/holdings objects defined above write and call one or more functions to perform the following calculations: // Calculate Total Market Value (Price * Shares Outstanding) // Converts a local currency value to USD (local value * FX) // Calculate Price/Earnings (Price / Earnings Per Share (EPS)) // Calculate Dividend Yield (Dividend Per Share (DPS) / Price) // Groups a collection of positions by country // Groups a collection of positions by region // Filters a collection to show only the positions with a positive EPS // Filters a collection to show only positions with a total market value > one million // Calculates the position with the largest weight in each region // Calculates the the total market values in each region (one value per region) // Validate the portfolio weight adds up to 100; report over/under weight Thoughts on how to generalize some of the above functions to support future requirements with a view to: - Performance - Flexibility - Code Reuse """
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question