Ξ
PROJECT 5: MARKETSIM
T
h
Table of Contents
*
Overview
*
About the Project
*
C
*
*
Grading Information
*
Development Guidelines
*
S
REVISIONS
This assignment is subject to change up until 3 weeks prior to the due date. We do not anticipate changes; any changes will be logged in this section.
-
OVERVIEW
In this project, you will create a market simulator that accepts trading orders and keeps track of a portfolio’s value over time. It also then assesses the performance of that portfolio. You will submit the code for the project to Gradescope SUBMISSION. There is no report associated with this project.
-
Learning Objectives
The specific learning objectives for this assignment are focused on the following areas:
Market Simulation: Develop a market simulator. Variations of this market simulator will play a role in future projects.
Transaction Costs: Develop an understanding of market costs and how
affect the value of a portfolio.
-
they
-
A
In this project, you will leverage some of the work completed in project 2 to build a market simulator
-
YOUR IMPLEMENTATION
Your submission must implement this API specification.
Before the deadline, make sure to pre-validate your submission using Gradescope TESTING. Once you are satisfied with the results in testing, submit the code to Gradescope SUBMISSION. Only code submitted to Gradescope SUBMISSION will be graded. If you submit your code to Gradescope TESTING and have not also submitted your code to Gradescope SUBMISSION, you will receive a zero (0).
-
Getting Started
You will be given a starter framework to make it easier to get started on the project and focus on the concepts involved. This framework assumes you have already set up the local environment and ML4T Software. The framework for Project 5 can be obtained from: Marketsim_2023Fall.zip.
Extract its contents into the base directory (e.g., ML4T_2023Fall). This will add a new folder
Within the marke
s is the same script that will vironment
marketsim.py
Student implementations will replace your compute_portvals() function within this file, modifying or replacing the existing stub code provided in the file.
orders directory
A directory containing several order files can be used with this project.
-
Part 1: Implement the Basic Simulator (90 Points)
Your job is to implement your market simulator as a function, compute_portvals() that returns a DataFrame with one column. You should implement it within the file marketsim.py. It should adhere to the following API:
1
2
3
d
# TODO: Your code here return por
= 1000
The start date and end date of the simulation are the first and last dates with orders in the orders_file. (Note: The orders may not appear in sequential order in the file.) The arguments are as follows:
orders_file is the name of a file from which to read orders, and
start_val is the starting value of the portfolio (initial cash available)
commission is the fixed amount in dollars charged for each transaction (both entry and exit)
impact is the amount the price moves against the trader compared to the historical data at each transaction. Impact of 0.01 in the API corresponds to an impact of 1%.
Return the result (portvals) as a single-column pandas.DataFrame (column name does not matter), containing the value of the portfolio for each trading day in the first column from start_date to end_date, inclusive.
The files containing orders are CSV files with the following columns:
Date (yyyy-mm-dd)
Symbol (e.g. AAPL, GOOG) Order (BUY or SELL)
Shares (no. of shares to trade)
For example:
-
Date,Symbol,Order,Shares
-
2008-12-3,AAPL,BUY,130
-
2008-12-8,AAPL,SELL,130
-
2008-12-5,IBM,BUY,50
Your si g
adjust quities.
The resulting data frame should contain values like this:
1 2008-12-3
2 2008-12-4
3 2008-12-5
4 …
-
How it Should Work
-
-
Your code should keep account of how many shares of each stock are in the portfolio on each day and how much cash is available on each day. Note that negative shares and negative cash are possible. Negative shares mean that the portfolio is in a short position for that stock. Negative cash means that you’ve borrowed money from the broker.
When a BUY order occurs, you should add the appropriate number of shares to the count for that stock and subtract the appropriate cost of the shares from the cash account. The cost should be determined using the adjusted close price for that stock on that day.
When a SELL order occurs, it works in reverse: You should subtract the number of shares from the count and add to the cash account.
Reviews
There are no reviews yet.