The earlier rules in this thread were for simulating trades lasting 10 trading days. Here, I have tried something similar but for simulated trades entering long on the next trading day's close S&P 500 and exiting on the close one trading day later. As before, the input data is from (or calculated from) the
Jet Propulsion Laboratory's Horizons ephemeris computation system. Inputs have the same as before plus additional ephemeris data.
In the following list of inputs <Body> is a celestial body (Moon, Sun Mercury, Venus, Mars, Jupiter, Saturn, Uranus*) and <NNN> is the number of calendar days from New York, NY at 20:00 UTC (000 through 007).
- <Body>Azimuth<NNN> - position on the horizon: 0 to 360 degrees where 0 is north
- <Body>AzimuthRelNorth<NNN> - position on the horizon relative to north: -180 to 180 degrees where 0 is north
- <Body>AzimuthRelSouth<NNN> - position on the horizon relative to south: -180 to 180 degrees where 0 is south
- <Body>Elevation<NNN> - position above or below the horizon: -90 to 90 degrees
- <Body>IllumPct<NNN> - percent of body illuminated from the Sun: 0 through 100 percent
- <Body>IllumPctRelNew<NNN> - percent of body illuminated from the Sun relative to new: -50 through 50 percent where 0 is 0 percent illuminated
- <Body>IllumPctRelFull<NNN> - percent of body illuminated from the Sun relative to full: -50 through 50 percent where 0 is 100 percent illuminated
- <Body>AngDiam<NNN> - angular diameter in arc seconds
- <Body>SkyMotion<NNN> - apparent angular rate of the body in the plane-of-sky om arc seconds per minute
- <Body>SkyMotionPA<NNN> - position angle of the body's direction of motion in the plane-of-sky: 0 to 360 degrees where 0 is north
- <Body>SkyMotionPARelNorth<NNN> - position angle of the body's direction of motion in the plane-of-sky relative to north: -180 to 180 degrees where 0 is north
- <Body>SkyMotionPARelSouth<NNN> - position angle of the body's direction of motion in the plane-of-sky relative to south: -180 to 180 degrees where 0 is south
- <Body>RelVelAng<NNN> - flight path angle of the body's relative motion with respect to the observer's line-of-sight : -90 = body is moving directly toward the observer; 0 = body is moving at right angles to the observer's line-of-sight; +90 = body is moving directly away from the observer
- dist<Body><Body> - apparent spherical distance between the two bodies in the sky if measured 20:00 UTC today at approximately 100 km from the Earth's surface (i.e., "the edge of space") in kilometers
The values from the ephemeris are stationary (not trending) and cyclic. This allows the raw input values to be used as is.
In the perl rules below (you can ignore the $ in each variable name), when the return is set to 1, the trade would be go long at the next trading day's close and exit on the following trading day's close. Each nonblank line is from a separate training run.
Code:
if ( $VenusSkyMotionPARelNorth006 <= 113.689 ) { if ( $VenusIllumPctRelNew003 > -9.92045 ) { if ( $VenusAzimuthRelSouth007 <= 76.5303 ) { if ( $VenusRelVelAng007 > -43.6443 ) { if ( $VenusSkyMotionPARelNorth003 > 74.475 ) { if ( $MoonIllumPctRelNew000 >= -24.7633 ) { if ( $MoonIllumPctRelNew000 <= 45.3974 ) { $return = 1 ; } } } } } } }
if ( $VenusIllumPctRelNew003 >= -9.92045 ) { if ( $VenusAzimuth004 <= 254.953 ) { if ( $VenusSkyMotionPARelNorth003 > 74.3587 ) { if ( $VenusRelVelAng007 >= -48.4235 ) { if ( $VenusSkyMotionPARelNorth007 <= 113.708 ) { if ( $MoonIllumPctRelNew000 >= -24.6626 ) { if ( $MoonIllumPctRelNew000 <= 45.4611 ) { $return = 1 ; } } } } } } }
if ( $VenusSkyMotionPARelNorth007 < 113.717 ) { if ( $VenusSkyMotionPARelNorth007 >= 71.4057 ) { if ( $VenusRelVelAng003 > -47.168 ) { if ( $VenusAzimuthRelSouth007 <= 76.5081 ) { if ( $VenusIllumPctRelNew002 >= -6.85619 ) { if ( $MoonIllumPctRelNew000 >= -24.772 ) { if ( $MoonIllumPctRelNew000 <= 46.4493 ) { $return = 1 ; } } } } } } }
if ( $MercurySkyMotion005 > 2.09364 ) { if ( $MercurySkyMotionPA003 >= 87.4848 ) { if ( $distJupiterMercury <= 15474.8 ) { if ( $MercurySkyMotion007 <= 3.96116 ) { if ( $distVenusMercury <= 6574.59 ) { if ( $MoonIllumPctRelNew000 >= -44.8493 ) { if ( $MoonIllumPctRelNew000 <= 17.2405 ) { $return = 1 ; } } } } } } }
if ( $distMarsJupiter >= 9721.91 ) { if ( $JupiterIllumPct006 < 99.7073 ) { if ( $distMercuryJupiter >= 5525.08 ) { if ( $distSaturnJupiter >= 4376.14 ) { if ( $MoonIllumPctRelNew000 <= 46.0165 ) { if ( $JupiterAzimuthRelSouth007 < 146.693 ) { if ( $JupiterSkyMotionPARelNorth000 < 159.087 ) { if ( $distMarsJupiter <= 19908.1 ) { if ( $JupiterSkyMotion006 < 0.485472 ) { $return = 1 ; } } } } } } } } }
if ( $MarsSkyMotionPA005 < 103.319 ) { if ( $MarsSkyMotionPA003 <= 73.5939 ) { if ( $VenusSkyMotionPARelSouth003 >= -111.266 ) { if ( $VenusSkyMotionPA002 >= 66.7971 ) { if ( $VenusIllumPct005 < 98.0737 ) { $return = 1 ; } } } } }
if ( $SaturnElevation000 >= -56.3318 ) { if ( $SaturnElevation000 <= 27.1526 ) { if ( $SaturnAzimuth000 < 342.728 ) { if ( $VenusSkyMotionPARelSouth000 <= -66.3701 ) { if ( $JupiterElevation000 >= -23.1582 ) { if ( $UranusAzimuthRelNorth000 >= -165.453 ) { if ( $VenusIllumPct000 > 87.5416 ) { $return = 1 ; } } } } } } }
if ( $VenusSkyMotionPA000 > 55.6991 ) { if ( $MarsSkyMotionPARelNorth000 <= 74.2851 ) { if ( $JupiterSkyMotionPA000 < 259.228 ) { if ( $JupiterIllumPctRelFull000 >= 49.107 ) { if ( $VenusAzimuthRelSouth000 < 99.8045 ) { if ( $UranusSkyMotion000 > 0.0263952 ) { if ( $MarsSkyMotionPARelSouth000 <= 103.071 ) { $return = 1 ; } } } } } } }
if ( $MarsSkyMotionPARelNorth000 <= 74.0173 ) { if ( $JupiterAngDiam000 < 42.5584 ) { if ( $JupiterIllumPctRelNew000 >= -0.89215 ) { if ( $VenusAzimuthRelSouth000 < 99.7307 ) { if ( $VenusRelVelAng000 > -38.3745 ) { if ( $UranusSkyMotion000 >= 0.0251009 ) { if ( $MarsAzimuth000 > 26.5223 ) { $return = 1 ; } } } } } } }
if ( $MarsSkyMotionPARelNorth000 <= 75.8776 ) { if ( $MarsSkyMotion000 > 0.0980262 ) { if ( $SunSkyMotion000 > 2.36899 ) { if ( $SunRelVelAng000 < 1.07194 ) { if ( $MarsElevation000 <= 50.3614 ) { if ( $SunElevation000 > 12.5991 ) { if ( $MarsAzimuthRelNorth000 >= -176.262 ) { $return = 1 ; } } } } } } }
Before, I wrote the rules and used genetic optimization to find constant values. This time, I mostly used genetic programming to find operations (e.g., if <=), inputs (e.g., $VenusSkyMotionPARelNorth006) and constant values (e.g., 113.689). Some of the rules have parts manually written with constants found with genetic optimization combined with other parts created by genetic programming.
The training data had 8088 simulated trades starting 1957-06-12 through 2009-09-24.
The out-of-sample evaluation data had 3467 simulated, one-trading-day trades starting 2009-09-25 through 2023-07-06 with
total return 321.2019% (not including dividends or trading costs); compound annual return 11.00%; mean return 0.0415%; median return 0.0658%; winning percent 54.31
Each of the rules found has a greater mean return, median return, and winning percent than the evaluation data.
The evaluation period with the generated rules applied had 2238 simulated, one-trading-day trades (64.55% of the total trading days) with
total return 527.4990% (not including dividends or trading costs); compound annual return 14.25%; mean return 0.0821%; median return 0.0882%; winning percent 56.08
If trades on consecutive trading days were combined (total return unchanged), there would have been 98 trades with
mean return 1.8917%; median return 1.1458%; winning percent 70.41
The combined trades would have lasted from 1 to 218 trading days with a mean 22.84 days and a median 6.50 days.
Since each rule had better performance per trade on the out-of-sample data than the equivalent buy-and-hold trades, I think there is a reasonable chance the rules would have better performance than buy-and-hold trades in the future.
Here are some future blocks of trading days that will pass the rules:
Code:
entryDate 20230727 exitDate 20230809 duration 9
entryDate 20230810 exitDate 20230828 duration 12
entryDate 20230912 exitDate 20230918 duration 4
entryDate 20230926 exitDate 20231009 duration 9
entryDate 20231010 exitDate 20231012 duration 2
entryDate 20231211 exitDate 20240103 duration 15
* Yes, I finally felt it was time to probe Uranus because "Once you go Uranus, nothing will be the same as."