Commits

Mark Lavin committed 4326f11

Adding project template.

  • Participants
  • Parent commits a9558e4

Comments (0)

Files changed (1)

File projects/spring2011.py

+"""
+This assignement will walk you through gathering data for a
+pair of stocks and calculating the correlation between those stocks
+using the daily returns.
+
+Yahoo makes their historical stock data available in CSV format.
+Below is the url for IBM stock data from Jan 1, 2010 to Dec 31, 2010.
+http://ichart.finance.yahoo.com/table.csv?s=IBM&a=00&b=1&c=2010&d=11&e=31&f=2010&g=d&ignore=.csv
+
+The data is returned in CSV (comma separated format) with the flowing columns:
+Date, Open, High, Low, Close, Volume, Adj Close
+
+The daily return of
+a stock is defined by: 
+    (C_n - C_n-1) / C_n-1
+where C_n denotes the nth adjusted close and C_n-1 denotes the (n-1)th
+adjusted close.
+
+The function signatures for various steps of this process have been
+given below. The names and parameters of these functions should not
+be changed. You are free to write additional functions or classes as
+needed. You are welcome to use any modules in the Python
+standard library as well as NumPy, SciPy, and Matplotlib external
+libraries. All code must run on Python 2.6.5.
+"""
+
+
+def build_request_url(symbol, start_date, end_date):
+    """
+    This function should take a stock symbol as a string
+    along with the start and end dates as Python dates
+    and return the yahoo csv download url.
+    """
+    pass
+
+
+def get_yahoo_data(url):
+    """
+    This function should take a url as returned by build_request_url
+    and return a list of tuples with each tuple containing the
+    date (as a Python date) and the adjusted close (as a float).
+    """
+    pass
+
+
+def calculate_stock_correlation(data):
+    """
+    This function should take a list containing two lists of the form
+    returned by get_yahoo_data (list of date, adj. close tuples) and
+    return the correlation of the daily returns as defined above.
+    """
+    pass
+
+
+def graph_stock_regression(data, filename):
+    """
+    This function should take a list containing two lists of the form
+    returned by get_yahoo_data (list of date, adj. close tuples) and
+    save the graph of the series of daily return pairs as well as
+    the regression line. The graph should be saved to the given
+    filename.
+    """
+    pass
+
+
+def main():
+    """
+    This function should get the stock data for Google (GOOG)
+    and Apple (AAPL) for Jan 1, 2010 to Dec 31, 2010. Using that
+    data it should calculate and print the correlation of the daily
+    returns and graph the regression of Google vs Apple. Save the graph as
+    GOOGvsAAPL.png
+    """
+    pass
+
+
+if __name__ == "__main__":
+    """
+    When this module as run as a script it will call the main function.
+    You should not modify this code.
+    """
+    main()