Formulaic Alphas' algorithms
Letting an algorithm write its own trading signals as formulas you can read. First with genetic programming over prices and social-media sentiment, then with a reinforcement-learning agent.
Details
- Period
- 2024 – 2026
- Status
- Completed
- Code
- Private repository
- Stack
- Python, DEAP, PyTorch, LLaMA 3, pandas, yfinance
Case study
The idea
Most models that predict prices are black boxes. Here the output is a formula: an expression over prices, volumes or sentiment that turns into a long or short position, and that a person can read, check and reuse.
Genetic programming with sentiment (2024)
- Data. Prices twice a day for seven US-listed companies (Charles River Laboratories, Deere & Company, Eaton, Genuine Parts, Nucor, Visa and Sherwin-Williams) from January 2020 to May 2024, each paired with the sentiment of posts on X about the company, scored with LLaMA 3.
- Search. A genetic program (DEAP) evolves trading rules as expression trees over those fourteen inputs, with arithmetic, logical and conditional operators: 5,000 rules per generation for 30 generations, tournament selection, and the annualised Sharpe ratio on the first 80% of the data as fitness.
- Test. The 50 best rules are run on the remaining 20% (June 2023 to May 2024) and measured by Sharpe and Sortino ratios, maximum drawdown, skewness and kurtosis. One variant trades only the stocks a rule refers to; another averages the signals of all 50 rules.
- Results. On the test period the best rules reached Sharpe ratios between 2 and 3 with drawdowns around 2%, before transaction costs. The variant that trades only the stocks a rule mentions was less consistent, between 0.4 and 2.7.
Reinforcement learning for alpha discovery (2026)
- The agent. A PPO agent builds a formula one token at a time, in reverse Polish notation, from a small language: price and volume columns, constants, arithmetic, time-series operators (moving averages, ranks, z-scores, lags, returns) and twelve classic alpha building blocks such as momentum, mean reversion, Bollinger position and volume surge.
- What it sees and earns. The state holds 26 features: the market regime over 5, 20 and 60 days, plus the formula built so far. The reward is the annualised Sharpe ratio of the formula’s signal, averaged over 19 stocks from six sectors, with a bonus when it works on most of them.
- Afterwards. The 30 best formulas go into a library, where they can be evaluated on new data and backtested against buy and hold, a 20/50-day moving-average crossover, momentum, mean reversion and random trading. Daily prices of S&P 500 constituents come from yfinance.