High Frequency Trading Assignment
You work as a well-paid financial analyst at a giant "too-big-to-fail" financial institution. Your boss, who is working towards a big cash bonus this year, instructs you to create a new algorithm that will determine whether a particular blue chip stock should be bought or sold, based on its current value.
The program must allow a trader to enter in a stock's symbol, its current price, and a lucky number (see the validation rules for these inputs below). The program then outputs a recommendation to either buy, sell, or hold the stock. The recommendation is based on whether the current stock price is above, below, or equal to a particular threshold value specific to that stock (see more on the threshold below).
The threshold value is calculated according to a simple formula that your boss is convinced will win every time:
- take the average of the stock's performance over the last 4 days
- multiply that by the lucky number from your boss's fortune cookie at lunchtime minus 1,
- then divide the result by the same lucky number from the fortune cookie.
If the current price is above the resulting threshold value, the program should tell the user to sell. If the current price is below the threshold value, the program should tell the user to buy. If the current price is equal to the threshold value, the program should instruct the user to hold the stock.
The program must include the following validation:
- the user must enter the dollar sign $ before the current stock price (e.g. "$75.75")
- the program must ignore case in the stock symbol (e.g. "WMT" is treated same as "wmt")
- the lucky number must be any positive integer
- if the user enters an invalid price, stock symbol, or lucky number, the program must inform the user that the input is invalid and gracefully exit
Example stock data
For starters, as a proof-of-concept to show the firm's upper management, your boss wants your program to work with the example stock data displayed below.
|Company||Stock symbol||Current price||Price 1 day ago||Price 2 days ago||Price 3 days ago||Price 4 days ago|
|Procter & Gamble||PG||$78.37||$79.24||$79.34||$79.45||$79.58|
Example input and output
The following is an example of a session with the program. Data displayed is For Position Only (FPO), and not meant to be real data. User responses are in bold:
Welcome to the Lucky Fortune Trading Algorithm! Enter the lucky number from lunch today: 17 Enter the stock symbol: WMT Enter the current price: $75.75 ......calculating..... .......crunching...... ........hang on....... This stock is undervalued. BUY!