Discussing the article: "Feature Engineering for ML (Part 3): Session-Aware Time Features for Forex Machine Learning"

 

Check out the new article: Feature Engineering for ML (Part 3): Session-Aware Time Features for Forex Machine Learning.

The article addresses the loss of temporal information in ML pipelines by encoding periodic time variables with Fourier harmonics and adding forex session structure. It implements session and overlap flags, lagged session volatility, and calendar effects, then prunes features by timeframe. The get time features function returns an index‑aligned, ML‑ready set of time features suitable for integration with price‑based signals.

Every bar in a financial time series carries a timestamp. Most ML pipelines discard it. The timestamp is converted to a target label, a lookahead window is defined, features are constructed from price and volume history, and the datetime index is never seen again. This is a significant information loss. Time itself encodes a rich structure — the rotation of the market day, the boundaries of trading sessions, the approach of month-end fixings, the cadence of the weekly open — none of which is visible in a price or return series.

The challenge is representation. Raw integer timestamps are meaningless to a regression or classification model: the number 1735689600 (a Unix epoch) conveys no cyclical structure. A naive integer hour column implies that hour 23 is farther from hour 0 than it is from hour 18, which is geometrically wrong. A binary session flag captures presence but discards position within the session. A single harmonic captures the dominant daily cycle but misses the asymmetry between the slow Asian session and the volatile London–New York overlap.

This article develops a principled approach to time-feature engineering for financial ML. It covers the theory of cyclical (Fourier) encoding, the structure of the four major forex trading sessions, session-specific volatility features, and the calendar effects that influence institutional order flow near period boundaries. The implementation is the get_time_features function from the afml library, which orchestrates all of these components into a single, ML-ready feature DataFrame. Part 1 of this series covered fractional differentiation for price features; Part 2 deployed that engine in MQL5. This article addresses the orthogonal question: how to encode the temporal context in which a price observation occurs.

 Feature Engineering for ML (Part 3): Session-Aware Time Features for Forex Machine Learning

Author: Patrick Murimi Njoroge