The code for the Super Simple Stock exercise is in superSimpleStock.py
.
Tests and test data are in test/superSimpleStockTest.py
and test/sample_data.csv
respectively.
-
Python 3.x
-
Additional modules not in the standard library can be installed with:
pip install python-dateutil
pip install pandas
import superSimpleStock
stock= superSimpleStock.Stock('test/sample_data.csv')
stock.get_dividend_yield(stock= 'POP', ticker_price= 3)
stock.get_pe_ratio(stock= 'POP', ticker_price= 3)
stock.record_trade(stock= 'POP', quantity= 10, sold= True, price= 5)
stock.record_trade(stock= 'POP', quantity= 11, sold= True, price= 6)
stock.record_trade(stock= 'POP', quantity= 12, sold= True, price= 7)
print(stock.trade)
stock.get_stock_price('POP')
stock.get_all_share_index()
python3 -m unittest test.superSimpleStockTest
If coverage is installed, run tests and report coverage with:
coverage run -m unittest test.superSimpleStockTest
coverage html --include='superSimpleStock*'
Coverage report will be in htmlcov
Or:
coverage report --include='superSimpleStock*'
Name Stmts Miss Cover
-----------------------------------------
superSimpleStock.py 64 3 95%
Author: Dario Beraldi
Date: 19/09/2018