High Frequency Trading Assignment

From Knowledge Kitchen
Jump to navigation Jump to search


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.

Requirements

General

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).

Threshold calculation

The threshold value is calculated according to a simple formula that your boss is convinced will win every time:

  1. take the average of the stock's performance over the last 4 days
  2. multiply that by the lucky number from your boss's fortune cookie at lunchtime minus 1,
  3. 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.

Input validation

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
Wal-Mart WMT $75.75 $76.16 $76.15 $76.23 $76.30
Coca-Cola KO $38.53 $38.75 $38.78 $38.77 $38.85
Procter & Gamble PG $78.37 $79.24 $79.34 $79.45 $79.58
Berkshire Hathaway BRK/A $172,500.00 $173396.00 $173490.00 $173762.00 $$173.471.99
Exxon-Mobile XOM $87.44 $87.78 $88.72 $87.36 $89.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!


What links here