Project 8 Development

From Quantitative Analysis Software Courses
Revision as of 21:25, 15 March 2020 by Jfox44 (talk | contribs) (Created page with "== Due Date== 4/19/2020 11:59PM [https://www.timeanddate.com/time/zones/aoe Anywhere on Earth time] ==Revisions== This assignment is subject to change up until 3 weeks prio...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Due Date

4/19/2020 11:59PM Anywhere on Earth time

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 take a minimum of the 3 indicators created in Project 6 and:

  • Develop a trading strategy using your intuition and Technical Analysis, and test it against a stock using your market simulator
  • Design a learning trading agent
    • You must draw on the learners you have created so far in the course. Your choices are:
    1. Regression or classification-based learner: Create a strategy using your Random Forest learner. Suggestions if you follow this approach: Classification_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 overfitting in-sample. For classification, you must use mode rather than mean (RTLearner, BagLearner).
    2. Reinforcement Learner-based approach: Create a Q-learning-based strategy using your Q-Learner. Read the Classification_Trader_Hints first, 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 Classification_Trader_Hints first, 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., addEvidence()) your learner will be provided with a stock symbol and a time period. It should use this data to learn a strategy. For instance, for a regression-based learner it 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 exactly the same indicators as in the manual strategy project so we can compare your results. You may optimize your indicators for time (vectorization), but there should be no changes to lookback windows or any other pertinent parameters.
    • If the date range is the same as used for the training, it is an in-sample test. Otherwise it is an out-of-sample test. 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 addEvidence() method. The timeout requirements (see rubric) will be set accordingly. Multiple calls to your testPolicy() method should return exactly the same result.

Overall, your tasks for this project include:

  • Devise numerical/technical indicators to evaluate the state of a stock on each day.
  • Build a manual strategy that uses the indicators.
  • Build a strategy learner based on one of the learners described above that uses the indicators.
  • Test/debug the strategy learner on specific symbol/time period problems.
  • Write a report describing your manual strategy and strategy learner.

Template

Instructions:

  • Download and install the files from this zip file File:20Spring strategy evaluation.zip
  • ManualStrategy.py Code implementing a ManualStrategy object (your manual strategy) in the strategy_learner/ 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 file yourself.
  • Place your existing Q-Learner or RTLearner (Okay to include DTLearner as well if inheritance is involved) or OptimizationLearner into the strategy_evaluation/ directory.
  • StrategyLearner.py Code implementing a StrategyLearner object (your ML strategy) in the strategy_learner directory.
  • See "what to turn in" below for a list of files that should be submitted.
  • To test your strategy learner, follow the instructions on Running the grading scripts

Data Details, Dates and 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 more easily compare results. We will test your learner with other symbols as well.
  • You may use data from other symbols (such as SPY) to inform your strategy.
  • The in sample/development 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.
  • Benchmark: The performance of a portfolio starting with $100,000 cash, investing in 1000 shares of the symbol in use and holding that position. Include transaction costs.
  • There is no limit on leverage.
  • Transaction costs:
    • ManualStrategy and StrategyLearner Report: Commission: $9.95, Impact: 0.005 (unless stated otherwise).
    • Auto-Grader Commission will always be $0.00, Impact may vary, and will be passed in as a parameter to the learner.
  • Minimize use of herrings.


Tasks

Implement Manual Rule-Based Trader (XX points)

In ManualStrategy.py implement a set of rules using at a minimum 3 indicators you created in Project 6. Devise some simple logic using your indicators to enter and exit positions in the stock.

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 this 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 figure.

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). 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.

Your code should implement the same API as for theoretically optimal:

   df_trades = ms.testPolicy(symbol = "AAPL", sd=dt.datetime(2010, 1, 1), ed=dt.datetime(2011,12,31), sv = 100000)

Implement Strategy Learner (XX Points)

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 ManualStrategy. 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 or 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.

Your StrategyLearner should implement the following API:

import StrategyLearner as sl
learner = sl.StrategyLearner(verbose = False, impact = 0.000) # constructor
learner.addEvidence(symbol = "AAPL", sd=dt.datetime(2008,1,1), ed=dt.datetime(2009,12,31), sv = 100000) # training phase
df_trades = learner.testPolicy(symbol = "AAPL", sd=dt.datetime(2010,1,1), ed=dt.datetime(2011,12,31), sv = 100000) # testing phase

The input parameters are:

  • verbose: if False do not generate any output
  • impact: The market impact of each transaction.
  • symbol: the stock symbol to train on
  • sd: A datetime object that represents the start date
  • 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.

Implement author() function (deduction if not implemented)

You should implement a function called author() that returns your Georgia Tech user ID as a string. 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():

    def author():
        return 'tb34' # replace tb34 with your Georgia Tech username.

Implementing this method correctly does not provide any points, but there will be a penalty for not implementing it.

Report

Indicator Overview

Briefly describe the indicators you used to devise your Manual Strategy and Strategy Learner from the indicators you implemented in Project 6. You must use a minimum of 3 indicators of the 5 you implemented.

Manual Strategy

Describe how you combined your indicators to create an overall signal. How do you decide to enter and exit your positions and why? Why do you believe (or not) that this is an effective strategy? Create a chart that shows, in sample:

  • Benchmark (see definition above): Green 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.

Compare the performance of your manual strategy versus the benchmark for the in sample and out of sample time periods. Provide a chart.

Evaluate the performance of your strategy in the out of sample period. Note that you should not train or tweak your approach on this data. You should use the classification learned using the in sample data only. Create a chart that shows, out of sample:

  • Benchmark (see definition above): Green 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.

Create a table that summarizes the performance of the stock, and the manual strategy for both in sample and out of sample periods. Explain WHY these differences occur.

Strategy Learner

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 how you discretized (standardized) or otherwise adjusted your data. If not, tell us why not.

Experiment 1: Using exactly the same indicators that you used in manual_strategy (trade JPM), compare your manual strategy with your learning strategy in sample. The code that implements this experiment and generates the relevant charts and data should be submitted as experiment1.py.

  • Describe your experiment in detail: Assumptions, parameter values and so on.
  • Describe the outcome of your experiment.
  • Would you expect this relative result every time with in-sample data? Explain why or why not.

Experiment 2: Provide a hypothesis regarding how changing the value of impact should affect in sample trading behavior and results (provide at least two metrics). Conduct an experiment with JPM on the in sample period with a commission of $0.00 to test that hypothesis. Provide charts, graphs or tables that illustrate the results of your experiment. The code that implements this experiment and generates the relevant charts and data should be submitted as experiment2.py.

Your descriptions should be stated clearly enough that an informed reader could reproduce the results without referencing your code.

What to turn in

Be sure to follow these instructions diligently! No zip files.

Submit the following files (only) via Canvas before the deadline:

  • Project 8: Strategy Evaluation (Report)
    • Your report as report.pdf.
  • Project 6: Strategy Evaluation (Code)
    • Your code as <Implemented Learner>.py, indicators.py, ManualStrategy.py, StrategyLearner.py, ManualStrategy.py, experiment1.py, experiment2.py and marketsimcode.py (optional if needed)
      • <Implemented Learner.py> refers to: QLearner.py, or RTLearner (okay to submit DTLearner if using inheritance) and BagLearner.py or OptimizeLearner.py.
    • README.txt document

Make sure that you submit all code that is necessary for your software to run including plotting. If your code crashes because of a missing file, you may lose signficant points on the code section.

Do not submit any other files. Penalties will be assessed for additional files outside of the allowed ones as stated above.

Unlimited resubmissions are allowed up to the deadline for the project.

Rubric

Report

Auto-Grader

Code

Required, Allowed & Prohibited