2012Fall7646 Homework 2
The purpose of this assignment is to:
- Introduce you to Python, NumPy and matplotlib;
- Have you explore the statistical properties and trade offs trading the same "instrument" in different ways.
Suppose we have an investment instrument with the following properties:
- You can purchase it in $1, $10, $100, and $1000 denominations.
- Holding time is one day.
- 51% of the time the return is exactly 1.0 (the value doubles).
- 49% of the time the return is exactly -1.0 (all value is lost).
This "investment instrument" is like an even money bet on a biased coin (that comes up "heads" 51% of the time). The odds for this game are very similar to the odds held by the casino for even money bets at roulette.
Suppose further that we have $1000 to invest on the first day. For this project we will run a simulation to determine how to make that investment on the first day: Should make a single $1000 investment, or 1000 $1 investments (or something in between)?
Part 1: Set up your Python coding development environment. See: QSToolKit_Installation_Guide.
Part 2: Create a Python program that will do the following:
- It should accept the following inputs (which can be hardcoded as variables):
- num_positions # number of shares to buy in parallel: e.g., 1, 10, 100 or 1000
- position_value = 1000 / num_positions # represents the size of each investment
- num_trials = 10000 # how many times to randomly repeat the test
- Use NumPy's random number generating capability to simulate the outcome of one day of investment, call it cumu_ret[trial]
- Example for the case where num_positions = 1, the outcome should be 0 (49% chance) or $2000 (51% chance)
- Repeat num_trials times (i.e., simulate 10,000 different single days of trading.
- Save the result of each day as:
- daily_ret[trial] = (cumu_ret[trial]/1000) - 1
Part 3: Run your program 4 times, with num_positions set to 1, 10, 100, 1000
- For each run, compute results as follows:
- Plot the result of the 10,000 trials in a histogram with X axis from -1.0 to +1.0, and Y axis as the number of trials with that result.
- The mean or expected value of the daily return.
- The standard deviation of the daily return.
Part 4: Answer these questions:
- Given these results, which method would you use to invest with?
- For that selection, compute the Sharpe Ratio you would expect if you could use this as a real trading strategy. For this question, assume that your trading strategy could achieve this average daily return and standard deviation of return every day.
- Turn in files as attachments by t-square. Please do not "zip" your files together first; just submit separate files as named below:
- program.py Your Python program.
- results.txt The numerical results described above. Along with your answer to the question: Given these results which method would you use to invest with?
- histogram_0001_pos.pdf The histogram of the result for 1 position of $1000.
- histogram_0010_pos.pdf The histogram of the result for 10 positions of $100.
- histogram_0100_pos.pdf The histogram of the result for 100 positions of $100.
- histogram_1000_pos.pdf The histogram of the result for 1000 positions of $1.
How to submit
Go to the t-square site for the class, then click on the "assignments" tab. Click on "add attachment" to add your three files. Once you are sure you've added both files, click "submit."
To help get you started, here are some snippets of code from a possible solution:
# # Example code regarding Homework 2 # import numpy as np import matplotlib.pyplot as plt import matplotlib.mlab as mlab from pylab import * num_positions = 1000 position_value = 1000/num_positions num_trials = 10000 # # main code goes here # plt.hist(daily_ret,100,range=[-1,1])The plot for 1000 x $1 bets should look like this