In a previous thread, I showed an example of astronomical and price data as inputs to create trading rules. Here, I'll show something similar for using only astronomical data as input including how these trading rules worked on out-of-sample data.
The input data is from the Jet Propulsion Laboratory's Horizons ephemeris computation system. The inputs are as an observer would see from New York, NY at 20:00 UTC. Each input is for a celestial body (Moon, Sun Mercury, Venus, Mars, Jupiter, or Saturn) the number of calendar days from today (e.g., 000 for today or 007 for one week ago) and an input type:
For various combinations of inputs, my rule generation software trained simulated trades using S&P 500 index prices and ephemeris data from the day before entering a trade from 1957-03-04 through 2003-05-16 where a trade was simulated going long at the close the next trading day and exiting at the close 10 trading days after entry (11632 simulated trades). Validation data unseen during training was for the day before entering a trade from 2003-05-20 through 2023-03-07 where the simulated trade was also long at the next close and exiting 10 trading days after entry (4985 simulated trades).
In my previous thread, I used genetic programming where the software created set of trading rules. Here, I manually wrote some smaller combinations of trading rules as templates and used genetic optimization to fill in constant values to create trading rules. Then, I combined trading rules from different training runs to create a larger set of rules for a higher number of trades.
In the perl rules below (you can ignore the $ in each variable name), when the return is set to 1, the trade would be taken at the next trading day's close. Each nonblank line is from a separate training run.
The baseline combined 4985 simulated trades on the whole validation data had mean gain 0.29 percent, sample standard deviation 3.36 percent, median gain 0.67 percent, and winning percent 61.54. The goal was to get trading rules with better values than the baseline (higher gains, lower standard deviation, higher winning percent).
The set of trading rules above using the validation data resulted in 2277 simulated trades with mean gain 0.63 percent, sample standard deviation 2.95 percent, median gain 0.90 percent, and winning percent 67.02. The trading rules from each of the 12 individual training runs also had better values than the baseline.
Because the future inputs can be generated, future trades can be predicted. Here are the predicted trades using the above rules for the S&P 500 through the end of May.
The combination of predicted trades would be go long at the close March 31; exit at the close April 24. Go long at the close April 27; exit at the close May 22.
The input data is from the Jet Propulsion Laboratory's Horizons ephemeris computation system. The inputs are as an observer would see from New York, NY at 20:00 UTC. Each input is for a celestial body (Moon, Sun Mercury, Venus, Mars, Jupiter, or Saturn) the number of calendar days from today (e.g., 000 for today or 007 for one week ago) and an input type:
- Azimuth -- position on the horizon: 0 to 360 degrees where 0 is north
- AzimuthRelNorth - position on the horizon: -180 to 180 degrees where 0 is north
- AzimuthRelSouth - position on the horizon: -180 to 180 degrees where 0 is south
- Elevation - position above or below the horizon: -90 to 90 degrees
- IllumPct - percent of body illuminated from the Sun: 0 through 100 percent
- IllumPctRelNew - percent of body illuminated from the Sun: -50 through 50 percent where 0 is 0 percent illuminated
- IllumPctRelFull - percent of body illuminated from the Sun: -50 through 50 percent where 0 is 100 percent illuminated
- AngDiam - angular diameter in arc seconds
For various combinations of inputs, my rule generation software trained simulated trades using S&P 500 index prices and ephemeris data from the day before entering a trade from 1957-03-04 through 2003-05-16 where a trade was simulated going long at the close the next trading day and exiting at the close 10 trading days after entry (11632 simulated trades). Validation data unseen during training was for the day before entering a trade from 2003-05-20 through 2023-03-07 where the simulated trade was also long at the next close and exiting 10 trading days after entry (4985 simulated trades).
In my previous thread, I used genetic programming where the software created set of trading rules. Here, I manually wrote some smaller combinations of trading rules as templates and used genetic optimization to fill in constant values to create trading rules. Then, I combined trading rules from different training runs to create a larger set of rules for a higher number of trades.
In the perl rules below (you can ignore the $ in each variable name), when the return is set to 1, the trade would be taken at the next trading day's close. Each nonblank line is from a separate training run.
Code:
if ( $VenusAzimuthRelSouth000 >= 14.2417 ) { if ( $VenusAzimuthRelSouth000 <= 90.3941 ) { if ( $VenusElevation000 >= -13.9106 ) { if ( $VenusElevation000 <= 31.4736 ) { if ( $MercuryIllumPctRelNew000 >= -46.847 ) { if ( $MercuryIllumPctRelNew000 <= 49.316 ) { if ( $VenusIllumPctRelNew000 >= -11.873 ) { if ( $VenusIllumPctRelNew000 <= 49.968 ) { if ( $VenusAngDiam000 >= 10.4643 ) { if ( $VenusAngDiam000 <= 40.8093 ) { $return = 1 ; } } } } } } } } } }
if ( $SaturnAzimuthRelSouth000 >= -157.573 ) { if ( $SaturnAzimuthRelSouth000 <= 98.0348 ) { if ( $SaturnElevation000 >= -65.7537 ) { if ( $SaturnElevation000 <= -19.5381 ) { if ( $MoonIllumPctRelNew000 >= -49.881 ) { if ( $MoonIllumPctRelNew000 <= 48.553 ) { if ( $SaturnIllumPctRelNew000 >= -0.235 ) { if ( $SaturnIllumPctRelNew000 <= -0.006 ) { if ( $SaturnAngDiam000 >= 15.6943 ) { if ( $SaturnAngDiam000 <= 20.2308 ) { $return = 1 ; } } } } } } } } } }
if ( $SunAzimuth000 >= 222.538 ) { if ( $SunAzimuth000 <= 224.48 ) { if ( $SunElevation000 >= 12.4349 ) { if ( $SunElevation000 <= 21.3683 ) { if ( $SunAngDiam000 >= 1927.08 ) { if ( $SunAngDiam000 <= 1951.86 ) { if ( $SunAngDiam000 > $SunAngDiam007 ) { $return = 1 ; } } } } } } }
if ( $MarsAzimuth000 >= 67.5343 ) { if ( $MarsAzimuth000 <= 279.061 ) { if ( $MarsElevation000 >= -10.2939 ) { if ( $MarsElevation000 <= 43.6832 ) { if ( $MarsIllumPctRelNew000 >= -12.731 ) { if ( $MarsIllumPctRelNew000 <= -0.937 ) { if ( $MarsAngDiam000 >= 5.25738 ) { if ( $MarsAngDiam000 <= 13.6376 ) { $return = 1 ; } } } } } } } }
if ( $SaturnAzimuthRelSouth000 >= -158.01 ) { if ( $SaturnAzimuthRelSouth000 <= 97.2686 ) { if ( $SaturnElevation000 >= -61.8973 ) { if ( $SaturnElevation000 <= -16.2652 ) { if ( $SaturnIllumPctRelNew000 >= -0.235 ) { if ( $SaturnIllumPctRelNew000 <= -0.009 ) { if ( $SaturnAngDiam000 >= 15.6356 ) { if ( $SaturnAngDiam000 <= 20.2175 ) { $return = 1 ; } } } } } } } }
if ( $MoonAzimuth000 >= 37.9644 ) { if ( $MoonAzimuth000 <= 290.125 ) { if ( $MoonElevation000 >= -24.471 ) { if ( $MoonElevation000 <= 31.9772 ) { if ( $MoonIllumPct000 >= 0.428 ) { if ( $MoonIllumPct000 <= 99.829 ) { if ( $MoonAngDiam000 >= 1792.15 ) { if ( $MoonAngDiam000 <= 1924.56 ) { if ( $MoonAzimuth007 >= 108.057 ) { if ( $MoonAzimuth007 <= 251.904 ) { if ( $MoonElevation007 >= -0.4395 ) { if ( $MoonElevation007 <= 59.9465 ) { if ( $MoonIllumPct007 >= 1.314 ) { if ( $MoonIllumPct007 <= 68.382 ) { if ( $MoonAngDiam007 >= 1756.77 ) { if ( $MoonAngDiam007 <= 1994.2 ) { if ( $MoonIllumPct000 > $MoonIllumPct007 ) { $return = 1 ; } } } } } } } } } } } } } } } } }
if ( $MoonAzimuth000 >= 0.409 ) { if ( $MoonAzimuth000 <= 69.4272 ) { if ( $MoonElevation000 >= -59.3868 ) { if ( $MoonElevation000 <= -8.198 ) { if ( $MoonIllumPct000 >= 57.982 ) { if ( $MoonIllumPct000 <= 99.789 ) { if ( $MoonAngDiam000 >= 1758.24 ) { if ( $MoonAngDiam000 <= 1992.79 ) { if ( $MoonAzimuth007 >= 79.8481 ) { if ( $MoonAzimuth007 <= 143.336 ) { if ( $MoonElevation007 >= -14.6267 ) { if ( $MoonElevation007 <= 29.6536 ) { if ( $MoonIllumPct007 >= 48.171 ) { if ( $MoonIllumPct007 <= 99.651 ) { if ( $MoonAngDiam007 >= 1763.85 ) { if ( $MoonAngDiam007 <= 1935.73 ) { if ( $MoonIllumPct000 > $MoonIllumPct007 ) { $return = 1 ; } } } } } } } } } } } } } } } } }
if ( $VenusAzimuth000 >= 179.041 ) { if ( $VenusAzimuth000 <= 270.048 ) { if ( $VenusElevation000 >= 16.6749 ) { if ( $VenusElevation000 <= 28.7977 ) { if ( $VenusIllumPct000 >= 86.292 ) { if ( $VenusIllumPct000 <= 99.985 ) { if ( $VenusAngDiam000 >= 9.61969 ) { if ( $VenusAngDiam000 <= 15.2557 ) { if ( $VenusAzimuth007 >= 236.824 ) { if ( $VenusAzimuth007 <= 272.992 ) { if ( $VenusElevation007 >= 16.8584 ) { if ( $VenusElevation007 <= 28.6785 ) { if ( $VenusIllumPct007 >= 18.945 ) { if ( $VenusIllumPct007 <= 99.891 ) { if ( $VenusAngDiam007 >= 9.70542 ) { if ( $VenusAngDiam007 <= 47.8982 ) { if ( $VenusIllumPct000 > $VenusIllumPct007 ) { $return = 1 ; } } } } } } } } } } } } } } } } }
if ( $VenusAzimuth000 >= 176.408 ) { if ( $VenusAzimuth000 <= 269.877 ) { if ( $VenusElevation000 >= 1.9608 ) { if ( $VenusElevation000 <= 13.304 ) { if ( $VenusIllumPct000 >= 74.517 ) { if ( $VenusIllumPct000 <= 95.315 ) { if ( $VenusAngDiam000 >= 10.4481 ) { if ( $VenusAngDiam000 <= 21.8056 ) { if ( $VenusAzimuth007 >= 239.865 ) { if ( $VenusAzimuth007 <= 272.659 ) { if ( $VenusElevation007 >= 2.8772 ) { if ( $VenusElevation007 <= 29.0173 ) { if ( $VenusIllumPct007 >= 46.812 ) { if ( $VenusIllumPct007 <= 99.655 ) { if ( $VenusAngDiam007 >= 9.82985 ) { if ( $VenusAngDiam007 <= 15.5886 ) { if ( $VenusIllumPct000 > $VenusIllumPct007 ) { $return = 1 ; } } } } } } } } } } } } } } } } }
if ( $MoonAzimuth000 >= 65.7005 ) { if ( $MoonAzimuth000 <= 114.018 ) { if ( $MoonElevation000 >= -24.4821 ) { if ( $MoonElevation000 <= 32.2454 ) { if ( $MoonIllumPct000 >= 19.643 ) { if ( $MoonIllumPct000 <= 98.531 ) { if ( $MoonAngDiam000 >= 1783.96 ) { if ( $MoonAngDiam000 <= 1970.11 ) { if ( $MoonAzimuth007 >= 112.542 ) { if ( $MoonAzimuth007 <= 228.046 ) { if ( $MoonElevation007 >= -4.9741 ) { if ( $MoonElevation007 <= 68.1649 ) { if ( $MoonIllumPct007 >= 2.534 ) { if ( $MoonIllumPct007 <= 71.343 ) { if ( $MoonAngDiam007 >= 1795.31 ) { if ( $MoonAngDiam007 <= 1979.96 ) { if ( $MoonIllumPct000 > $MoonIllumPct007 ) { $return = 1 ; } } } } } } } } } } } } } } } } }
if ( $MoonAzimuth000 >= 8.0126 ) { if ( $MoonAzimuth000 <= 77.7495 ) { if ( $MoonElevation000 >= -54.0281 ) { if ( $MoonElevation000 <= 70.2897 ) { if ( $MoonIllumPct000 >= 88.009 ) { if ( $MoonIllumPct000 <= 99.839 ) { if ( $MoonAngDiam000 >= 1764.6 ) { if ( $MoonAngDiam000 <= 1993.24 ) { if ( $MoonAzimuth007 >= 66.4668 ) { if ( $MoonAzimuth007 <= 143.117 ) { if ( $MoonElevation007 >= -1.9771 ) { if ( $MoonElevation007 <= 37.2114 ) { if ( $MoonIllumPct007 >= 7.36 ) { if ( $MoonIllumPct007 <= 99.217 ) { if ( $MoonAngDiam007 >= 1764.82 ) { if ( $MoonAngDiam007 <= 1953.44 ) { if ( $MoonIllumPct000 > $MoonIllumPct007 ) { $return = 1 ; } } } } } } } } } } } } } } } } }
if ( $VenusAzimuth000 >= 243.997 ) { if ( $VenusAzimuth000 <= 270.371 ) { if ( $VenusElevation000 >= -4.208 ) { if ( $VenusElevation000 <= 29.4658 ) { if ( $VenusIllumPct000 >= 70.215 ) { if ( $VenusIllumPct000 <= 99.563 ) { if ( $VenusAngDiam000 >= 9.7534 ) { if ( $VenusAngDiam000 <= 16.7935 ) { if ( $VenusAzimuth007 >= 245.968 ) { if ( $VenusAzimuth007 <= 274.164 ) { if ( $VenusElevation007 >= -13.188 ) { if ( $VenusElevation007 <= 28.8037 ) { if ( $VenusIllumPct007 >= 69.07 ) { if ( $VenusIllumPct007 <= 99.155 ) { if ( $VenusAngDiam007 >= 9.85254 ) { if ( $VenusAngDiam007 <= 15.9083 ) { if ( $VenusIllumPct000 > $VenusIllumPct007 ) { $return = 1 ; } } } } } } } } } } } } } } } } }
The baseline combined 4985 simulated trades on the whole validation data had mean gain 0.29 percent, sample standard deviation 3.36 percent, median gain 0.67 percent, and winning percent 61.54. The goal was to get trading rules with better values than the baseline (higher gains, lower standard deviation, higher winning percent).
The set of trading rules above using the validation data resulted in 2277 simulated trades with mean gain 0.63 percent, sample standard deviation 2.95 percent, median gain 0.90 percent, and winning percent 67.02. The trading rules from each of the 12 individual training runs also had better values than the baseline.
Because the future inputs can be generated, future trades can be predicted. Here are the predicted trades using the above rules for the S&P 500 through the end of May.
Code:
endHistoryDate 20230330 startTradeDate 20230331 endTradeDate 20230417
endHistoryDate 20230406 startTradeDate 20230410 endTradeDate 20230424
endHistoryDate 20230426 startTradeDate 20230427 endTradeDate 20230511
endHistoryDate 20230427 startTradeDate 20230428 endTradeDate 20230512
endHistoryDate 20230428 startTradeDate 20230501 endTradeDate 20230515
endHistoryDate 20230501 startTradeDate 20230502 endTradeDate 20230516
endHistoryDate 20230502 startTradeDate 20230503 endTradeDate 20230517
endHistoryDate 20230503 startTradeDate 20230504 endTradeDate 20230518
endHistoryDate 20230504 startTradeDate 20230505 endTradeDate 20230519
endHistoryDate 20230505 startTradeDate 20230508 endTradeDate 20230522




