Nathan Oldridge
  • Home
  • Contact
  • Home
  • Contact

1-minute SPY Data as CSV (10 years worth, Sep 2012 to Nov 2022)

11/25/2022

0 Comments

 
This is a 65-MB CSV file containing timestamps, open, high, low, close, change, %change and volume for 1-min candles on $SPY
spy1min-10y.csv
File Size: 66135 kb
File Type: csv
Download File

If you found this useful, thank me on Twitter or elsewhere. I love chatting with other traders.
0 Comments

The 12-minute Opening Range Breakout (Day Trading $SPY): Intermediate ETL Example with Python and Google Sheets

11/24/2022

0 Comments

 
I am the first person on the Internet to coin this phrase in the context of day trading.
12-minute ORB
​12-minute Opening Range Breakout
In day trading of stocks, the term Opening Range Breakout refers to waiting for FIRST candle of the day to close, and then buying a break ABOVE (or selling a break BELOW) that initial range. Most commonly, I see 3-minute ORBs and 5-minute ORBs, since those are common charts for people to watch on a site like TradingView.

But what size of ORB (in minutes) is the most profitable?

I used CSV files, Python and Google Sheets (Pivot Tables) to find out. 
Picture
Extract: I downloaded $SPY stock data for the past 326 trading days, with 1-minute resolution, in CSV form, from BarChart.com. I copied and pasted a few smaller CSVs together, but could have automated this if there were too many files ...

Transform: I used Python to open the CSV, delete several columns, and cast some columns to float() as required. Then, I coded an algorithm to find the high and low of the stock over the first x minutes, and then look candle-by-candle for a break either ABOVE or BELOW that range. THEN, I followed the chart candle-by-candle to analyze whether a stop-loss would be triggered, or profit taken depending on the target set, or whether the day came to a close without either of those things happened. In those cases, I closed the position at 3:55pm, 5 minutes before close.

The outcome of every day's trade was appended to a list, and then the SUM of the profits and losses from those 326 trading days was output to the Terminal.

I also had three nested loops, which let me test various ORB sizes (in minutes), stop-loss distances (measured in number of bars compared to the original ORB) and targets (a trade would close if a particular target, in bars, was reached).
Picture

30 different ORB sizes x 5 varying stop-losses x 7 varying targets = 1050 permutations of ORBs/Stops/Targets, and each of THOSE was applied to each of the 326 trading days.

In any case, the Terminal output was 1050 lines telling me the ORB size, Stoploss, Targets, and total profit/loss for that permutation. This was small enough that I could copy/paste it into Google Sheets.

Load: Google Sheets didn't realize my data was numerical, so I had to use =SPLIT() to break apart the data from the Terminal. If I was doing this with a larger data set, I would have output to CSV instead of printing to the Terminal.
Picture
Then, I used a Pivot Table to summarize the results across varying ORB sizes. Due to outliers, I wanted to look at AVERAGE profit, MAX profit, MIN profit and MEDIAN profit across all stop-losses and targets for a particular ORB size. The results are pretty clear (see below). ​By all measures, a 12-minute ORB outperforms all other durations.

Actually, a 13-minute ORB is about the same, but the difference is negligible considering the randomness of the markets.
Picture
0 Comments

Basic ETL Example: Using Google Sheets to find stocks with Inside Day and Outside Day

11/9/2022

0 Comments

 
Summary:
  • You can use Google Sheets' built-in method called GOOGLEFINANCE to extract data about the current day's high and low, and the previous day's high and low.
  • You can use IF formulas to flag whether the current day is inside of the previous day's price action or outside (or neither). Setting this flag is a form of data transformation
  • You can use a Pivot Table to find all of the stock tickers that had inside days (or outside days) and you can even order them by intraday volume. This is a method of loading the data into a more easily-digestible form.

Motivation:
  • To find stock-trading plays, I used to use http://www.runstrat.com - it would scan the market for particular patterns that occur, including inside days and outside days. Unfortunately, it went offline at the end of October, presumably because it was expensive to run the site and donations (revenue) did not cover expenses.
  • Can I build something to replace it? Yes, but extracting data about stocks can be challenging.
  • Google Sheets contains a formula command called GOOGLEFINANCE which is 20-minute delayed stock data

Implementation:
  • To get the current day's high for a stock like GOOG, use =GOOGLEFINANCE("GOOG","high")
  • To get the current day's low for a stock like GOOG, use =GOOGLEFINANCE("GOOG","low")
  • To get the previous day's high, you need to have a 2x2 set of blank cells, and use =GOOGLEFINANCE("GOOG","high",TODAY()-1,1)
  • To get the previous day's low, you need to have a 2x2 set of blank cells, and use =GOOGLEFINANCE("GOOG","low",TODAY()-1,1)
  • ​​To accommodate the 2x2 nature of the data returned by the previous day's data, my tickers and other data are in 2-row-tall merged cells:
Picture

​DailyStratBarType is 1 if the current day's low and high are 
within the previous day's
DailyStratBarType is 3 if the current day's low is lower than yesterday AND the current day's high is higher as well
DailyStratBarType is 2 if either the current day's low is lower than yesterday's OR the current day's high is higher than yesterday's (but not both)

To designate this, I used a nested IF formula: =IF(AND(J4>G3,L4<H3),1,IF(AND(J4<G3,L4>H3),3,2))
Lastly, I needed to collect the ticker symbols of the stocks that have been flagged 1 (or 3, separately). This can be done with a Pivot Table, which lets me:
  • display only the ticker symbols that have been flagged as 1 (or 3, separately)
  • sorted from highest to lowest volume
Picture
Notes:
  • The "but not both" part of DailyStratBarType being a "2" should remind my former Toronto Prep School Computer Science students that XOR (exclusive or) does have use cases in the real world.
  • You can Make a Copy of this Spreadsheet, which is a work in progress, for your own purposes by visiting this link: docs.google.com/spreadsheets/d/1v9ONxggTIFebN6Tf09hRNnLE21VWhXQhRgQDI1myaRE/edit?usp=sharing
0 Comments

I am not returning to Toronto Prep School

8/3/2022

0 Comments

 
If you are finding this website as one of my former students, I have news for you: I will not be returning to Toronto Prep School in September.

There are many reasons for this; most are personal.

If you need a letter of reference, you can contact me via the Contact Form of this website.
0 Comments
Powered by Create your own unique website with customizable templates.