PROJECT 8: STRATEGY EVALUATION
h Table of Contents
About the Project
Your Implementation Contents of Report Testing Recommendations Submission Requirements Grading Information Development Guidelines
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.
$ $ $ $ $ $ $ $
Programming Help
1 OVERVIEW
In this assignment, you implement two strategies and compare their performance. One strategy is a manual strategy, where you will develop the trading rules. The other is a strategy learner, which will develop the trading rules using arti cial intelligence. You will submit the code for the project in Gradescope SUBMISSION. You will also submit a report to Canvas.
1.1 Learning Objectives
This project builds on the work of several earlier projects. The speci c learning objectives for this assignment are focused on the following areas:
Trading Solution: This project represents the capstone project for the course. This synthesizes the investing and machine learning concepts; and integrates many of the technical components developed in prior projects.
Trading Policy Comparison: Provides an opportunity to evaluate the performance of a manual strategy with that of the AI-learner to better understand its behavior and how it works relative to human-developed strategies.
Foundation for Continued Learning: The knowledge learned and
the components throughout the course can serve as a foundation for continued learning and research in trading, machine learning, reinforcement learning, and/or investing.
程序代写 CS代考 加QQ: 749389476
2 ABOUT THE PROJECT
In this project, you will select a minimum of three and a maximum of all ve indicators from Project 6 and use the same indicators in a manual and strategy learner.
2.1 Indicator Selection
Choose at least 3 indicators. We recommend that these be the same ones researched and reported in P6, however, if you are nding you cannot achieve the results you would like, you may use one new indicator. Note that you can choose only 2 indicators from {SMA, Bollinger Bands, RSI}, just as in P6. Hint: If you’re nding poor results using the suggested indicators, be sure to verify your learner’s implementations.
You can only use the indicators that were reported on P6. If you created an EMA function as part of the MACD indicator, you may only use MACD as the indicator and not EMA. You may use EMA if you reported EMA as an indicator.
Indicators must return a single results vector. As an example, the MACD indicator can only return one vector. This means it must return a custom scalar array that you develop that provides the information you need, the existing Signal line as an array, or the MACD line as an array.
Indicators can only be used once
2.2 Overall Approach
Build a Manual Strategy, implemented as a class, that combines a minimum of 3 out of the 5 indicators from Project 6.
Build a Strategy Learner, implemented as a class, based on one of the learners described above that uses the same 3+ indicators as used in the manual strategy.
Test/debug the Manual Strategy and Strategy Learner on speci c symbol/time period problems.
Conduct experiments.
Write a report describing your Manual Strategy, Strategy Learner, and
Experiments.
2.3 Implement a Strategy Learner
You must draw on the learners you have created so far in the course. Your choices are:
1. Classi cation-based learner: Create a strategy using your Random Forest learner. Suggestions if you follow this approach: Classi cation_Trader_Hints. Important note, if you choose this method, you must set the leaf_size for your learner to 5 or greater. This is to avoid degenerate over tting in-sample. For classi cation, you must convert your regression learner to use mode rather than mean (RTLearner, BagLearner).
2. Reinforcement-based learner: Create a Q-learning-based strategy using your Q- Learner. Read the Classi cation_Trader_Hints rst, because many of the ideas there are relevant for the Q trader, then see Q_Trader_Hints. For Q-learning, use the same binning cuts for in-sample and out-of-sample.
3. Optimization-based learner: Create a scan-based strategy using an optimizer, which must be used in conjunction with the Classi cation-based or Reinforcement-based learner. Read the Classi cation_Trader_Hints rst, because many of the ideas there are relevant for the Opto trader, then see Opto_Trader_Hints
Regardless of your choice above, your learner should work in the following way:
In the training phase (e.g., add_evidence()) your learner will be provided with a stock symbol and a time period. It should use this data to learn a strategy. For instance, a classi cation-based learner will use this data to make predictions about future price changes.
In the testing phase (e.g., testPolicy()) your learner will be provided a symbol and a date range. All learning should be turned OFF during this phase.
You should use the same indicators as you use in the Manual Strategy in Strategy Learner so we can compare your results. You may optimize your indicators for time (vectorization).
Your learner should return a trades DataFrame like it did in the last project. Here are some important requirements: Your testPolicy() method should be much faster than your add_evidence() method. The timeout requirements (see rubric) will be set accordingly. Multiple calls to your testPolicy() method should return exactly the same result.
2.4 Overall Considerations
Overall, your tasks for this project include:
Build a Manual Strategy, implemented as a class, that combines a minimum of 3 out of the 5 indicators from Project 6.
Build a Strategy Learner, implemented as a class, based on one of the learners described above that uses the same 3+ indicators as used in the manual strategy.
Test/debug the Manual Strategy and Strategy Learner on speci c symbol/time period problems.
Conduct experiments.
Write a report describing your Manual Strategy, Strategy Learner, and Experiments.
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
To make it easier to get started on the project and focus on the concepts involved, you will be given a starter framework. This framework assumes you have already set up the local environment and ML4T Software. The framework for Project 8 can be obtained from: Strategy_Evaluation_2023Fall.zip.
Extract its contents into the base directory (e.g., ML4T_2023Fall). This will add a new folder called “strategy_evaluation” to the course directory structure:
The framework for Project 8 can be obtained in the strategy_evaluation folder alone. Within the strategy_evaluation is the grading script:
grade_strategy_learner.py
Script to test your implementation. This matches the publicly available tests for this project. This le does not need to be turned in and allows you to test locally.
Additional les will also need created and added to the project directory. These les are
from previous projects or will need to be created: testproject.py
Code initializing/running all necessary les for the report. NOTE: You will have to create the contents of this le yourself.
ManualStrategy.py
Code implementing a ManualStrategy object (your Manual Strategy) in the strategy_evaluation/ directory. It should implement testPolicy() which returns a trades data frame (see below). The main part of this code should call marketsimcode as necessary to generate the plots used in the report. NOTE: You will have to create this le yourself.
Place your existing Q-Learner, RTLearner, and BagLearner (and DTLearner as well if inheritance is involved), or OptimizationLearner into the strategy_evaluation/ directory.
Place your existing indicators.py into the strategy_evaluation/ directory
NOTE: You can make changes to the indicators to properly work with both Manual Strategy and Strategy Learner but both strategies must use the same indicator code. If you choose to create new indicators, add them to indicators.py.
Place your existing marketsimcode.py into the strategy_evaluation/ directory
(optional: if needed; note that this is marketsimcode.py and not marketsim.py).
StrategyLearner.py
Code implementing a StrategyLearner object (your ML strategy) in the strategy_evaluation directory. NOTE: You will have to create this le yourself.
experiment1.py and experiment2.py
Code conducting the experiments outlined below. NOTE: You will have to
create these les yourself.
See “what to turn in” below for a list of les that should be submitted.
3.2 Data Details, Dates & Rules
Use only the data provided for this course. You are not allowed to import external data.
For your report, trade only the symbol JPM. This will enable us to compare results more easily. We will test your Strategy Learner with other symbols as well.
You may use data from other symbols (such as SPY) to inform both your Manual Strategy and Strategy Learner.
The in-sample period is January 1, 2008 to December 31, 2009.
The out-of-sample/testing period is January 1, 2010 to December 31, 2011.
Starting cash is $100,000.
Allowable positions are: 1000 shares long, 1000 shares short, 0 shares.
Only buy/sell actions are allowed. Stops, trailing stops, stop-loss, or any other trading setup is not allowed.
Benchmark: The performance of a portfolio starting with $100,000 cash, investing in 1000 shares of the symbol in use on the rst trading day, and holding that position. Include transaction costs.
There is no limit on leverage. This means that you do not need to con rm that you have the capital to make your trade. All trades can be executed without validating available cash in your portfolio.
Transaction costs:
ManualStrategy and StrategyLearner: Commission: $9.95, Impact: 0.005 (unless stated otherwise in an experiment).
Auto-Grader Commission will always be $0.00, Impact may vary, and will be passed in as a parameter to the learner
3.3 Tasks & Requirementsts
You will implement a manual rule-based trader, the strategy learner, and conduct experiments.
3.3.1 Implement Manual Rule-Based Trader
Not included in the template. You will have to create this code le.
Create ManualStrategy.py and implement a set of rules using at a minimum of 3 indicators you created in Project 6 (NOTE: You can make changes to the indicators to properly work with both Manual Strategy and Strategy Learner but both strategies must use the same indicator code). Devise some simple logic using your indicators to
enter and exit positions in the stock. All indicators must be used in some way to determine a buy/sell signal. You cannot use a single indicator for all signals.
A recommended approach is to create a single logical expression that yields a -1, 0, or 1, corresponding to a “short,” “out” or “long” position. Example usage is signal: If you are out of the stock, then a 1 would signal a BUY 1000 order. If you are long, a -1 would signal a SELL 2000 order. You don’t have to follow this advice though, so long as you follow the trading rules outlined above.
For the report we want a written description, not code, however, it is OK to augment your written description with a pseudocode gure.
You should tweak your rules as best you can to get the best performance possible during the in-sample period (do not peek at out-of-sample performance) and should include more than one trade. Use your rule-based strategy to generate a trades DataFrame over the in-sample period.
We expect that your rule-based strategy should outperform the benchmark over the in- sample period.
Benchmark: The performance of a portfolio starting with $100,000 cash, investing in 1000 shares of JPM on the rst trading day, and holding that position.
Your ManualStrategy will also need to create two charts. For the in-sample period:
Benchmark (starting with $100,000 cash, investing in 1000 shares of JPM, and holding that position): Purple line
Performance of Manual Strategy: Red line
Both should be normalized to 1.0 at the start. Vertical blue lines indicating LONG entry points. Vertical black lines indicating SHORT entry points.
For the out-of-sample period:
Benchmark (starting with $100,000 cash, investing in 1000 shares of JPM, and
holding that position): Purple line
Performance of Manual Strategy: Red line
Both should be normalized to 1.0 at the start. Vertical blue lines indicating LONG entry points. Vertical black lines indicating SHORT entry points.
Note: The vertical lines are short and long entry points, not buy and sell indicators.
Create a table that summarizes the performance of the stock, and the Manual Strategy for both in-sample and out-of-sample periods. At a minimum, the table must include:
Cumulative return of the benchmark and Manual Strategy portfolio STDEV of daily returns of the benchmark and Manual Strategy portfolio Mean of daily returns of the benchmark and Manual Strategy portfolio
Your ManualStrategy should implement the following API:
3.3.2 Implement Strategy Learner
For this part of the project, you should develop a learner that can learn a trading policy using your learner and the same indicators used in the Manual Strategy (NOTE: You can make changes to the indicators to properly work with both Manual Strategy and Strategy Learner but both strategies must use the same indicator code). You must draw on the learners you have created so far in the course. Your choices are:
1. Classi cation-based learner: Create a strategy using your Random Forest learner. Suggestions if you follow this approach: Classi cation_Trader_Hints. Important note, if you choose this method, you must set the leaf_size for your learner to 5 or greater. This is to avoid degenerate over tting in-sample. For classi cation, you must convert your regression learner to use mode rather than mean in both the RTLearner and BagLearner.
2. Reinforcement-based learner: Create a Q-learning-based strategy using your Q- Learner. Read the Classi cation_Trader_Hints rst, because many of the ideas there are relevant for the Q trader, then see Q_Trader_Hints. For Q-learning, use the same binning cuts for in-sample and out-of-sample.
3. Optimization-based learner: Create a scan-based strategy using an optimizer. Read the Classi cation_Trader_Hints rst, because many of the ideas there are relevant for the Opto trader, then see Opto_Trader_Hints
Regardless of your choice above, your learner should work in the following way:
In the training phase (e.g., add_evidence()) your learner will be provided with a stock symbol and a time period. It should use this data to learn a strategy. For instance, a classi cation-based learner will use this data to make predictions about future price changes.
1 df_trades = ms.testPolicy(symbol = “AAPL”, sd=dt.datetime(2010, 1, 1), ed=
buHtiG yb ❤ htiw detsoh yp.ipa_ygetarts_launam
In the testing phase (e.g., testPolicy()) your learner will be provided a symbol and a date range. All learning should be turned OFF during this phase.
You should use the same indicators as you use in the Manual Strategy in Strategy Learner so we can compare your results. You may optimize your indicators for time (vectorization).
Your learner should return a trades DataFrame like it did in the last project. Here are some important requirements: Your testPolicy() method should be much faster than your add_evidence() method. The timeout requirements (see rubric) will be set accordingly. Multiple calls to your testPolicy() method should return exactly the same result.
You should be able to use your Q-Learner or RTLearner from the earlier project directly. If you want to use the optimization approach, you will need to create new code for that. You will need to write code in StrategyLearner.py to “wrap” your learner appropriately to frame the trading problem for it. Utilize the template provided in StrategyLearner.py. Remember that impact should be included in the learner’s decision process.
Your Strategy Learner should nd the optimal parameters **that you choose to optimize** for each indicator and should result in more than one trade. Remember, the indicators used must match those used for Manual Strategy. However, optimization of the indicators does not need to match that of Manual Strategy. Example: for SMA the learner could nd the optimal lookback window to use.
NOTE: Lookback windows are not required to be optimized. You can use the same window used in the Manual Strategy if you wish.
Your StrategyLearner should implement the following API:
1 import StrategyLearner as sl
2 learner = sl.StrategyLearner(verbose = False, impact = 0.0, commission=0.0
3 learner.add_evidence(symbol = “AAPL”, sd=dt.datetime(2008,1,1), ed=dt.date
4 df_trades = learner.testPolicy(symbol = “AAPL”, sd=dt.datetime(2010,1,1),
buHtiG yb ❤ htiw detsoh yp.ipa_renrael_ygetarts
The input parameters are:
verbose: if False do not generate any output impact: The market impact of each transaction commission: The commission amount charged. symbol: The stock symbol to train on
sd: A datetime object that represents the start date
Computer Science Tutoring
ed: A datetime object that represents the end date sv: Start value of the portfolio
The output result is:
df_trades: A data frame whose values represent trades for each day. Legal values are +1000.0 indicating a BUY of 1000 shares, -1000.0 indicating a SELL of 1000 shares, and 0.0 indicating NOTHING. Values of +2000 and -2000 for trades are also legal when switching from long to short or short to long so long as net holdings are constrained to -1000, 0, and 1000.
3.3.3 Implement Experiment 1
Not included in the template. You will have to create this code le.
Experiment 1 should compare the results of your manual strategy and the strategy learner. It should:
Compare your Manual Strategy with your Strategy Learner in-sample trading JPM. Create a chart that shows:
Value of the ManualStrategy portfolio (normalized to 1.0 at the start) Value of the StrategyLearner portfolio (normalized to 1.0 at the start) Value of the Benchmark portfolio (normalized to 1.0 at the start)
Compare your Manual Strategy with your Strategy Learner out-of-sample trading JPM. Create a chart that shows:
Value of the ManualStrategy portfolio (normalized to 1.0 at the start) Value of the StrategyLearner portfolio (normalized to 1.0 at the start) Value of the Benchmark portfolio (normalized to 1.0 at the start)
The code that implements this experiment and generates the relevant charts and data should be submitted as experiment1.py.
See DATA DETAILS, DATES & RULES section above for commission and impact information.
3.3.4 Implement Experiment 2
Not included in the template. You will have to create this code le.
Conduct an experiment with your StrategyLearner that shows how changing the value of impact should a ect in-sample trading behavior.
Select two metrics, and generate tests that will provide you with at least
3 measurements when trading JPM on the in-sample period with a commission of $0.00. Generate charts that support your tests and show your results.
The code that implements this experiment and generates the relevant charts and data should be submitted as experiment2.py.
See the ‘Report’ section on Experiment 2 for more details.
3.3.5 Implement Test Project
Execution Limit: 10 minutes
Not included in the template. You will have to create this code le.
Create testproject.py. Testproject.py is the entry point to your project, and it
should implement the necessary calls (following each respective API) to Manual Strategy.py, StrategyLearner.py, experiment1.py, and experiment2.py with the appropriate parameters to run everything needed for the report in a single Python call:
3.3.6 Implement author() function/method
Deduction if not implemented
You should implement a function called author() that returns your Georgia Tech user ID as a string in all python les. This is the ID you use to log into Canvas. It is not your 9 digit student number. Here is an example of how you might implement author():
3.4 Technical Requirements
The following technical requirements apply to this assignment: The le testproject.py must run within 10 minutes.
3.5 Hints and Resources
1 PYTHONPATH=../:. python testproject.py
buHtiG yb ❤ htiw detsoh tcejorptset
1 def author():
2 return ‘tb34’ # replace tb34 with your Georgia Tech username.
buHtiG yb ❤ htiw detsoh yp.elpmaxe_rohtua
You can use util.py to read some other values (e.g., columns other than adjusted close) from the data. Look carefully at util.py and you will see that you can query for other values.
Your positions must be one of three xed sizes: -1000 shares, +1000 shares, 0 shares.
You can trade up to 1000 or 2000 shares at a time as long as you maintain the requirement of holding 1000, 0, or -1000 shares.
There is no limit on leverage. This means that you don’t need to verify that you have enough cash in your portfolio to make a trade.
4 CONTENTS OF REPORT
Answer the following prompt in a maximum of 10 pages (excluding references) in JDF format. Any content beyond 10 pages will not be considered for a grade. Ten pages is a maximum, not a target; our recommended per-section lengths intentionally add to less than 10 pages to leave you room to decide where to delve into more detail. This length is intentionally set expecting that your submission will include diagrams, drawings, pictures, etc. These should be incorporated into the body of the paper unless speci cally required to be included in an appendix.
The JDF format speci es font sizes and margins, which should not be altered. Include charts and tables to support each of your answers. Charts and tables should be generated by the code and saved to les. Charts should be properly annotated with legible and appropriately named labels, titles, and legends. Tables should be properly annotated with column names. When numbers are presented in tables, ensure a su cient level of numeric precision is provided.
Please address each of these points/questions in your report. You may include additional charts in your submission, but the total number of charts may not exceed 10 charts. The report is to be submitted as p8_strategyEval_report.pdf.
At a minimum, the report must contain the following sections: Introduction: ~ 0.5 pages (Optional)
The report should brie y describe the paper’s justi cation. While the introduction may assume that the reader has some domain knowledge, it should assume that the reader is unfamiliar with the speci cs of the assignment. The introduction should also present an initial hypothesis (or hypotheses).
Indicator Overview: ~1 page
Brie y describe the indicators you used to devise your Manual Strategy and Strategy Learner. You must use a minimum of 3 indicators of the 5 you implemented in Project 6. At a minimum, for each indicator discuss the following:
Include a brief description of how the indicator is implemented.
Discuss the parameters for each indicator that are optimized in both Manual Strategy and Strategy Learner.
Hint: If you use Bollinger Bands in Project 6 and want to use that indicator here, you can replace it with BB %B, which should work better with this assignment.
Manual Strategy: ~3 pages
Describe how you combined your indicators to create an overall signal. Explain how and why you decide to enter and exit your positions? Why do you believe (or not) that this is an e ective strategy?
Compare the performance of your Manual Strategy versus the benchmark for the in- sample and out-of-sample time periods. Provide your charts to support the discussion.
Evaluate the performance of your strategy in the out-of-sample period. Note that you should not train or tweak your approach to this data. You should use the classi cation learned using the in-sample data only.
Explain WHY these di erences occur. Strategy Learner: ~1.5 pages
The centerpiece of this section should be the description of how you utilized your learner to determine trades:
Describe the steps you took to frame the trading problem as a learning problem for your learner.
Describe the hyperparameters, their values, and how they were determined.
Describe how you discretized (standardized) or otherwise adjusted your data. If this was not performed or necessary, explain why.
Experiment 1 (Manual Strategy / Strategy Learner): ~1.5 pages
Describe your experiment in detail: This includes any assumptions, the initial experimental hypothesis, parameter values, and any other information that would enable an informed reader to set up and repeat the experiment.
Describe, interpret, and summarize the outcome of your experiment, and include your charts from experiment 1. Would you expect this relative result every time with in- sample data? Explain why or why not.
Experiment 2 (Strategy Learner): ~1.5 pages
Provide a hypothesis regarding how changing the value of impact should a ect in- sample trading behavior and results (provide at least two metrics, assessing a minimum of 3 di erent measurements for each metric).
Your descriptions should be stated clearly enough that an informed reader could conduct the experiment and reproduce the results without referencing your code.
References: ~0.25 pages (Optional)
References should be placed at the end of the paper in a dedicated section. Reference lists should be numbered and organized alphabetically by the author’s last name. If multiple papers have the same author(s) and year, you may append a letter to the end of the year to allow di erentiated in-line text (e.g. Joyner, 2018a and Joyner, 2018b in the section above). If multiple papers have the same author(s), list them in chronological order starting with the older paper. Only works that are cited in-line should be included in the reference list. The reference list does not count against the length requirements.
5 TESTING RECOMMENDATIONS
To test your code, we will invoke each of the functions. You are encouraged to perform any tests necessary to instill con dence that the code will run properly when submitted for grading and will produce the required results. You should con rm that testproject.py runs as expected.
In addition to testing on your local machine, you are encouraged to submit your le to Gradescope TESTING, where some basic pre-validation tests will be performed against the code. There are two Gradescope TESTING environments; one for the strategy evaluation and another for the testproject.py le. No credit will be given for coding assignments that do not pass this pre-validation. Gradescope TESTING does not grade your assignment. The Gradescope TESTING script is not a complete test suite and does not match the more stringent private grader that is used in Gradescope SUBMISSION. Thus, the maximum Gradescope TESTING score of 60, while instructional, does not represent the minimum score one can expect when the assignment is graded using the private grading script. You are encouraged to develop additional tests to ensure that all project requirements are met.
You are allowed unlimited resubmissions to Gradescope TESTING. Please refer to the Gradescope Instructions for more information.
6 SUBMISSION REQUIREMENTS
This is an individual assignment. All work you submit should be your own. Make sure to cite any sources you reference and use quotes and in-line citations to mark any direct quotes.
Assignment due dates in your time zone can be found by looking at the Project in the Assignment menu item in Canvas (ensure your Canvas time zone settings are set up properly). This date is 23:59 AOE converted to your time zone.
Assignments received after Sunday at 23:59 AOE (even if only by a few seconds) are not accepted without advanced agreement except in cases of medical or family emergencies. In the case of such an emergency, please contact the Dean of Students.
6.1 Report Submission
Complete your report using the JDF format, then save your submission as a PDF. The report is to be submitted as p8_strategyEval_report.pdf. Assignments should be submitted to the corresponding assignment submission page in Canvas. You should submit a single PDF for this assignment. Please submit the following le(s) to Canvas in PDF format only:
p8_strategyEval _report.pdf
Do not submit any other les. All charts must be included in the report, not submitted as separate les. Also note that when we run your submitted code, it should generate all charts. Not submitting a report will result in a penalty.
You are allowed unlimited submissions of the p8_strategyEval_report.pdf le to Canvas.
6.2 Code Submission
This class uses Gradescope, a server-side auto-grader, to evaluate your code submission. No credit will be given for code that does not run in this environment and students are encouraged to leverage Gradescope TESTING prior to submitting an assignment for grading. 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).
Please submit the following le to Gradescope SUBMISSION: Your code as:
Note:
submit DTLearner if using inheritance) and BagLearner.py, and OptimizeLearner.py.
ManualStrategy.py
StrategyLearner.py
indicators.py
experiment1.py
experiment2.py
marketsimcode.py (optional