Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need urgent help on coding this in python. Can someone please kindly assist? Thanks. :) Question 4 (15 marks) 1 A share is the

image text in transcribed

I need urgent help on coding this in python. Can someone please kindly assist? Thanks. :)

Question 4 (15 marks) 1 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.txt. 4. Append the stock data into the list and push the list into the deque. 1 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. The contents of stock portfolio.txt file is as follows: 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 u 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 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 DBS DBS 3000 your current stock holding Stack unit price DBS 3000 22.360 sell all 3000 units and profit is 3000*price difference SIA 5000 4.230 DBS 5000 25.230 sell all 5000 units and profit is 5000* price difference 23.230 sell 1000 units of DBS and profit is 1000* price difference SIA 3000 5.230 Singtel 2000 2.560 Need to maintain what stock do you want to sell DBS, 9000, 24.89 selling DBS,9000 unit at $24.89 Your profit is 7550.0 the purchase your updated stock holding order Stock unit price SIA 5000 4.230 Singtel 4000 3.189 DBS 2000 23.230 The updated holding has 2000 DBS stock left ger SIA 3000 5.230 Singtel 2000 2.560 T500 2.780 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 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 SIA 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 Please remember test out your following program with Sample 1, 2 and 3 as shown above. Remember to comment your code accordingly. Question 4 (15 marks) 1 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.txt. 4. Append the stock data into the list and push the list into the deque. 1 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. The contents of stock portfolio.txt file is as follows: 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 u 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 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 DBS DBS 3000 your current stock holding Stack unit price DBS 3000 22.360 sell all 3000 units and profit is 3000*price difference SIA 5000 4.230 DBS 5000 25.230 sell all 5000 units and profit is 5000* price difference 23.230 sell 1000 units of DBS and profit is 1000* price difference SIA 3000 5.230 Singtel 2000 2.560 Need to maintain what stock do you want to sell DBS, 9000, 24.89 selling DBS,9000 unit at $24.89 Your profit is 7550.0 the purchase your updated stock holding order Stock unit price SIA 5000 4.230 Singtel 4000 3.189 DBS 2000 23.230 The updated holding has 2000 DBS stock left ger SIA 3000 5.230 Singtel 2000 2.560 T500 2.780 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 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 SIA 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 Please remember test out your following program with Sample 1, 2 and 3 as shown above. Remember to comment your code accordingly

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

Transactions On Large Scale Data And Knowledge Centered Systems X Special Issue On Database And Expert Systems Applications Lncs 8220

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Stephen W. Liddle ,Klaus-Dieter Schewe ,Xiaofang Zhou

2013th Edition

3642412203, 978-3642412202

More Books

Students also viewed these Databases questions

Question

Describe a persuasive message.

Answered: 1 week ago

Question

Identify and use the five steps for conducting research.

Answered: 1 week ago

Question

List the goals of a persuasive message.

Answered: 1 week ago