Martingale

From Quantitative Analysis Software Courses
Revision as of 12:00, 16 August 2018 by Tucker (talk | contribs) (→‎Tasks)
Jump to navigation Jump to search

Revisions

2018-8-11

  • Project is in DRAFT.

Overview

The purpose of this assignment is to get you started programming in Python right away and to help provide you some initial feel for risk, probability and "betting." Purchasing a stock is, after all, a bet that the stock will increase in value.

In this project you will evaluate the actual betting strategy that Professor Balch uses at roulette when he goes to Las Vegas. Here it is:

  • winnings = $0
  • while winnings < $80:
    • won = False
    • bet_amount = $1
    • while not won
      • wager bet_amount on black
      • won = result of roulette wheel spin
      • if won == True:
        • winnings = winnings + bet_amount
      • else:
        • winnings = winnings - bet_amount

Here are some details regarding how roulette betting works: Betting on black (or red) is considered an "even money" bet. That means that if you bet N chips and win, you keep your N chips and you win another N chips. If you bet N chips and you lose then those N chips are lost. The odds of winning or losing depend on whether you're betting at an American wheel or a European wheel. For this project we will be assuming an American wheel. You can learn more about roulette and betting here: https://en.wikipedia.org/wiki/Roulette

Tasks

Set up your development environment

First, if you haven't yet set up your software environment, follow the instructions here: ML4T_Software_Setup. The base directory structure for all projects in the class, including supporting data and software are will be set up correctly when you follow those instructions.

Get the template code for this project

This project is available here: File:18fall martingale.zip. Download and extract its contents into the base directory (ML4T_18fall). Once you've done this, you should see the following directory structure:

  • ML4T_18fall/: Root directory for course
    • data/: Location of data
    • grading/: Grading libraries used by the individual grading scripts for each assignment.
    • util.py: Common utility library. This is the only allowed way to read in stock data.
    • martingale/: Root directory for this project
      • martingale.py: Main project file to use as a template for your code.

You should change ONLY martingale.py. ALL of your code should be in that one file. Do not create additional files. It should always remain in and run from the directory ML4T_2018Fall/martingale/. Leave the copyright information at the top intact.

Insert your GT User ID and GT ID number

Revise the code functions author() and gtid() to correctly include your GT User ID and 9 digit GT ID respectively. Your GT User ID should be something like tbalch78 and your GTID is a 9 digit number. You should also update this information the comments section at the top.

Build a simple gambling simulator

Revise the code in martingale.py to simulate 1000 successive bets on spins of the roulette wheel using the betting scheme outlined above. You should test for the results of the betting events by making successive calls to the get_spin_result(win_prob) function. Note that you'll have to update the win_prob parameter according to the correct probability of winning. You can figure that out by thinking about how roulette works (see wikipedia link above).

Track your winnings by storing them in a numpy array. You might call that array winnings where winnings[0] should be set to 0 (just before the first spin). winnings[1] should reflect the total winnings after the first spin and so on.

Make some charts

For the following charts, and for all charts in this class you should use python's matplotlib library. You should configure your code to write the

Run your simple simulator 10 times, and track the winnings, starting from 0 each time. Plot each run on one chart using matplotlib functions.

Done til here

Rubric

report only... the rest of this is not updated yet.

10 test cases: We will test your code against 10 cases (10 points per case). Each case will be deemed "correct" if:

  • 5 points: Sharpe ratio = reference answer +- 0.001
  • 2.5 points: Average daily return = reference answer +- 0.00001
  • 2.5 points: Cumulative return = reference answer +- 0.001

Required, Allowed & Prohibited

Required:

  • Your project must be coded in Python 2.7.x.
  • Your code must run on one of the university-provided computers (e.g. buffet02.cc.gatech.edu).
  • Use the code for reading in historical data provided in util.py
  • Your code must run in less than 5 seconds on one of the university-provided computers.

Allowed:

  • You can develop your code on your personal machine, but it must also run successfully on one of the university provided machines or virtual images.
  • Your code may use standard Python libraries (except os).
  • You may use the NumPy, SciPy, matplotlib and Pandas libraries. Be sure you are using the correct versions.
  • Code provided by the instructor, or allowed by the instructor to be shared.

Prohibited:

  • Any use of global variables.
  • Any libraries not listed in the "allowed" section above.
  • Use of any code other than util.py to read in data.
  • Use of Python's os module.
  • Any code you did not write yourself (except for the 5 line rule in the "allowed" section).
  • Knights who say "neeee."

Legacy versions