Project

Algorithmic Stock Trading Program

You will try your hand at simulated stock market trading! You will use historical stock market performance data for both Apple, Inc (stock: AAPL), and Microsoft, Inc (stock: MSFT) for over the last 15+ years. Only a minimal knowledge of stock trading is needed.

We will not attempt to deal with any of the deeper technicalities of stock trading; however, your project will attempt to make sensible buy, sell, or hold decisions on stock data you are processing.

Your program, as a simulation, will be fed this historical stock data to ‘replay’ the days of trading for that stock. You will have your program act as if days are passing (day 0, day 1, day 2, …, etc), albeit much, much faster. Each ‘day’, you will look back at previous days, and make decisions on how you intend to trade your stock that day (if at all.)

Your program will include a variety of functions, some you design entirely on your own simply because you need them, and others because I specified that you create them.

Central to your program will be two different functions in your code: one where I provide explicit rules for one stock trading algorithm and a second algorithm will be created using your own stock trading rules.

Milestones

This project will be broken up into multiple milestones, each cumulative to the milestones previous to it. This will pace your progress, and make certain you well understand each distinct component of your program.

  1. Milestone I: Data Preparation (34/100 points)

    Purpose: Read in the financial data into our Python program and organize the data for use.

  2. Milestone II: The “Moving Average” Trading Algorithm (33/100 points)

    Purpose: Design a function that performs the ‘moving average’ algorithm for stock trading.

  3. Milestone III: Your Own Designed Trading Algorithm (33/100 points)

    Purpose: Design your own interesting stock trading algorithm.

  4. Milestone IV: OOD and other Ideas [Extra Credit]

    Purpose: Provide some extra-credit opportunities. I’ll ask you to explore some intermediate-level concepts like Object-Oriented design, and Modules.

General Submission Requirements

Each milestone has requirements specific to itself, in addition to the general ones described below. Each milestone builds on the milestones previous to it! Remember, you are building up a full program, component-by-component.

This is not a group project, and all submitted work must be done individually (original, and unique to you.)

Submission Requirements

Please read and follow the Submission Requirements to avoid point deductions.

In addition, there are project specific requirements:

  1. Your project will be tested with at least two stock data sets from Yahoo Finance: Apple, and for Microsoft. I reserve the right to test it with stock data of other companies, so be sure your code understands this.

  2. A Python file project.py will be submitted as your program. Each milestone will require that you submit a file of this same name, building on the code from the previous submission.

    If you do the extra credit portion, project.py and tradinglib.py (optional; see extra credit) will be the expected file names.

  3. Your final submission must have at least the following functions defined:

    • main()
    • test_data(col, day)
    • alg_moving_average()
    • alg_mine()

    You will certainly write additional functions of your own design and choosing to help these four functions do their job!

  4. In addition to the above point, any prototype code needs to be used exactly as I gave it to you (function names, parameters and their names, docstrings, return values, etc.)

  5. The project cannot be submitted late. You have plenty of time to work on this, don’t squander it.

Grading Rubric
Type Description Point Loss (Max)
  [General]  
SyntaxError Exceptions A program that doesn’t even start due to syntax errors. -30
Docstrings Missing proper lab header (e.g. no name, lab section, etc) -10
main() Your program should have main() as the first-called function -10
PEP 8 Style Egregious problems with your code styling -10
Incorrect Filename Follow the submission instructions -5
Commenting Insufficient or excessive comments -5
  [Milestone I]  
Data File Your code should work with a pristine, unedited copy of the data I provided you, with the correct filename. Any changes to the data need to be done directly by your Python code. -10
Data Handling You are free to read in the data using any programming techniques you think works for you. Also, this data must be stored in a way that makes later referencing of stock price easy. -10
Bookkeeping The later milestones will need to know how much money and stocks you own in order to allow you to make sensible decisions. There needs to be appropriate code that will be used to keep track of both. -8
Testing

I will test your code, and therefore I require that you create a function named test_data() as specified above, where:

  • The function takes as arguments one string parameter of open, high, low, close, volume, and adj_close, and an integer for the day in the data you want to refer to.
  • The function returns the float value of the stock data for the particular column and day number.
-6
  [Milestone II]  
Simulation Code Your moving average trading simulation should be written according to the specification given. Some decisions are left to you, but the core algorithm should be honored. Your algorithm will not at any point look ahead at ‘future’ stock data. You can only use data for the days gone for making decisions in your simulation’s ‘current day’ -18
Data Handling Is your algorithm appropriately using the data you loaded from the CSV file? You will lose points if you use test_data() from Milestone I (it needs to be include, but not used.) -5
Bookkeeping Does your trading algorithm make the right decisions when buying and selling, and does it track this information appropriately. For example, you can’t sell if you own zero stocks! Things like this should be covered. -5
Testing I will test your code by calling your alg_moving_average(filename) function directly. It should run smoothly and return the two values specified of the correct data types (stocks: integer, cash: float). -5
  [Milestone III]  
Simulation Code Your custom trading simulation should be written according to the specification given. Most decisions are left to you, regardless Your algorithm will not at any point look ahead at ‘future’ stock data. You can only use data for the days gone for making decisions in your simulation’s ‘current day’ -18
Data Handling Is your algorithm appropriately using the data you loaded from the CSV file? -5
Bookkeeping Your trading function should appropriately use the groundwork built in Milestone I (or, updated afterwards for this Milestone). That is, does your trading algorithm make the right decisions when buying and selling, and does it track this information appropriately. For example, you can’t sell if you own zero stocks! Things like this should be covered. -5
Testing I will test your code by calling your alg_mine() function directly. It should run smoothly and return the two values specified of the correct data types (stocks: integer, cash: float). -5