Skip to content
Alphanume Learn

Guided Python project

Backtest a Pre-Market Stock Signal in Python

How does raising the minimum pre-market score change which stocks a daily short rule selects?

Open the workbench

Choose Teaching sample to run Python without signing in.

How to run the test

Select a stock using its pre-market score. After the close, attach the stock’s open-to-close return. The workbench flips the sign of that return for a short position.

Worked example · fictional data

Fictional stock EX01 has a score of 0.72. It qualifies at a cutoff of 0.65 but not at 0.80. Its price goes from $10.00 at the open to $9.38 at the close.

score, cutoff = 0.72, 0.65
open_price, close_price = 10.00, 9.38
if score >= cutoff:
    gross_short_pct = 100 * (open_price - close_price) / open_price
    print(round(gross_short_pct, 2))  # 6.2

What the result tells you

The 0.65 rule includes this observation at a gross short return of 6.2%. The 0.80 rule excludes it. Pick your rule on the earlier data, then use it unchanged on the later period.

The score estimates the chance of a drop of at least 5% from open to close. It is not an expected return. Gross outcomes omit trading costs and do not establish that shares were available to short.

Projects Build a daily stock strategy
0 of 5 steps complete

Step 1 of 5 · Define the rule

Turn the daily score into a test.

Pre-Market Drop Risk ranks flagged stocks by their estimated probability of falling at least 5% from open to close. The score becomes a strategy input when you state how to select and measure the names.

Here the rule selects scores above a threshold and measures a short held from open to close. The calculation uses the dataset’s recorded same-day percentage return.

Your task

Run the default probability threshold. Inspect the selected observations and their gross returns.

One thing to remember

The probability describes a drop threshold. It is not an expected return or a position size.

Connecting the dataset and preparing the study…

Loading draft…
Alphanume data

Loading the project’s real dataset.

Loading your code…

Progress for this project is separate from your full course.