Designing a Logistic Regression Comparison: Timing, Evaluation, and Failure Handling
Before comparing logistic regression with baseline strategies, define which information may enter training, which period everyone will evaluate, and what happens when training fails. Dropping failed months or replacing them with cash changes the result, even with the same model. Failure handling is part of the comparison, not an exception to invent during execution.
The blog has published an actual SPY/IEF/GLD comparison of buy-and-hold and 12-month momentum. It has not yet published logistic regression trained on actual ETF data under the same conditions. This article designs that comparison. Its probabilities are illustrative numbers, not model predictions.
Conditions the strategies should share
For the first comparison, I propose these common conditions for buy-and-hold, momentum, and logistic regression:
| Item | Comparison condition |
|---|---|
| Input | Same ETFs, price definition, and data snapshot |
| Evaluation calendar | Same start and end after the warm-up period |
| Feature observation | Information available by month-end |
| Signal calculation | After the required month-end data become available |
| Execution assumption | Close of the next observed trading day |
| ML selection | Equal weights among assets with estimated class-1 probability at least 0.50 |
| Normal cash holding | Valid predictions exist, but no asset is selected |
| Costs | One-way 0, 5, 10, and 20 bp, using the same accounting code |
| Ending | Liquidate on the same end date, including costs |
| Failure | A required check failing during evaluation makes the run unsuccessful |
The 0.50 threshold aligns this design with the logistic/tree comparison; it is not an optimized value. A different threshold must be a recorded candidate, with the selection procedure decided before viewing test results.
Do not compare full-period baseline results directly with a shorter ML evaluation. Recalculate the baselines over the common period from the same initial state. Reusing a period whose results have already been inspected does not create new independent validation.
Decide which outcomes are eligible for training
The prediction target is:
Is the price return positive from the entry reference point after the signal to the next exit reference point?
A positive return gives label 1; zero or a negative return gives 0. Until the interval ends, the label remains unknown. This is a direction label before trading costs, distinct from the strategy's net performance.
| Stage | Treatment |
|---|---|
| Features | Use only historical information available at the signal |
| Entry reference | Next observed trading day's close |
| Exit reference | Execution-day close corresponding to the next monthly signal |
| Label finalization | After the exit price becomes available |
| Training inclusion | Only labels finalized before that retraining time |
At a March 31 signal, a historical sample whose holding interval ends April 1 cannot enter training. An old signal date alone does not make its outcome available.
With date-only data, label_end_date < signal_date is a conservative rule. Using labels that finish on the same day requires price-arrival and training-cutoff timestamps. The logistic regression baseline design shows how to preserve unknown labels and exclude them during training. Here that becomes a common experiment rule.
Separate insufficient preparation from evaluation failure
The minimum training sample requirement is still undecided, so this is not yet a complete executable specification.
| Unresolved item | Decision needed |
|---|---|
| Features | Columns, windows, price definitions, availability times |
| Minimum training history | Historical span, finalized sample count, class-specific requirements |
| Periods | Development/validation/evaluation boundaries and overlapping labels |
| Model settings | Candidate configurations and selection criteria |
| Training warnings | Conditions under which convergence or other warnings invalidate a run |
| Common start | Evaluation start at which all strategies meet preparation requirements |
Sample size is not just a number of rows. Three ETFs observed in one month are not equivalent to three independent months. Inspect the historical span and class distribution as well.
- Before evaluation: verify preparation requirements and fix a shared evaluation calendar.
- During evaluation: stop on a required-check failure and retain the reason.
- After changing conditions: record a new configuration and run ID, preserving the earlier failure.
Do not reclassify unfavorable months as warm-up after seeing performance, or present a result excluding failed months as a completed original comparison.
Choosing cash is different from failing to predict
When valid predictions all fall below the threshold, cash is the normal selection result. When insufficient training data or invalid inputs prevent prediction, no investment decision has been produced.
| Situation | Treatment | Record |
|---|---|---|
| Valid predictions and selected assets | Allocate equally | Probabilities and target weights |
| Valid predictions, all below threshold | Target all cash | Valid signal with no selected assets |
| Current prediction row has an unknown future label | Permit prediction; defer subsequent classification evaluation | Unknown-label state |
| Minimum training requirement not met | Failed run | Required and actual training quantities |
| Only one class in the training window | Failed run | Class counts |
| Missing/infinite required features or missing asset rows | Failed run | Date, asset, and affected column |
| Fit or prediction error | Failed run | Error and environment |
An unavailable future label is different from an unavailable required feature.
A failed research run is not accepted as a valid completed calculation. This does not define orders for a live account. Do not fill the remaining returns with zeros or insert an imaginary liquidation to manufacture a complete performance series.
Studying a cash fallback separately
A policy that moves to cash when training fails can be studied, but as a separate strategy, not a hidden exception. First specify eligible failures, execution timing, selling costs for existing holdings, when training and investing resume, and how cash-fallback frequency and duration are reported. Its results combine model behavior with a failure-response policy.
A small example of cash versus failure
These are synthetic inputs, not real ETF observations or trained-model outputs.
| Case | SYN_A | SYN_B | SYN_C | Action |
|---|---|---|---|---|
| Assets selected | 0.60 | 0.45 | 0.70 | 50% each in A and C |
| None selected | 0.40 | 0.45 | 0.30 | 100% cash |
| Missing prediction | None | 0.45 | 0.70 | Error; do not produce weights |
The probability-to-target-weight calculation is:
from math import isfinitedef target_weights(probabilities, threshold=0.50): if not isfinite(threshold) or not 0 <= threshold <= 1: raise ValueError("임계값은 0~1의 유한한 값이어야 합니다") if not probabilities: raise ValueError("예측 결과가 없습니다") if any( p is None or not isfinite(p) or not 0 <= p <= 1 for p in probabilities.values() ): raise ValueError("유효하지 않은 예측 확률입니다") selected = [ asset for asset, p in probabilities.items() if p >= threshold ] weights = {asset: 0.0 for asset in probabilities} if not selected: return weights, 1.0 for asset in selected: weights[asset] = 1.0 / len(selected) return weights, 0.0The return values are asset target weights and cash target weight. The three cases produce:
({'SYN_A': 0.5, 'SYN_B': 0.0, 'SYN_C': 0.5}, 0.0)({'SYN_A': 0.0, 'SYN_B': 0.0, 'SYN_C': 0.0}, 1.0)ValueError: 유효하지 않은 예측 확률입니다The Korean error message means “Invalid predicted probability.” These cases were executed with synthetic inputs while preparing the revision on October 22, 2026. They do not validate model training or a backtest.
Outside this function, verify that predictions cover every expected asset, refer to the same signal time, and come from successful training. Returned weights are targets before costs and execution. With actual predict_proba output, inspect classes_ to select the class-1 column; columns follow class order. scikit-learn LogisticRegression documentation
Separate retraining from model reselection
Fit preprocessing statistics only on each training window, then transform the current prediction row. Computing means and standard deviations on the entire period before splitting can introduce future information. A Pipeline does not remove the need to select training rows correctly. scikit-learn leakage guidance
| Action | Treatment |
|---|---|
| Retrain on finalized historical data at a predefined schedule | Allowed |
| Reselect features, thresholds, or model candidates after viewing evaluation results | Separate experiment |
Adding labels finalized during evaluation to later training is a predefined sequential evaluation procedure. Do not report it as if the model was fitted once and then frozen. Neither approach permits training on outcomes unavailable when a prediction was made.
Record evidence before building the results table
| Record | Question it answers |
|---|---|
| Run ID and configuration version | Which conditions were used? |
| Input hash, price definition, period | Are inputs comparable? |
| Evaluation dates and prediction-row count | Were any months missing or excluded? |
| Training span and class counts | Did each fit meet requirements? |
| Label finalization times | Were only available outcomes used? |
| Probabilities, weights, transaction ledger | How did predictions become trades? |
| Costs, cash, terminal treatment | Was accounting consistent? |
| Warnings, failure reasons, environment | Was the run complete and reproducible? |
First align the dates and inputs of completed runs; then separate classification results from net strategy results. High accuracy can coexist with poor net performance if errors occur on large losses or trading is frequent. A smaller drawdown may also reflect more cash exposure.
This article proposes comparison conditions and failure handling. Determining superiority still requires finalizing the unresolved training requirements and period, then producing completed runs with identical input, calendar, and accounting rules. The logistic regression versus tree-model design explains what should remain fixed when adding models.
Report an error or share feedback
Open a draft with this article’s title and URL. Review the message and recipient before sending.
Open email draftIf no email app opens, copy these details into your usual email service.
Related posts
Quant & Data Research Designing a Logistic Regression Baseline: Keeping Unfinished Labels Out of Training
Design training-time rules for a logistic regression comparison, preserving missing labels and separating training rows from current predictions.
Quant & Data Research Mistaking Chance for Skill in Financial Machine Learning: Claims and Conditions That Challenge Them
Define what favorable backtests support and which claims must change when leakage, repeated search, period dependence, or incremental costs appear.