代写Algorithms and Data Structures I Project 5: The Stock Market帮做Java编程

Algorithms and Data Structures I

Project 5: The Stock Market

Background

The stock market allows investors to buy shares of publicly-traded companies. Investors can make a profit by selling shares they own for a higher price than what they paid. Profit is calculated as:

profit = (price_sold - price_bought) * num_shares

For example, if I buy 2 shares of company A for $5 each, and then a week later sell them for $8 each, I have made $6 in profit: $8 - $5 = $3 and $3 * 2 shares = $6.

Unfortunately, stock prices don’t just go up. Sometimes a stock will be bought and then sold at a lower price for a loss. For example, I can buy 3 shares of company X at $10 each, and then sell all three shares later on for $4 each. This would net me ($4 - $10) * 3 = - $18.

In this project, share transactions, or Trades, hold the following information:

-    TradeType: whether the investor bought or sold shares

-     Lot: a group of shares

Each Lot contains the following information:

-    Ticker: which company the shares are for

-    quantity: how many shares are in the lot

-    pricePerShare: the price for each share in the Lot

Lots of shares (that’s Lots with a capital L) must be sold in the order they were bought, also known as first in first out (FIFO). This means we should use a Queue to represent a history of Trades.

For example, take this history of Trades:

When selling shares in Trade 3, the first 20 of the 30 sold shares must come from Trade 1. This means that the shares from Trade 1 are sold at a profit of $2 per share or $40 total.

Trade 3 still has 10 shares left to sell. These 10 must now come from the Lot in Trade 2. They are sold at a profit of $6 per share, or $60 total.

The total profit from selling 30 shares in Trade 3 is $40 from Trade 1 +  $60 from Trade 2 = $100 total profit for Ticker AAA.

Exercise

Your job is to complete the implementation of the Portfolio class, which extends the PortfolioInterface.

The Portfolio class starts with two private fields (you can add more if youd like):

-    Hash Map> positions

-    Maps Tickers to a Queue of Lots that were purchased by the Portfolio. Because the Lots are stored in a Queue, the first Lots removed from the Queue are the first that must be sold.

-    Note: Java’s Queue is an abstract class. You can use the java .util .ArrayDeque when adding new Queues to the positions HashMap.

-    Hash Map profits

-    Maps Tickers to their total amount of profit (or loss) so far. Every time a Lot is sold, the

profits map should be updated to reflect change in profits or losses from that Lot’s Ticker.

The PortfolioInterface lists a few methods that you are responsible for implementing:

-    void handleTrade(Trade trade)

-    Process a single Trade. If it is a BUY, then shares are added to the portfolio. If it is a SELL, then shares must be removed from the portfolio in the order they were received and the profits must   be calculated and updated.

- Note: You can safely assume that calls to handleTrade() that SELL shares will only ever happen when the Portfolio has enough shares of that Ticker to sell. The shares might be split across multiple Lots, but there will always be enough to sell.

-    void handleTrades(List trades)

-    Processes a list of Trades from the beginning of the list to the end. Trades in this list might sell shares that were bought in Trades located earlier in the list.

-    double getProfit(Ticker ticker)

-    Returns the net profit for all sales involving shares from Ticker

-    double getTotal Profit()

-    Returns the net profit for the entire Portfolio, that is, the sum of profits for every Ticker.

-    int getSharesHeld(Ticker ticker)

-    Returns the number of shares that the portfolio holds for Ticker. Ex: if a Portfolio sells all of its shares for a given Ticker, calling getSharesHeld afterwards must return 0.

Starter Code

The Starter Code for Project 5 is located here. Here is a rundown of each starter file:

-    Ticker.java

-    Represents a hashable Ticker for a company (ex: Apple’s stock ticker is “AAPL”, Google’s is “GOOG”)

-     Lot.java

-    Represents a group (or Lot”) of shares. Includes the Ticker of the company, the quantity of shares in the Lot, and the price per share.

- Note: There is a setQuantity() method in the event that a Lot has to be split up during a partial sale (see example with company AAA above)

-    Trade.java

-    Represents a trade of one Lot of shares. Has a TradeType (either BUY or SELL) and a Lot.

-     PortfolioInterface.java

-    The Interface that the Portfolio class must implement. Each method in this file has a descriptive comment explaining what the method should do.

-     Portfolio.java

-    An implementation of the PortfolioInterface that you will complete for this project.

-     Project5.java

-    A driver program that creates a Portfolio and buys and sells some Lots of shares.

-    You can either run Project.java directly (java Project5) or with a filename argument (java Project5 trades .csv) and it will bulk-handle a CSV file of Trades

-    trades.csv

-    A comma-separated-values (CSV) file containing 200 fictional Trades. You can test your work by running java Project5 trades .csv.

Sample Output

Running java Project5 should yield:

I own 10 shares of AAA

I own 0 shares of AAA

Profits : 150 .0

I own 10 shares of BBB

I own 0 shares of BBB

Profits from : -25 .0

Total Profits : 125 .0

Running java Project5 trades .csv should yield:

Company AAA :

Profit to-date : 12466 .91

Shares still holding : 115

Company BBB :

Profit to-date : -3735 .2899999999995

Shares still holding : 175

Company CCC :

Profit to-date : 15712 .980000000003

Shares still holding : 340

Company DDD :

Profit to-date : 2355 .6000000000004

Shares

still holding : 123

Company

EEE :

Profit

Shares

to-date : 17877 .830000000005

still holding : 198

Company

FFF :

Profit

Shares

to-date : -639 .2

still holding : 87

Company

GGG :

Profit

to-date : 33356 .09

Shares still holding : 209

Total profits from 200 Trades : 77394 .92

Deliverables

You are responsible for submitting only Portfolio.java. All other files must remain unchanged.


热门主题

课程名

mktg2509 csci 2600 38170 lng302 csse3010 phas3226 77938 arch1162 engn4536/engn6536 acx5903 comp151101 phl245 cse12 comp9312 stat3016/6016 phas0038 comp2140 6qqmb312 xjco3011 rest0005 ematm0051 5qqmn219 lubs5062m eee8155 cege0100 eap033 artd1109 mat246 etc3430 ecmm462 mis102 inft6800 ddes9903 comp6521 comp9517 comp3331/9331 comp4337 comp6008 comp9414 bu.231.790.81 man00150m csb352h math1041 eengm4100 isys1002 08 6057cem mktg3504 mthm036 mtrx1701 mth3241 eeee3086 cmp-7038b cmp-7000a ints4010 econ2151 infs5710 fins5516 fin3309 fins5510 gsoe9340 math2007 math2036 soee5010 mark3088 infs3605 elec9714 comp2271 ma214 comp2211 infs3604 600426 sit254 acct3091 bbt405 msin0116 com107/com113 mark5826 sit120 comp9021 eco2101 eeen40700 cs253 ece3114 ecmm447 chns3000 math377 itd102 comp9444 comp(2041|9044) econ0060 econ7230 mgt001371 ecs-323 cs6250 mgdi60012 mdia2012 comm221001 comm5000 ma1008 engl642 econ241 com333 math367 mis201 nbs-7041x meek16104 econ2003 comm1190 mbas902 comp-1027 dpst1091 comp7315 eppd1033 m06 ee3025 msci231 bb113/bbs1063 fc709 comp3425 comp9417 econ42915 cb9101 math1102e chme0017 fc307 mkt60104 5522usst litr1-uc6201.200 ee1102 cosc2803 math39512 omp9727 int2067/int5051 bsb151 mgt253 fc021 babs2202 mis2002s phya21 18-213 cege0012 mdia1002 math38032 mech5125 07 cisc102 mgx3110 cs240 11175 fin3020s eco3420 ictten622 comp9727 cpt111 de114102d mgm320h5s bafi1019 math21112 efim20036 mn-3503 fins5568 110.807 bcpm000028 info6030 bma0092 bcpm0054 math20212 ce335 cs365 cenv6141 ftec5580 math2010 ec3450 comm1170 ecmt1010 csci-ua.0480-003 econ12-200 ib3960 ectb60h3f cs247—assignment tk3163 ics3u ib3j80 comp20008 comp9334 eppd1063 acct2343 cct109 isys1055/3412 math350-real math2014 eec180 stat141b econ2101 msinm014/msing014/msing014b fit2004 comp643 bu1002 cm2030
联系我们
EMail: 99515681@qq.com
QQ: 99515681
留学生作业帮-留学生的知心伴侣!
工作时间:08:00-21:00
python代写
微信客服:codinghelp
站长地图