Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python. Need help with this question, if you could explain the code it would be very much appreciated. Thanks! Question 4 A share is the

Python. Need help with this question, if you could explain the code it would be very much appreciated. Thanks!

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Question 4 A share is the single smallest denominations of a company's stock. For example: Assuming you own shares of 2 companies, below is your current stock holding. You own 3000 shares of DBS's stock and 5000 shares of SIA's stock. your current stock holding Stock unit price DBS 3000 22.360 SIA 5000 4.230 When a share of common stock of some company is sold, the capital gain (or, sometimes, loss) is the difference between the share's selling price and the price originally paid to buy it. This rule is easy to understand for a single share, but if we sell multiple shares of stock bought over a long period of time, then we must identify the shares actually being sold. A standard accounting principle for identifying which shares of a stock were sold in such a case is to use a FIFO protocolthe shares sold are the ones that have been held the longest indeed, this is the default method) 1. Use a deque data structure to store the stock holding. 2. Use a list data structure to hold the stock data. 3. Read the stock data from a text file named stock portfolio.csv. 4. Append the stock data into the list and push the list into the deque. 5. Print the current holding of stock (content of the deque). 6. Prompt user to enter a stock to sell. 7. Calculate the profit/loss using the FIFO protocol. 8. Print the profit/loss. 9. Print the updated stock holding. After successfully read in the data, your program should print the following and prompt user to enter the stock he wants to sell. Note that 3000 unit of DBS stock purchased at 22.360 was the oldest stock while Singtel 2000 units at 2.560 was the latest purchase. In a FIFO protocol, you should sell the oldest stock first. your current stock holding Stock unit price DBS 3000 22.360 SIA 5000 4.230 DBS 5000 25.230 Singtel 4000 3.180 DBS 3000 23.230 Singtel 1000 2.780 SIA 3000 5.230 Singtel 2000 2.560 What stock do you want to sell? Sample run #1 Selling 9000 units of DBS stock at $24.89 your current stock holding Stock unit price DBS 3000 22.360 SIA 5000 4.230 DBS 5000 25.230 Singtel 4000 3.180 DBS 3000 23.230 Singtel 1000 2.780 SIA 3000 5.230 Singtel 2000 2.560 A is the oldest purchased and is the most recent purchased. In FIFO protocol, shares from 'A' should be sold first, followed by shares in 'B', then shares in 'C your current stock holding Stack orice DBS 3eee 22.360 STA 500g 4.250 DBS 5000 25.230 DBS 23.230 sell all 3000 units and profit is 3000*price difference sell all 5000 units and profit is 5000* price difference sell 1000 units of DBS and profit is 1000* price difference get SIA Singtel what stock do you want to sell DBS, 9808,24.89 selling DBS, 9000 unit at $24.89 Need to maintain Your profit is 7550.0 the purchase your updated stock holding order The updated holding has 2000 DBS stock left 3eee 2000 3eee 2eee 5.230 2.560 Stock SIA Singte DBS Sites SIA Singtel unit 5000 422 2000 1888 3eee 2eee price 4.230 3.182 23.230 2.785 5.230 2.560 price difference is the difference between the selling and buying price. Sample run #2 Selling of a non holding stock your current stock holding Stock unit price DBS 3000 22.360 SIA 5000 4.230 DBS 5000 25.230 Singtel 4000 3.180 DBS 3000 23.230 Singtel 1000 2.780 SIA 3000 5.230 Singtel 2000 2.560 What stock do you want to sell? OUB, 1000, 23.9 You do not hold any OUB stock Sample run #3 Selling of a stock more than the holding number of units your current stock holding Stock unit price DBS 3000 22.360 SIA 5000 4.230 DBS 5000 25.230 Singtel 4000 3.180 DBS 3000 23.230 Singtel 1000 2.780 SIA 3000 5.230 Singtel 2000 2.560 What stock do you want to sell? SIA,9000,3.67 your holding of SIA is less than the number of units you want to sell. We will sell all your holdi ng (8000) units for you. Your profit is -7480.0 your updated stock holding Stock unit price DBS 3000 22.360 DBS 5000 25.230 Singtel 4000 3.180 DBS 3000 23.230 Singtel 1000 2.780 Singtel 2000 2.560

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spatial Databases With Application To GIS

Authors: Philippe Rigaux, Michel Scholl, Agnès Voisard

1st Edition

1558605886, 978-1558605886

More Books

Students also viewed these Databases questions

Question

What is the most important part of any HCM Project Map and why?

Answered: 1 week ago