Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is the file of data to read in: stock portfolio.txt (please indicate how to read in data of file) DBS,3000,22.36 SIA,5000,4.23 DBS,5000,25.23 Singtel,4000,3.18 DBS,3000,23.23

image text in transcribed

image text in transcribed

This is the file of data to read in: stock portfolio.txt (please indicate how to read in data of file)

DBS,3000,22.36

SIA,5000,4.23

DBS,5000,25.23

Singtel,4000,3.18

DBS,3000,23.23

Singtel,1000,2.78

SIA,3000,5.23

Singtel,2000,2.56

image text in transcribed

image text in transcribed

image text in transcribed

Note: Please give explanations for all your codes so I can understand the qn better

Please do the following for me: + Organized and easy flowing

+efficeint in terms of time complexity and length of code

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 A is the oldest purchased and is the most recent purchased. B 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 In FIFO protocol, shares from 'A' should be sold first, followed by shares in 'B', then shares in 'C' your current stock holding Stack unit price DBS 3000 22.360 SIA 50810 4.230 DBS co 5080 25.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 23.230 what stock do you want to sell DBS, 9000, 24.89 selling DBS,9000 unit at $24.89 DBS 3000 get *** SIA 3000 5.230 Singtel 2000 2.560 Need to maintain the purchase Your profit is 7550.0 your updated stock holding order Stock unit price SIA 5000 4.230 3.18 DBS 2000 23.238 Singer T808 2.788 SIA 3000 5.230 Singtel 2000 2.560 Singtel ABRA The updated holding has 2000 DBS stock left 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? QUB, 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 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 A is the oldest purchased and is the most recent purchased. B 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 In FIFO protocol, shares from 'A' should be sold first, followed by shares in 'B', then shares in 'C' your current stock holding Stack unit price DBS 3000 22.360 SIA 50810 4.230 DBS co 5080 25.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 23.230 what stock do you want to sell DBS, 9000, 24.89 selling DBS,9000 unit at $24.89 DBS 3000 get *** SIA 3000 5.230 Singtel 2000 2.560 Need to maintain the purchase Your profit is 7550.0 your updated stock holding order Stock unit price SIA 5000 4.230 3.18 DBS 2000 23.238 Singer T808 2.788 SIA 3000 5.230 Singtel 2000 2.560 Singtel ABRA The updated holding has 2000 DBS stock left 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? QUB, 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

Logidata+ Deductive Databases With Complex Objects Lncs 701

Authors: Paolo Atzeni

1st Edition

354056974X, 978-3540569749

More Books

Students also viewed these Databases questions

Question

=+4. Are there any disadvantages to this approach?

Answered: 1 week ago

Question

What is order of reaction? Explain with example?

Answered: 1 week ago

Question

Derive expressions for the rates of forward and reverse reactions?

Answered: 1 week ago

Question

Write an expression for half-life and explain it with a diagram.

Answered: 1 week ago