The objective for assignment 2 is to continue to build the trading system that was started in assignment 1 with new requirements and changes. The focus will be on developing visualizations to show the trader time-series and analytics.
The new trading system will have the same requirements as assignment 1 but with the following additional requirements or modifications:
The application will be entirely web-based using Flask or any other Python-based web framework
The user interface does not need to be attractive but neat, clean and organized. Using a framework like Bootstrap is permissible. If you are going to use a design motif, stick to a “flat” modern theme.
If you are new to web programming then stick to pure HTML5.
Blotter data will be persisted into a database. You are free to decide what database what you wish, but a NoSQL database (MongoDB, DynamoDB, etc.) is preferred. You will not lose or gain points for choosing / not choosing a particular database.
The universe of equities the trader can choose from will go from 5 to the full set of equities available to trade on the NASD exchange
http://www.nasdaq.com/screening/companies-by-industry.aspx?exchange=NASDAQ
The data needs to be loaded only once on startup and does not need to be loaded on a recurring basis.
Trading
Blotter
The blotter will be persisted in a database and can be cached using data structures
The blotter will have a new column called Cash . The cash column will have the net cash balance after the trade represented by that row in the blotter.
P/L
The P/L data will be stored using pandas DataFrames
Add a column called “Total P/L” which is the sum of UPL and RPL
Add a column called Allocation By Shares which is the percentage of shares for this stock over total shares in the whole portfolio
Add a column called Allocation By Dollars which is the percentage of dollars this position has over total dollars in the market for the whole portfolio
Basic analytics
Visualizations
After the trader selects the stock s/he wishes to trade, display the 100-day trade history chart.
Use any charting library you wish: Matplotlib, D3.js
Collaboration (except sharing code) for this Visualizations section is allowed as long as it is open to all students to see i.e. on #general or #assignment2 channel or Blackboard forum
Intraday trading last 100 trades are web scraped from NASDAQ website
Last 100 days OLHC data is web scraped from GOOGLE finance website
Current price is web scraped from Bloomberg Markets
Application is developed using
The application is developed using Python data structures. Most of the web scraping is done using packages requests and BeautifulSoup (bs4). For persistence, data is stored in the Sqlite database. It is accessed using object-relational mapper (ORM) SQLAlchemy. Web pages use the Bootstrap framework. Tables are exposed as classes.
Graphs on the website are developed using Matplotlib package.
Application source code uploaded to GitHub https://github.com/akulapa/data602-assignment2. Currently, it is set up as a private folder (course requirement).
Docker image is created with empty Sqlite database traders.db. Image is uploaded to Docker Cloud and can be downloaded using the following command
docker pull akulapa/ubuntu1604:data602-assignment2
After downloading, to create a Docker container execute the following
docker run -v /etc/localtime:/etc/localtime:ro -p 8080:5000 akulapa/ubuntu1604:data602-assignment2
-v option sets local time inside docker container using time from the host machine. The application runs on the port 5000 inside the container and is mapped to 8080 while accessing the website.
http://localhost:8080
Once Docker container is started and on first access of website, complete symbol list is downloaded from NASDAQ website. The downloaded file is saved to the folder. After saving the file it is uploaded into the Sqlite database, tickerData table. Additionally, Symbols can be refreshed anytime by clicking on top right button Ticker List Update.
/usr/src/data602-assignment2/app/instance/temp/tickerlist.csv
Home page for the application is displayed as follows.
Available funds is displayed on each page.
The symbol can be keyed in manually or by using the searchable drop down. Enter Key or click on Search button will get traders to the details page. Symbol validation is done against the list downloaded from NASDAQ website. If Symbol does not exist in the list following message is displayed.
Stock basic information
Graphs
The graph is scatter plot displaying the amount of shares sold at a certain price in last 100 trades.
The graph shows price movement over time.
Graph shows change in closing price in last 100 days. Price at the beginning of the 100th day is considered as starting price. Closing price below starting price is in red and above is in green.
Candlestick graph is a whisker plot showing daily OHLC. And also momentum over a period of 100 days.
Above graph shows five days Simple Moving Average (SMA) of closing price. The average is calculated using rolling and mean function from pandas package. Standard deviation known as Volatility is calculated using rolling and std function.
df['SMA'] = df['Close'].rolling(5).mean()
df['Volatility'] = df['Close'].rolling(5).std()
Above graph shows five days Exponential Moving Average (EMA) of the closing price. The average is calculated using ewn and mean function from pandas package. Standard deviation known as Volatility is calculated using ewn and std function.
df['EMA'] = df['Close'].ewm(span=int(5), adjust=False).mean()
df['Volatility'] = df['Close'].ewm(span=int(5), adjust=False).std()
Table displays data about last 100 trades.
Table displays OHLC data for last 100 days.
Table displays 5 day Simple Moving Average(SMA) and Volatility.
Table displays 5 day Exponential Moving Average (EMA) and Volatility.
This table gives information about Major Indexes, namely NASDAQ, NYSE and S&P 500.
The table shows the stock trading volume of last 100 trades and also the average volume for last five and ten days.
The table shows information about last closing price. It is based on closing price. Intraday trading information is not used in the calculations.
Based on analytical information provided on the page, the trader can either buy or sell a stock. To complete a transaction trader needs to select the type of transaction and quantity, and then click on gavel button. Validation is done on transaction selected, and the quantity entered
- cannot be negative
- has to be numeric
- cannot be greater than current balance while selling
- cannot exceed current available funds can afford, (quantity * current price <= available funds)
If submitted data fails during validation a message is shown on the screen as displayed below.
Overall complete screen is displayed in above format.
Once the trade is executed successfully trader is redirected to home page with the message on top of the page.
Profit and Loss page
The screen shows information about stocks in the portfolio. While opening the page, the current price for each Symbol is applied by extracting it from Bloomberg Markets website. It also calculates
Page has 3 tabs P/L Statement, Allocation by Shares and Allocation by Dollars.
Above table displays P/L Statement.
Above graph displays Shares Allocation in portfolio.
Above graph displays Dollar Amount Allocation in portfolio.
Blotter page
Page displays every tranasction that is executed successsfully. It also has graph showing Cash On Hand after every trade.
Table displays every trade that is executed.
Graph displays Cash On Hand after every trade.