Opto Trader Hints

From Quantitative Analysis Software Courses
Revision as of 14:46, 22 November 2017 by Tucker (talk | contribs) (→‎ML Trader)
Jump to navigation Jump to search

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

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.