Difference between revisions of "Opto Trader Hints"

From Quantitative Analysis Software Courses
Jump to navigation Jump to search
 
(One intermediate revision by the same user not shown)
Line 5: Line 5:
 
==ML Trader==
 
==ML Trader==
  
Convert your decision tree '''regression''' learner into a '''classification''' learner.  The classifications should be:
+
Recall your manual trader: You should have used one or more indicators, then you used a simple set of logical statements to decide on an action.  Those logical statements should include statements like "if indicator1 < threshold1 and indicator2 > threshold2" The idea for this version of the project is to use an optimizer to find the values of these thresholds rather than setting them manually.  More succinctly, the optimization problem is:
 +
 
 +
* Given: a set of parameters: threshold[0] to threshold[n-1]
 +
* Find: values for the parameters that maximize Sharpe ratio of the corresponding trading strategy.
 +
 
 +
Your objective function for the optimizer is thus the Sharpe ratio of the strategy.  The logic you use should classify a particular state (set of indicator values) as:
  
 
* +1: LONG
 
* +1: LONG
Line 11: Line 16:
 
* -1: SHORT
 
* -1: SHORT
  
The X data for each sample (day) are simply the values of your indicators for the stock -- you should have 3 to 5 of them.  The Y data (or classifications) will be based on N day return (your choice for N).  You should classify the example as a +1 or "LONG" if the N day return exceeds a certain value, let's call it YBUY for the moment.  You should classify the example as a -1 or "SHORT" if the N day return is below a certain value we'll call YSELL.  In all other cases the sample should be classified as a 0 or "CASH."  Note that it is very important that you train your learner with these classification values (not the N day returns). 
+
The X data for each sample (day) are simply the values of your indicators for the stock -- you should have 3 to 5 of them.  Once you have these values, you can use the classifications to generate a set of transactions which you then assess the Sharpe ratio of.
 
 
Note that your X values are calculated each day from the current day's (and earlier) data, but the Y value (classification) is calculated using data from the future.  You may tweak various parameters of your learner to maximize return (more on that below).  Train and test your learning strategy over the in sample period.
 
 
 
'''Important note:''' You must set the leaf_size parameter of your decision tree learner to 5 or larger.  This requirement is intended to avoid a degenerate overfit solution to this problem.
 
 
 
You should tweak the parameters of your learner to maximize performance during the in sample period.  Here is a partial list of things you can tweak:
 
* Adjust YSELL and YBUY.
 
* Adjust leaf_size.
 
* Utilize bagging and adjust the number of bags.
 
  
 
==Hints==
 
==Hints==
 
'''Overall, I recommend the following steps in the creation of your strategies:'''
 
 
* Indicator design hints:
 
** For your X values: Identify and implement at least 3 technical features that you believe may be predictive of future return.
 
* Rule based design:
 
** Use a cascade of if statements conditioned on the indicators to identify whether a LONG condition is met.
 
** Use a cascade of if statements conditioned on the indicators to identify whether a SHORT condition is met.
 
** The conditions for LONG and SHORT should be mutually exclusive.
 
** If neither LONG or SHORT is triggered, the result should be CASH.
 
** For debugging purposes, you may find it helpful to plot the value of the rule-based output (-1, 0, 1) versus the stock price.
 
* Train a classification learner on in sample training data:
 
** For your Y values: Use future N day return (not future price).  Then classify that return as LONG, SHORT or CASH.  You're trying to predict a relative change that you can use to invest with.
 
** For debugging purposes, you may find it helpful to plot the value of the training classification data (-1, 0, 1) versus the stock price in one color.
 
** For debugging purposes, you may find it helpful to plot the value of the training classification output (-1, 0, 1) versus the stock price in another color.  Ideally, these two lines should be very similar.
 
 
Your code should classify based on N day change in price.  You need to build a new Y that reflects the N day change and aligns with the current date.  Here's pseudo code for the calculation of Y
 
 
ret = (price[t+N]/price[t]) - 1.0
 
if ret > YBUY:
 
    Y[t] = +1 # LONG
 
else if ret < YSELL:
 
    Y[t] = -1 # SHORT
 
else:
 
    Y[t] = 0 # CASH
 
 
If you select Y in this manner and use it for training, your learner will classify N day returns.
 

Latest revision as of 15:00, 28 November 2017

Overview

You will draw on your experience with your manual strategy and optimization to train and test a learning trading algorithm.

ML Trader

Recall your manual trader: You should have used one or more indicators, then you used a simple set of logical statements to decide on an action. Those logical statements should include statements like "if indicator1 < threshold1 and indicator2 > threshold2" The idea for this version of the project is to use an optimizer to find the values of these thresholds rather than setting them manually. More succinctly, the optimization problem is:

  • Given: a set of parameters: threshold[0] to threshold[n-1]
  • Find: values for the parameters that maximize Sharpe ratio of the corresponding trading strategy.

Your objective function for the optimizer is thus the Sharpe ratio of the strategy. The logic you use should classify a particular state (set of indicator values) as:

  • +1: LONG
  • 0: CASH
  • -1: SHORT

The X data for each sample (day) are simply the values of your indicators for the stock -- you should have 3 to 5 of them. Once you have these values, you can use the classifications to generate a set of transactions which you then assess the Sharpe ratio of.

Hints