From 0429c497c7ed332c299e6189ce25d94c8e76ac8a Mon Sep 17 00:00:00 2001 From: Felix Martin Date: Thu, 8 Oct 2020 20:24:49 -0400 Subject: [PATCH] Make zip naming consistent and start marketsim project --- marketsim/grade_marketsim.py | 384 ++++++++++++++++++ marketsim/marketsim.py | 91 +++++ marketsim/orders/orders-01.csv | 18 + marketsim/orders/orders-02.csv | 18 + marketsim/orders/orders-03.csv | 14 + marketsim/orders/orders-04.csv | 15 + marketsim/orders/orders-05.csv | 15 + marketsim/orders/orders-06.csv | 15 + marketsim/orders/orders-07.csv | 15 + marketsim/orders/orders-08.csv | 15 + marketsim/orders/orders-09.csv | 10 + marketsim/orders/orders-10.csv | 13 + marketsim/orders/orders-11.csv | 10 + marketsim/orders/orders-12.csv | 15 + ..._2020Spring.zip => 20Spring_ML4T_data.zip} | Bin ..._2020Spring.zip => 20Spring_marketsim.zip} | Bin 16 files changed, 648 insertions(+) create mode 100644 marketsim/grade_marketsim.py create mode 100644 marketsim/marketsim.py create mode 100644 marketsim/orders/orders-01.csv create mode 100644 marketsim/orders/orders-02.csv create mode 100644 marketsim/orders/orders-03.csv create mode 100644 marketsim/orders/orders-04.csv create mode 100644 marketsim/orders/orders-05.csv create mode 100644 marketsim/orders/orders-06.csv create mode 100644 marketsim/orders/orders-07.csv create mode 100644 marketsim/orders/orders-08.csv create mode 100644 marketsim/orders/orders-09.csv create mode 100644 marketsim/orders/orders-10.csv create mode 100644 marketsim/orders/orders-11.csv create mode 100644 marketsim/orders/orders-12.csv rename zips/{ML4T_2020Spring.zip => 20Spring_ML4T_data.zip} (100%) rename zips/{Marketsim_2020Spring.zip => 20Spring_marketsim.zip} (100%) diff --git a/marketsim/grade_marketsim.py b/marketsim/grade_marketsim.py new file mode 100644 index 0000000..74448b9 --- /dev/null +++ b/marketsim/grade_marketsim.py @@ -0,0 +1,384 @@ +"""MC2-P1: Market simulator - grading script. + +Usage: +- Switch to a student feedback directory first (will write "points.txt" and "comments.txt" in pwd). +- Run this script with both ml4t/ and student solution in PYTHONPATH, e.g.: + PYTHONPATH=ml4t:MC1-P2/jdoe7 python ml4t/mc2_p1_grading/grade_marketsim.py + +Copyright 2018, Georgia Institute of Technology (Georgia Tech) +Atlanta, Georgia 30332 +All Rights Reserved + +Template code for CS 4646/7646 + +Georgia Tech asserts copyright ownership of this template and all derivative +works, including solutions to the projects assigned in this course. Students +and other users of this template code are advised not to share it with others +or to make it available on publicly viewable websites including repositories +such as github and gitlab. This copyright statement should not be removed +or edited. + +We do grant permission to share solutions privately with non-students such +as potential employers. However, sharing with other current or future +students of CS 7646 is prohibited and subject to being investigated as a +GT honor code violation. + +-----do not edit anything above this line--- +""" + +import pytest +from grading.grading import grader, GradeResult, time_limit, run_with_timeout, IncorrectOutput + +import os +import sys +import traceback as tb + +import numpy as np +import pandas as pd +from collections import namedtuple + +from util import get_data +from util import get_orders_data_file + +# Student code +main_code = "marketsim" # module name to import + +# Test cases +MarketsimTestCase = namedtuple('MarketsimTestCase', ['description', 'group', 'inputs', 'outputs']) +marketsim_test_cases = [ + MarketsimTestCase( + description="Orders 1", + group='basic', + inputs=dict( + orders_file='orders-01.csv', + start_val=1000000, + commission=0., + impact=0. + ), + outputs=dict( + num_days = 245 , + last_day_portval = 1115569.2, + sharpe_ratio = 0.612340613407 , + avg_daily_ret = 0.00055037432146 + ) + ), + MarketsimTestCase( + description="Orders 2", + group='basic', + inputs=dict( + orders_file='orders-02.csv', + start_val=1000000, + commission=0., + impact=0. + ), + outputs=dict( + num_days = 245 , + last_day_portval = 1095003.35, + sharpe_ratio = 1.01613520942, + avg_daily_ret = 0.000390534819609 + ) + ), + MarketsimTestCase( + description="Orders 3", + group='basic', + inputs=dict( + orders_file='orders-03.csv', + start_val=1000000, + commission=0., + impact=0. + ), + outputs=dict( + num_days = 240, + last_day_portval = 857616.0, + sharpe_ratio = -0.759896272199, + avg_daily_ret = -0.000571326189931 + ) + ), + MarketsimTestCase( + description="Orders 4", + group='basic', + inputs=dict( + orders_file='orders-04.csv', + start_val=1000000, + commission=0., + impact=0. + ), + outputs=dict( + num_days = 233, + last_day_portval = 923545.4, + sharpe_ratio = -0.266030146916, + avg_daily_ret = -0.000240200768212 + ) + ), + MarketsimTestCase( + description="Orders 5", + group='basic', + inputs=dict( + orders_file='orders-05.csv', + start_val=1000000, + commission=0., + impact=0. + ), + outputs=dict( + num_days = 296, + last_day_portval = 1415563.0, + sharpe_ratio = 2.19591520826, + avg_daily_ret = 0.00121733290744 + ) + ), + MarketsimTestCase( + description="Orders 6", + group='basic', + inputs=dict( + orders_file='orders-06.csv', + start_val=1000000, + commission=0., + impact=0. + ), + outputs=dict( + num_days = 210, + last_day_portval = 894604.3, + sharpe_ratio = -1.23463930987, + avg_daily_ret = -0.000511281541086 + ) + ), + MarketsimTestCase( + description="Orders 7", + group='basic', + inputs=dict( + orders_file='orders-07.csv', + start_val=1000000, + commission=0., + impact=0. + ), + outputs=dict( + num_days = 237, + last_day_portval = 1106563.3, + sharpe_ratio = 2.10356512897, + avg_daily_ret = 0.0004345040621 + ) + ), + MarketsimTestCase( + description="Orders 8", + group='basic', + inputs=dict( + orders_file='orders-08.csv', + start_val=1000000, + commission=0., + impact=0. + ), + outputs=dict( + num_days = 229, + last_day_portval = 1074884.1, + sharpe_ratio = 0.941858298061, + avg_daily_ret = 0.000332404156893 + ) + ), + MarketsimTestCase( + description="Orders 9", + group='basic', + inputs=dict( + orders_file='orders-09.csv', + start_val=1000000, + commission=0., + impact=0. + ), + outputs=dict( + num_days = 37, + last_day_portval = 1067710.0, + sharpe_ratio = 2.90848480553, + avg_daily_ret = 0.00187252252117 + ) + ), + ######################### + # Commission and impact # + ######################### + MarketsimTestCase( + description="Orders 11, commission", + group='commission', + inputs=dict( + orders_file='orders-11.csv', + start_val=1000000, + commission=9.95, + impact=0. + ), + outputs=dict( + num_days = 37, + last_day_portval = 1045700.45, + sharpe_ratio = 1.80327835983, + avg_daily_ret = 0.00130745837411 + ) + ), + MarketsimTestCase( + description="Orders 12, impact", + group='impact', + inputs=dict( + orders_file='orders-12.csv', + start_val=1000000, + commission=0., + impact=0.005 + ), + outputs=dict( + num_days = 240, + last_day_portval = 1705686.6665, + sharpe_ratio = 1.26427802107, + avg_daily_ret = 0.00290246139389 + ) + ), + MarketsimTestCase( + description="Orders 10, impact and commission", + group='both', + inputs=dict( + orders_file='orders-10.csv', + start_val=1000000, + commission=9.95, + impact=0.005 + ), + outputs=dict( + num_days = 141, + last_day_portval = 1026658.3265, + sharpe_ratio = 0.627643575702, + avg_daily_ret = 0.000222013722594 + ) + ), + MarketsimTestCase( + description="author() test", + group='author', + inputs=None, + outputs=None + ), + ####################### + # Withheld test cases # + ####################### +] + +seconds_per_test_case = 10 # execution time limit + +# Grading parameters (picked up by module-level grading fixtures) +max_points = 100.0 # 9.5 * 10 + 2.5 * 2 + 1 secret point +html_pre_block = True # surround comments with HTML
 tag (for T-Square comments field)  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+# Test functon(s)  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+@pytest.mark.parametrize("description,group,inputs,outputs", marketsim_test_cases)  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+def test_marketsim(description, group, inputs, outputs, grader):  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    """Test compute_portvals() returns correct daily portfolio values.  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    Requires test description, test case group, inputs, expected outputs, and a grader fixture.  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    """  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    points_earned = 0.0  # initialize points for this test case  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    try:  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+        # Try to import student code (only once)  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+        if not main_code in globals():  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+            import importlib  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+            # * Import module  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+            mod = importlib.import_module(main_code)  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+            globals()[main_code] = mod  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+            # * Import methods to test  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+            for m in ['compute_portvals']:  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+                globals()[m] = getattr(mod, m)  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+        incorrect = False  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+        msgs = []  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+        if group == 'author':  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+            try:  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+                auth_string = run_with_timeout(marketsim.author,seconds_per_test_case,(),{})  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+                if auth_string == 'tb34':  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+                    incorrect = True  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+                    msgs.append("   Incorrect author name (tb34)")  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+                    points_earned = -10  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+                elif auth_string == '':  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+                    incorrect = True  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+                    msgs.append("   Empty author name")  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+                    points_earned = -10  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+            except Exception as e:  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+                incorrect = True  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+                msgs.append("   Exception occured when calling author() method: {}".format(e))  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+                points_earned = -10  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+        else:  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+            # Unpack test case  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+            orders_file = inputs['orders_file']  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+            start_val = inputs['start_val']  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+            impct = inputs['impact']  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+            commish = inputs['commission']  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+            portvals = None  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+            fullpath_orders_file = get_orders_data_file(orders_file)  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+            portvals = run_with_timeout(compute_portvals,seconds_per_test_case,(),{'orders_file':fullpath_orders_file,'start_val':start_val,'commission':commish,'impact':impct})  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+            # * Check return type is correct, coax into Series  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+            assert (type(portvals) == pd.Series) or (type(portvals) == pd.DataFrame and len(portvals.columns) == 1), "You must return a Series or single-column DataFrame!"  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+            if type(portvals) == pd.DataFrame:  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+                portvals = portvals[portvals.columns[0]]  # convert single-column DataFrame to Series  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+            if portvals.isnull().values.any():  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+                incorrect=True  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+                msgs.append("Portfolio values cannot be NaNs!")  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+            else:  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+                if group == 'basic':  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+                    if len(portvals) != outputs['num_days']:  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+                        incorrect=True  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+                        msgs.append("   Incorrect number of days: {}, expected {}".format(len(portvals), outputs['num_days']))  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+                    else:  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+                        points_earned += 2.0  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+                    if abs(portvals[-1]-outputs['last_day_portval']) > (0.001*outputs['last_day_portval']):  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+                        incorrect=True  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+                        msgs.append("   Incorrect final value: {}, expected {}".format(portvals[-1],outputs['last_day_portval']))  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+                    else:  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+                        points_earned += 5.0  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+                    adr,sr = get_stats(portvals)  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+                    if abs(sr-outputs['sharpe_ratio']) > abs(0.001*outputs['sharpe_ratio']):  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+                        incorrect=True  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+                        msgs.append("   Incorrect sharpe ratio: {}, expected {}".format(sr,outputs['sharpe_ratio']))  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+                    else:  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+                        points_earned += 1.0  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+                    if abs(adr-outputs['avg_daily_ret']) > abs(0.001*outputs['avg_daily_ret']):  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+                        incorrect=True  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+                        msgs.append("   Incorrect avg daily return: {}, expected {}".format(adr,outputs['avg_daily_ret']))  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+                    else:  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+                        points_earned += 1.0  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+                elif group=='commission' or group=='impact' or group=='both':  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+                    if abs(portvals[-1]-outputs['last_day_portval']) > 0.001:#(0.001*outputs['last_day_portval']):  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+                        incorrect = True  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+                        msgs.append("   Incorrect final value: {}, expected {}".format(portvals[-1],outputs['last_day_portval']))  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+                    else:  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+                        points_earned += 2.0  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+        if incorrect:  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+            # inputs_str = "    orders_file: {}\n" \
+                         # "    start_val: {}\n".format(orders_file, start_val)  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+            raise IncorrectOutput("Test failed on one or more output criteria.\n  Inputs:\n{}\n  Failures:\n{}".format(inputs, "\n".join(msgs)))  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    except Exception as e:  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+        # Test result: failed  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+        msg = "Test case description: {}\n".format(description)  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+        # Generate a filtered stacktrace, only showing erroneous lines in student file(s)  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+        tb_list = tb.extract_tb(sys.exc_info()[2])  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+        if 'grading_traceback' in dir(e):  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+            tb_list = e.grading_traceback  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+        for i in range(len(tb_list)):  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+            row = tb_list[i]  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+            tb_list[i] = (os.path.basename(row[0]), row[1], row[2], row[3])  # show only filename instead of long absolute path  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+        tb_list = [row for row in tb_list if row[0] == 'marketsim.py']  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+        if tb_list:  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+            msg += "Traceback:\n"  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+            msg += ''.join(tb.format_list(tb_list))  # contains newlines  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+        msg += "{}: {}".format(e.__class__.__name__, str(e))  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+        # Report failure result to grader, with stacktrace  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+        grader.add_result(GradeResult(outcome='failed', points=max(points_earned,0), msg=msg))  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+        raise  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    else:  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+        # Test result: passed (no exceptions)  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+        grader.add_result(GradeResult(outcome='passed', points=points_earned, msg=None))  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+def get_stats(port_val):  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    daily_rets = (port_val / port_val.shift(1)) - 1  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    daily_rets = daily_rets[1:]  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    avg_daily_ret = daily_rets.mean()  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    std_daily_ret = daily_rets.std()  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    sharpe_ratio = np.sqrt(252) * daily_rets.mean() / std_daily_ret  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    return avg_daily_ret, sharpe_ratio  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+if __name__ == "__main__":  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    pytest.main(["-s", __file__])  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
diff --git a/marketsim/marketsim.py b/marketsim/marketsim.py
new file mode 100644
index 0000000..6ad2380
--- /dev/null
+++ b/marketsim/marketsim.py
@@ -0,0 +1,91 @@
+"""MC2-P1: Market simulator.  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+Copyright 2018, Georgia Institute of Technology (Georgia Tech)  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+Atlanta, Georgia 30332  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+All Rights Reserved  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+Template code for CS 4646/7646  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+Georgia Tech asserts copyright ownership of this template and all derivative  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+works, including solutions to the projects assigned in this course. Students  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+and other users of this template code are advised not to share it with others  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+or to make it available on publicly viewable websites including repositories  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+such as github and gitlab.  This copyright statement should not be removed  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+or edited.  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+We do grant permission to share solutions privately with non-students such  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+as potential employers. However, sharing with other current or future  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+students of CS 7646 is prohibited and subject to being investigated as a  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+GT honor code violation.  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+-----do not edit anything above this line---  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+Student Name: Tucker Balch (replace with your name)  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+GT User ID: tb34 (replace with your User ID)  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+GT ID: 900897987 (replace with your GT ID)  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+"""  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+import pandas as pd  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+import numpy as np  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+import datetime as dt  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+import os  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+from util import get_data, plot_data  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+def compute_portvals(orders_file = "./orders/orders.csv", start_val = 1000000, commission=9.95, impact=0.005):  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    # this is the function the autograder will call to test your code  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    # NOTE: orders_file may be a string, or it may be a file object. Your  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    # code should work correctly with either input  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    # TODO: Your code here  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    # In the template, instead of computing the value of the portfolio, we just  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    # read in the value of IBM over 6 months  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    start_date = dt.datetime(2008,1,1)  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    end_date = dt.datetime(2008,6,1)  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    portvals = get_data(['IBM'], pd.date_range(start_date, end_date))  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    portvals = portvals[['IBM']]  # remove SPY  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    rv = pd.DataFrame(index=portvals.index, data=portvals.values)  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    return rv  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    return portvals  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+def test_code():  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    # this is a helper function you can use to test your code  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    # note that during autograding his function will not be called.  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    # Define input parameters  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    of = "./orders/orders2.csv"  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    sv = 1000000  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    # Process orders  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    portvals = compute_portvals(orders_file = of, start_val = sv)  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    if isinstance(portvals, pd.DataFrame):  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+        portvals = portvals[portvals.columns[0]] # just get the first column  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    else:  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+        "warning, code did not return a DataFrame"  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    # Get portfolio stats  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    # Here we just fake the data. you should use your code from previous assignments.  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    start_date = dt.datetime(2008,1,1)  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    end_date = dt.datetime(2008,6,1)  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    cum_ret, avg_daily_ret, std_daily_ret, sharpe_ratio = [0.2,0.01,0.02,1.5]  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    cum_ret_SPY, avg_daily_ret_SPY, std_daily_ret_SPY, sharpe_ratio_SPY = [0.2,0.01,0.02,1.5]  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    # Compare portfolio against $SPX  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    print(f"Date Range: {start_date} to {end_date}")  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    print()  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    print(f"Sharpe Ratio of Fund: {sharpe_ratio}")  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    print(f"Sharpe Ratio of SPY : {sharpe_ratio_SPY}")  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    print()  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    print(f"Cumulative Return of Fund: {cum_ret}")  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    print(f"Cumulative Return of SPY : {cum_ret_SPY}")  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    print()  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    print(f"Standard Deviation of Fund: {std_daily_ret}")  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    print(f"Standard Deviation of SPY : {std_daily_ret_SPY}")  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    print()  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    print(f"Average Daily Return of Fund: {avg_daily_ret}")  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    print(f"Average Daily Return of SPY : {avg_daily_ret_SPY}")  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    print()  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    print(f"Final Portfolio Value: {portvals[-1]}")  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+if __name__ == "__main__":  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
+    test_code()  		  	   		     			  		 			     			  	  		 	  	 		 			  		  			
diff --git a/marketsim/orders/orders-01.csv b/marketsim/orders/orders-01.csv
new file mode 100644
index 0000000..9675a1f
--- /dev/null
+++ b/marketsim/orders/orders-01.csv
@@ -0,0 +1,18 @@
+Date,Symbol,Order,Shares
+2011-01-10,AAPL,BUY,1500
+2011-01-13,AAPL,SELL,1500
+2011-01-13,IBM,BUY,4000
+2011-01-26,GOOG,BUY,1000
+2011-02-02,XOM,SELL,4000
+2011-02-10,XOM,BUY,4000
+2011-03-03,GOOG,SELL,1000
+2011-03-03,GOOG,SELL,2200
+2011-06-03,IBM,SELL,3300
+2011-05-03,IBM,BUY,1500
+2011-06-10,AAPL,BUY,1200
+2011-08-01,GOOG,BUY,55
+2011-08-01,GOOG,SELL,55
+2011-12-20,AAPL,SELL,1200
+2011-12-21,AAPL,BUY,20
+2011-12-27,GOOG,BUY,2200
+2011-12-28,IBM,SELL,2200
diff --git a/marketsim/orders/orders-02.csv b/marketsim/orders/orders-02.csv
new file mode 100644
index 0000000..8f7fe4f
--- /dev/null
+++ b/marketsim/orders/orders-02.csv
@@ -0,0 +1,18 @@
+Date,Symbol,Order,Shares
+2011-01-10,AAPL,BUY,1500
+2011-01-10,AAPL,SELL,1500
+2011-01-13,AAPL,SELL,1500
+2011-01-13,IBM,BUY,4000
+2011-01-26,GOOG,BUY,1000
+2011-02-02,XOM,SELL,4000
+2011-02-10,XOM,BUY,4000
+2011-03-03,GOOG,SELL,1000
+2011-06-03,IBM,SELL,3300
+2011-05-03,IBM,BUY,1500
+2011-06-10,AAPL,BUY,1200
+2011-08-01,GOOG,BUY,55
+2011-08-01,GOOG,SELL,55
+2011-08-01,GOOG,BUY,55
+2011-12-20,AAPL,SELL,1200
+2011-12-21,AAPL,BUY,20
+2011-12-28,IBM,SELL,2200
diff --git a/marketsim/orders/orders-03.csv b/marketsim/orders/orders-03.csv
new file mode 100644
index 0000000..6bb355c
--- /dev/null
+++ b/marketsim/orders/orders-03.csv
@@ -0,0 +1,14 @@
+Date,Symbol,Order,Shares
+2011-01-10,AAPL,BUY,1500
+2011-01-13,AAPL,BUY,1500
+2011-01-26,GOOG,BUY,1000
+2011-02-02,XOM,SELL,4000
+2011-02-10,XOM,BUY,4000
+2011-03-03,GOOG,SELL,1000
+2011-03-03,IBM,SELL,1200
+2011-06-03,IBM,SELL,3300
+2011-05-03,IBM,BUY,1500
+2011-06-10,AAPL,SELL,3000
+2011-08-01,GOOG,BUY,55
+2011-08-01,GOOG,BUY,55
+2011-12-20,GOOG,SELL,110
diff --git a/marketsim/orders/orders-04.csv b/marketsim/orders/orders-04.csv
new file mode 100644
index 0000000..0a7e0a7
--- /dev/null
+++ b/marketsim/orders/orders-04.csv
@@ -0,0 +1,15 @@
+Date,Symbol,Order,Shares
+2008-01-14,GOOG,SELL,1000
+2008-01-17,GOOG,BUY,1000
+2008-03-19,AAPL,SELL,3000
+2008-03-31,IBM,SELL,2000
+2008-05-02,BAC,BUY,5000
+2008-05-09,BAC,SELL,5000
+2008-06-02,IBM,BUY,2000
+2008-06-02,AAPL,BUY,3100
+2008-06-02,AAPL,BUY,4300
+2008-07-23,AAPL,SELL,3500
+2008-07-10,GOOG,SELL,1000
+2008-08-07,IBM,SELL,55
+2008-08-11,IBM,BUY,55
+2008-12-12,GOOG,BUY,1000
diff --git a/marketsim/orders/orders-05.csv b/marketsim/orders/orders-05.csv
new file mode 100644
index 0000000..4c959a1
--- /dev/null
+++ b/marketsim/orders/orders-05.csv
@@ -0,0 +1,15 @@
+Date,Symbol,Order,Shares
+2009-05-04,GLD,BUY,3000
+2009-06-08,AAPL,BUY,1500
+2009-07-07,IBM,BUY,4000
+2009-07-07,GOOG,BUY,1000
+2009-10-19,IBM,SELL,4000
+2010-01-13,XOM,BUY,3000
+2010-02-26,GOOG,SELL,1000
+2010-03-09,XOM,SELL,900
+2010-04-20,GLD,SELL,3000
+2010-05-03,BAC,BUY,1500
+2010-05-27,BAC,SELL,1500
+2010-06-29,XOM,SELL,2100
+2010-07-02,AAPL,SELL,300
+2010-07-06,AAPL,SELL,1200
diff --git a/marketsim/orders/orders-06.csv b/marketsim/orders/orders-06.csv
new file mode 100644
index 0000000..efd3ac6
--- /dev/null
+++ b/marketsim/orders/orders-06.csv
@@ -0,0 +1,15 @@
+Date,Symbol,Order,Shares
+2007-01-10,AAPL,BUY,2500
+2007-01-17,AAPL,SELL,1500
+2007-01-19,IBM,BUY,400
+2007-01-26,GOOG,BUY,1000
+2007-02-02,XOM,SELL,4000
+2007-02-16,XOM,BUY,700
+2007-03-05,GOOG,SELL,550
+2007-03-05,IBM,SELL,2200
+2007-05-14,XOM,SELL,880
+2007-05-15,XOM,BUY,550
+2007-09-13,GOOG,SELL,1000
+2007-10-10,XOM,BUY,100
+2007-10-12,XOM,SELL,3000
+2007-11-07,XOM,BUY,400
diff --git a/marketsim/orders/orders-07.csv b/marketsim/orders/orders-07.csv
new file mode 100644
index 0000000..60acad3
--- /dev/null
+++ b/marketsim/orders/orders-07.csv
@@ -0,0 +1,15 @@
+Date,Symbol,Order,Shares
+2009-01-14,AAPL,BUY,150
+2009-01-21,AAPL,SELL,150
+2009-01-21,IBM,BUY,400
+2009-01-30,GOOG,BUY,100
+2009-02-02,XOM,SELL,400
+2009-02-10,XOM,BUY,400
+2009-03-03,GOOG,SELL,100
+2009-03-03,IBM,SELL,220
+2009-06-03,IBM,SELL,330
+2009-05-08,IBM,BUY,1500
+2009-06-10,AAPL,BUY,1200
+2009-08-03,GOOG,BUY,550
+2009-08-03,GOOG,SELL,550
+2009-12-21,AAPL,SELL,1200
diff --git a/marketsim/orders/orders-08.csv b/marketsim/orders/orders-08.csv
new file mode 100644
index 0000000..5077e9e
--- /dev/null
+++ b/marketsim/orders/orders-08.csv
@@ -0,0 +1,15 @@
+Date,Symbol,Order,Shares
+2010-01-12,AAPL,BUY,150
+2010-01-21,IBM,BUY,400
+2010-01-21,GOOG,BUY,100
+2010-01-27,AAPL,SELL,150
+2010-02-05,XOM,SELL,400
+2010-02-11,GOOG,SELL,100
+2010-03-10,IBM,SELL,220
+2010-04-15,XOM,BUY,400
+2010-05-20,GOOG,BUY,550
+2010-06-03,IBM,SELL,330
+2010-06-24,AAPL,BUY,1200
+2010-08-18,IBM,BUY,1500
+2010-09-15,GOOG,SELL,550
+2010-12-07,AAPL,SELL,1200
diff --git a/marketsim/orders/orders-09.csv b/marketsim/orders/orders-09.csv
new file mode 100644
index 0000000..9ac0b3c
--- /dev/null
+++ b/marketsim/orders/orders-09.csv
@@ -0,0 +1,10 @@
+Date,Symbol,Order,Shares
+2011-01-10,AAPL,BUY,2500
+2011-01-10,AAPL,BUY,2500
+2011-01-13,AAPL,SELL,5000
+2011-01-13,IBM,BUY,4000
+2011-01-26,GOOG,BUY,1000
+2011-02-02,XOM,SELL,4000
+2011-02-10,XOM,BUY,4000
+2011-03-03,GOOG,SELL,1000
+2011-03-03,IBM,SELL,4000
diff --git a/marketsim/orders/orders-10.csv b/marketsim/orders/orders-10.csv
new file mode 100644
index 0000000..5cf8cad
--- /dev/null
+++ b/marketsim/orders/orders-10.csv
@@ -0,0 +1,13 @@
+Date,Symbol,Order,Shares
+2011-01-10,AAPL,BUY,1500
+2011-01-13,AAPL,SELL,1500
+2011-01-13,IBM,BUY,4000
+2011-01-26,GOOG,BUY,1000
+2011-02-02,XOM,SELL,4000
+2011-02-10,XOM,BUY,4000
+2011-03-03,GOOG,SELL,1000
+2011-03-03,IBM,SELL,2200
+2011-06-03,IBM,SELL,3300
+2011-05-03,IBM,BUY,1500
+2011-08-01,GOOG,BUY,55
+2011-08-01,GOOG,SELL,55
diff --git a/marketsim/orders/orders-11.csv b/marketsim/orders/orders-11.csv
new file mode 100644
index 0000000..121cf47
--- /dev/null
+++ b/marketsim/orders/orders-11.csv
@@ -0,0 +1,10 @@
+Date,Symbol,Order,Shares
+2011-01-10,AAPL,BUY,2500
+2011-01-10,AAPL,BUY,2500
+2011-01-13,AAPL,SELL,5000
+2011-01-13,IBM,BUY,4000
+2011-01-26,GOOG,BUY,1000
+2011-02-02,XOM,SELL,12000
+2011-02-10,XOM,BUY,4000
+2011-03-03,GOOG,SELL,1000
+2011-03-03,IBM,SELL,4000
diff --git a/marketsim/orders/orders-12.csv b/marketsim/orders/orders-12.csv
new file mode 100644
index 0000000..cdddbbe
--- /dev/null
+++ b/marketsim/orders/orders-12.csv
@@ -0,0 +1,15 @@
+Date,Symbol,Order,Shares
+2011-01-10,AAPL,BUY,1500
+2011-01-13,AAPL,SELL,1500
+2011-01-13,IBM,BUY,4000
+2011-01-26,GOOG,BUY,1000
+2011-02-02,XOM,SELL,4000
+2011-02-10,XOM,BUY,4000
+2011-03-03,GOOG,SELL,1000
+2011-03-03,IBM,SELL,2200
+2011-06-03,IBM,SELL,3300
+2011-05-03,IBM,BUY,1500
+2011-06-10,AAPL,BUY,10000
+2011-08-01,GOOG,BUY,55
+2011-08-01,GOOG,SELL,55
+2011-12-20,AAPL,SELL,1200
diff --git a/zips/ML4T_2020Spring.zip b/zips/20Spring_ML4T_data.zip
similarity index 100%
rename from zips/ML4T_2020Spring.zip
rename to zips/20Spring_ML4T_data.zip
diff --git a/zips/Marketsim_2020Spring.zip b/zips/20Spring_marketsim.zip
similarity index 100%
rename from zips/Marketsim_2020Spring.zip
rename to zips/20Spring_marketsim.zip