Machine Learning for Price Wave Analysis

Discussion in 'Strategy Building' started by ph1l, Jan 19, 2020.

  1. ph1l

    ph1l

    I've been trying to use machine learning to predict potential ranges of future price waves with my genetic program rules generator.

    Disclaimer: No Fibonacci numbers were harmed during the writing of this post.:)

    Using daily price data adjusted for splits and dividends for assorted ETFs, scripts first find price waves:
    • The swing direction starts as undefined.
    • If no price within the past N bars is higher than today's high price, the swing direction is up.
    • If no price within the past N bars is low than today's low price, the swing direction is down.
    • If the swing direction is measured as both up and down, the swing direction does not change.
    • If the swing direction changes from not up to up, a low wave point is the low of the most recent price bar with the lowest price within the past N bars.
    • If the swing direction changes from not down to down, a high wave point is the high of the most recent price bar with the highest price within the past N bars.
    • The first wave point found is ignored.

    An example wave instance with using 10 bars to define waves and 8 wave points:
    upload_2020-1-19_20-14-10.png

    For evaluation data, rules generated for the most recent M wave points in history (referred to as hw0, hw1, ... hwM-1) predict data about the pending future wave point (referred to as pw0).
    Training data has an additional future wave point.

    Scripts generate data for relationships among the wave points scaled on the time and price axes including:
    • the absolute price difference between two history waves as a percentage the maximum price difference among the hw0 through hwM-1. 0 <= value <= 100.
    • the absolute price difference between hw0 and pw0 as a percentage the maximum price difference among the hw0 through hwM-1. 0 <= value, and values can be > 100. This is the predicted target value.
    • the angle between two wave points moving forward in time and up/down in price for a positive/negative angle. -90 degrees < value < 90 degrees.
    • the sum of two angles. -180 degrees < value < 180 degrees.
    • the difference between two angles. -180 degrees < value < 180 degrees.

    The rules generator tries to classify relationships among the history wave points for a class of predicted target values where a class has the highest X percent of the predicted target values. For example,
    Code:
    rule      1 hw0_to_pw0_wpricepct_08    <-  /fitness 1.4006 /numWins 1410 /numHits 1993 /netWins 827 /mean 76.8945 /perfMeasure 632.518 /winPct 70.7476 /hitPct 30.6946 /numTxns 6493 /numInstr 300 /crc 6dfdda05f876af71
        0000: if  hw5_to_hw0_angle_plus_hw4_to_hw0_angle <= hw7_to_hw3_angle
        0001:         if  3.634 > hw7_to_hw0_angle_plus_hw6_to_hw0_angle
        0002:                 if  hw2_to_hw1_wpricepct >= 25.7066
        0003:                         if  21.692 >= hw5_to_hw2_angle_plus_hw3_to_hw1_angle
        0004:                                 if  14.1265 <= hw7_to_hw3_wpricepct
        0005:                                         if  3.09599 <= hw7_to_hw5_angle_plus_hw3_to_hw1_angle
        0006:                                                 return  238.318
        0007: if  hw4_to_hw2_angle_minus_hw3_to_hw2_angle < -40.859
        0008:         if  hw5_to_hw4_wpricepct >= 55.7305
        0009:                 if  78.3906 < hw3_to_hw0_wpricepct
        0010:                         return  238.318
    ...
        0294: if  -70.108 > hw6_to_hw4_angle_minus_hw1_to_hw0_angle
        0295:         if  hw6_to_hw5_angle_plus_hw4_to_hw3_angle >= hw4_to_hw3_angle_plus_hw2_to_hw1_angle
        0296:                 if  hw6_to_hw5_angle_plus_hw1_to_hw0_angle > hw7_to_hw1_angle_minus_hw3_to_hw1_angle
        0297:                         if  hw7_to_hw5_angle_minus_hw6_to_hw2_angle > hw6_to_hw1_angle_plus_hw3_to_hw1_angle
        0298:                                 if  hw6_to_hw1_angle_minus_hw4_to_hw2_angle <= hw7_to_hw0_angle
        0299:                                         return  238.318
        return NAN
    
    This rule either returns a constant value in the predicted class which means the rule thinks the conditions are in the predicted class or NAN when the rule doesn't think the conditions are in the predicted class.
    The example has 6493 instances of the hw0 through the hw7 where the rule successfully predicted the class 1410 out of 1993 times.

    For C classes, rules set instance i where 0 <= i < C is for the highest (C - i) / (C + 1) * 100 percent of the complete list of predicted target values.

    For the example above with class 08 out of 12 total classes the class has the highest (12-8)/(12+1) * 100 == 30.7692 percent of the complete list of predicted target values (or the 69.23rd percentile).

    Running the rules on evaluation data with calculations from the low values of predicted class data with data known at the detected date of hw0 can result in output like:
    upload_2020-1-19_20-15-16.png

    So for symbol XLRE with low wave point hw0 on 2020-01-07 with price 37.884998 and detected on 2020-01-13, the minimum target value for the highest class hit was 39.56489456188. Prices reached this target on 2020-01-17.
     
    beginner66 and Sprout like this.