Package: portfolio-report-Sealeon
Stock PortfolioThis assignment will test the following skills:Reading and writing to the file systemMaking HTTP requestsTesting read & write operations to the diskTesting HTTP requests using a mock libraryPackaging the script usingsetup.pyDescriptionWrite a program which will generate up-to-date performance reports for a given
stock portfolio. The program will accept two arguments: an input CSV file which
contains the holdings information, and, a path to output the CSV report.We will use theIEX Trading API, as
the market data source â€“ it is a public (free) API.RequirementsThe program will read a CSV file containing our portfolio data. Based on this
data, a new CSV report will be generated using live market value to indicate
our current holding performance using the IEX API.The program will be installable usingpip, and requires asetup.pyfile. When installed, a binary will be added to the Python path which can be
invoked from anywhere on the filesystem.An example interaction with the script looks like this:$ portfolio_report --source portfolio.csv --target report1.csvInput fileThe input CSV will have 3 columns (example provided).symbol: the ticker symbol (e.g. AAPL is Apple)units: the quantity of shares heldcost: the original / average purchase price of the holdingExample:symbolunitscostAAPL1000123.56AMZN202001.1Using the list of symbols from the input CSV, get quotes from IEX to fetch the
latest price. This can be done in a batch request â€“ meaning, multiple quotes
can be requested in a single HTTP request. See:Docs:https://iextrading.com/developer/docs/#topsExample request & responseExample request: GET the latest quotes for Apple, Facebook & Snapchat:https://api.iextrading.com/1.0/tops/last?symbols=AAPL,AMZN,SNAP[{"symbol":"AAPL","price":204.29,"size":100,"time":1563307196175},{"symbol":"AMZN","price":2008.395,"size":1,"time":1563307196058},{"symbol":"SNAP","price":15,"size":100,"time":1563307196047}]Once the latest price is obtained, a series of calculations are made to
establish the current performance of the portfolio: what the current market
value is, the gain and loss for each holding and a percentage of change.If a symbol listed in the input CSV is not found on the exchange, the IEX API
ignores it. Your script should account for this situation by warning the user
that the symbol was not found, but continue to process the rest of the valid
symbols.Output fileThe expected CSV report will have the following columnssymbol: The stock ticker symbol (i.e. AAPL)units: The amount of shares heldcost: The original cost per sharelatest_price: The latest market price per sharebook_value: The value of the shares at time of purchasemarket_value: The value of the shares based on the latest market valuegain_loss: The dollar amount either gained or lostchange: A percentage (decimal) of the gain/lossSample output CSVsymbolunitscostlatest_pricebook_valuemarket_valuegain_losschangeAAPL1000123.56156.23123561562332670.264AMZN202001.11478.194002229563-10459-0.261Getting startedTake a modular approach to completing this assignment and build each functional
component in isolation, accompanied by appropriate tests.Here is a breakdown of isolated functional units:Given a filename, read a CSV and convert it to a Python data structureBuild a method which returns the latest market price for holdingsBuild methods which calculate the book value, market valueBuild a method to convert the holding into CSVBuild a method that writes to the output filename.TestingTesting against third-party services can be challenging as they are out of our
control. As developers, we must build our application with the expectation of
specific behaviours from these services. Mocks (faking) are a handy way to
isolate the dependency and replace it with a constant to which we can build
tests. For this, we will use therequests-mocklibrary to stub out
HTTP requests.https://requests-mock.readthedocs.io/en/latest/pytest.htmlInstall usingpip install requests-mock.As for writing files, use thetmp_pathfixture that ships with pytest to
write to temporary locations on the disk.Make sure to updaterequirements.txtand include any libraries required
to build this project (e.g.requests,requests-mock) so they are available
to Travis CI.PackagingAs described above, provide asetup.pyconfiguration to package your
application. Ensure that dependencies required to run your script are included
(e.g. requests)Evaluation rubricMetric43210Meets requirementsAll requirements are metAlmost all requirements are metMost requirements met, some bugsIncorrect results, several bugsProgram does not workTestingUnit tests are present and cover all functionalityMost of the script is covered by testingPartial test coverage, some false assertions presentMinimal testing, false assertions present, missing main functional coverage.No meaningful tests existPackaging & deliveryThe project is properly packaged, documented and can be installed using pip.The project is packaged, but is missing certain metadataThe project is installable, but with some issues. Documentation is incomplete.Documentation is partial, the package does not installNo packaging present, little or no documentationReusabilityThe code could be reused as a whole and each routine could be reusedMost of the code could be reused in other programsSome parts of the code could be reused in other programsA few parts of the code could be reused in other programsThe code is not organized for reusabilityReadabilityThe code is well organized and very easy to understandThe code is pretty well organized and fairly easy to readThe code has some organization, is a challenge to readThe code is readable only by someone who knows what it is supposed to doThe code is poorly organized and very difficult to read