CS 7646
Machine Learning for Trading
咨询 Alpha 小助手,获取更多课业帮助
1 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.
1.1 Learning Objectives
The speci c 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 they aect the value of a portfolio.
3 YOUR IMPLEMENTATION
Your submission must implement this API speci cation.
Before the deadline, make sure to pre-validate your submission using Gradescope TESTING. Once you are satis ed 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).
3.1 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 called “marketsim” to the course directory structure.
3.2 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 le marketsim.py. It should adhere to the following API.
The start date and end date of the simulation are the rst and last dates with orders in the orders_ le. (Note: The orders may not appear in sequential order in the le.) The arguments are as follows. orders_le is the name of a le from which to read orders, and start_val is the starting value of the portfolio (initial cash available) commission is the xed 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 rst column from start_date to end_date, inclusive. The les containing orders are CSV les with the following columns:
3.2.1 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.