Tick Data for Backtesting and Algo Trading: Difference between revisions

From Volatility.RED
No edit summary
 
(38 intermediate revisions by 2 users not shown)
Line 1: Line 1:
I noticed that many guides or lists of tick data sources were out of date, broken, or otherwise not working, so I decided to make an updated list with modern sources for use as a resource with the algo trading community. I will also keep this up to date as new sources appear and old sources break.
I noticed that many guides or lists of tick data sources were out of date, broken, or otherwise not working, so I decided to make an updated list with modern sources for use as a resource with the [[Algorithmic_Trading | algo trading]] community. I will also keep this up to date as new sources appear and old sources break.


Below are the guides for downloading tick or bar level data for various markets which can be used for backtesting and analysis.
Below are the guides for downloading tick or bar level data for various markets which can be used for backtesting and analysis.
Line 7: Line 7:
____TOC____
____TOC____


=='''<p style="font-size:18px">Stocks [Daily Bars]'''</p>==
=='''Stock Daily Bar Data'''==


Yahoo Finance - US and International stock exchanges - On a stock by stock basis, you can download decades of historical daily bar data by doing the following steps:
===Yahoo Finance===


::1. Go to https://finance.yahoo.com
US and International stock exchanges - On a stock-by-stock basis, you can download decades of historical daily bar data by doing the following steps:
::2.In the search field, type in your desired symbol or company name and select the appropriate result
::3.Click the ''''Historical Data'''' tab
::4.Set the date range to ''''MAX''''
::5.Hit the ''''Apply'''' button
::6.Click the ''''Download Data'''' link just below the ''''Apply'''' button
::7.Enjoy your daily bar data


'''Google Finance -''' Rest in peace.. :( Google nuked their finance site back to the stone age many years ago so this service is pretty useless now (Honestly Google, what were you thinking? Google Finance was awesome back in 2012 and prior.) Google also used to have an API but that too got turned off. I included an entry for Google here because many people will be searching around the net and find references to using Google Finance's API but be unsure why it's not working as expected.
*Go to https://finance.yahoo.com
*In the search field, type in your desired symbol or company name and select the appropriate result
*Click the ''''Historical Data'''' tab
*Set the date range to ''''MAX''''
*Hit the ''''Apply'''' button
*Click the ''''Download Data'''' link just below the ''''Apply'''' button
*Enjoy your daily bar data


'''Cautious mention - QuantConnect - tick and minute bar data on stocks and forex.''' I'm currently reviewing QuantConnect as a potential source. They do offer a lot of free data but since their ecosystem was built around offering up crowd sourced strategies to prop firms I'm hesitant to recommend them until I've wrapped my head around their offering and can say I trust their platform.
===Google Finance===
Rest in peace.. :( Google nuked their finance site back to the stone age many years ago so this service is pretty useless now (Honestly Google, what were you thinking? Google Finance was awesome back in 2012 and prior.) Google also used to have an API but that too got turned off. I included an entry for Google here because many people will be searching around the net and find references to using Google Finance's API but be unsure why it's not working as expected.


===[https://pypi.org/project/yfinance/ yfinance Python Library]===


=='''<p style="font-size:18px">Forex [Tick Data]'''</p>==
yfinance aims to solve this problem by offering a reliable, threaded, and Pythonic way to download historical market data from Yahoo! finance.
''(Since tick data is available from multiple sources without cost, I will only mention bar data at the end.*)''


Jack from [https://fxgears.com/ FXGears.com] has provided a basic daily bar download script for yfinance in Python, but check out the yfinance docs for more advanced features:


'''<p style="font-size:18px">[https://fxgears.com/out/darwinex Darwinex]-</p>'''
Make sure you have yfinance installed. From your command line:
::Darwinex is easy but you'll need to have a live account. Anyone can [https://fxgears.com/out/darwinex/register signup for an account (live)] and head over to this page here once logged in: [https://fxgears.com/out/darwinex/tickdata Historical Tick Data Download]. From there, just click the '''"Request FTP Access"''' button to have your FTP login details generated for you. Darwinex provides tick level data all major and minor currency pairs, as well as index and commodity CFDs, with most of them going back to mid-late 2017. You don't need to deposit to have a live account at Darwinex, you just need to have a verified account with them, so there's little downside to enabling access to this high quality source of tick data. (As a side benefit, you can also get access to historical price data of their [http://fxgears.com/out/darwinex/explore Darwin Exchange], so you can model investing in other traders and model their strategy returns, which is pretty cool.)
<syntaxhighlight lang="PowerShell">
pip install yfinance
</syntaxhighlight>


<syntaxhighlight lang="python" line='line'>
import yfinance as yf
import datetime
import os


'''<p style="font-size:18px">[https://fxgears.com/out/pepperstone Pepperstone] / Integral / [https://www.truefx.com/truefx-historical-downloads/ TrueFX]''' -</p>'''
# define start date, go back further if you need but not all years are available for all symbols.
::Pepperstone relies on price feeds and liquidity very similar to Integral's offering, so similar that for a while Pepperstone used to publish Integral's data on their own FTP for easy customer access. Unfortunately, they stopped offering this FTP access some time ago (thus why most online tutorials referencing them are out of date) and the source of data that Pepperstone currently recommends is Integral's TrueFX data service offering. [https://www.truefx.com/truefx-historical-downloads/ A free account at TrueFX.com'] will get you access to tick data on most major and minor currency pairs from the past year only (Currently only 2019 YTD is available for free.) I encouraged Pepperstone to bring back their historical data access to regain access to years prior to 2019 and if they ever open back up then I'll update this spot here with access info.​
start_date = '2020-01-01'


end_date = datetime.date.today() - datetime.timedelta(days=1)
end_date = end_date.strftime(format="%Y-%m-%d")


'''<p style="font-size:18px">[https://fxgears.com/out/dukascopy Dukascopy] -</p>'''
symbols = ['SPY', 'IBM', 'BAC']
::This source is a staple in the forex tick data world. Dukascopy Bank has been around for a long time and has offered historical tick data on their products with dates going back into the mid-early 2000's. Like the other sources, you'll need signup to their site, but they do not require a live account to access data. To access, all you need to do is visit the [https://fxgears.com/out/dukascopy/tickdata Dukascopy Bank Historical Data Feed page], and use the historical download tool provided (with registering or logging in when prompted before it will let you download.) The download tool makes it easy to select what data you want, but note that all non-forex listings here (like stocks) are CFDs on Duka's platform, NOT the underlying stock data that trades on a stock exchange. (If you're interested in Dukascopy but need to trade under Euro zone regulations, you can find their [https://fxgears.com/out/dukascopy/europe Europe subsidiary here] with different trading conditions.)​


for item in symbols:
    working_df = yf.download(item, start=start_date, end=end_date)
    working_df.reset_index(inplace=True)
    working_df.to_csv('{}_{}.csv'.format(item, end_date), index=False)
</syntaxhighlight>


<nowiki>*</nowiki>Regarding Bar type data - Downscale it from the tick data above as needed. However, if you really only want daily bar data, you can find it from Oanda's website, or others pretty easily.
Note: You will have to know the Yahoo! Finance symbology to download your target symbols. (It's sometimes not intuitive, "CAD=X" is USD/CAD for example.)


=='''Forex [Tick Data]'''==


=='''<p style="font-size:18px">Crypto</p>'''==
Quality of data matters and the below options are some of the better quality sources available for free.


===[https://geni.us/Pepperstone Pepperstone] / Integral / [https://www.truefx.com/truefx-historical-downloads/ TrueFX]===


'''[https://fxgears.com/out/binance Binance -]''' One of the top exchanges by volume with easily one of the largest collections of crypto pairs to trade. Binance is very API friendly, and is structured in a way that even trading smaller amounts can be done efficiently. Recently, Binance opened up trading on leveraged products (spot, and futures,) as well as started offering options.
https://www.truefx.com/truefx-historical-downloads/


You're going to need an account, which is free to get started, so if you don't already have an account [https://fxgears.com/out/binance you can register here.]
::Pepperstone relies on price feeds and liquidity very similar to Integral's offering, so similar that for a while Pepperstone used to publish Integral's data on their own FTP for easy customer access. Unfortunately, they stopped offering this FTP access some time ago (thus why most online tutorials referencing them are out of date) and the source of data that Pepperstone currently recommends is Integral's TrueFX data service offering. [https://www.truefx.com/truefx-historical-downloads/ A free account at TrueFX.com'] will get you access to tick data on most major and minor [[currency]] pairs from the past year only (Currently only 2019 YTD is available for free.) I encouraged Pepperstone to bring back their historical data access to regain access to years prior to 2019 and if they ever open back up then I'll update this spot here with access info.


From your account page, then you'll need to generate API keys to access the API and pull down data:<br>
=='''[[Crypto tick and bar data | Crypto Tick and Bar Data - Free API and Script Provided]]'''==
https://i.imgur.com/PKtpYr9.png


[[Crypto tick and bar data | We have a dedicated page with working code for this here!]]


On the following page, find the create field and enter any nick name you want:<br>
[[Crypto tick and bar data | Crypto Tick and Bar Data - Free API and Script Provided]]
https://i.imgur.com/RPmtR41.png


=='''Related Wikis'''==


Hit the create button. You'll likely have to authenticate or verify via email that you want to generate an API key, but once done you will see the generated API key itself, and the API secret code as well. Save these somewhere secure and safe.
Readers of '''Editing Tick Data for Backtesting and [[Algorithmic_Trading | Algo Trading]]''' also viewed:


Next up we need to setup Python on our system to do the leg work of downloading data. Head over to https://python.org and grab the latest version of Python 3 for your OS. Install said package.
* [[Algorithmic Trading]]
 
* [[Best_and_Worst_Times_to_Trade | Best and Worst Times to Trade]]
Once installed we will add the python-binance and pandas packages to access the Binance API from within Python and to save the resulting data to a CSV file.
* [[Technical Trading Strategies]]
 
* [[Sentiment_Analysis#Volatility | Volatility]]
To do this, open a [https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2012-r2-and-2012/jj717276(v%3Dws.11) Open a CMD (Command Line) window as Administrator on Windows] (or the appropriate terminal in Linux / OSX..) and run the following commands:
* [[Developing_your_Trading_Process | Developing your Trading Process]]

Latest revision as of 10:09, 31 August 2025

I noticed that many guides or lists of tick data sources were out of date, broken, or otherwise not working, so I decided to make an updated list with modern sources for use as a resource with the algo trading community. I will also keep this up to date as new sources appear and old sources break.

Below are the guides for downloading tick or bar level data for various markets which can be used for backtesting and analysis.

Note: Typical format for tick and bar data is in CVS files. You might need to adjust or re-arrange said files as needed to fit into your desired analytics and/or backtesting program.

__

__

Stock Daily Bar Data

Yahoo Finance

US and International stock exchanges - On a stock-by-stock basis, you can download decades of historical daily bar data by doing the following steps:

  • Go to https://finance.yahoo.com
  • In the search field, type in your desired symbol or company name and select the appropriate result
  • Click the 'Historical Data' tab
  • Set the date range to 'MAX'
  • Hit the 'Apply' button
  • Click the 'Download Data' link just below the 'Apply' button
  • Enjoy your daily bar data

Google Finance

Rest in peace.. :( Google nuked their finance site back to the stone age many years ago so this service is pretty useless now (Honestly Google, what were you thinking? Google Finance was awesome back in 2012 and prior.) Google also used to have an API but that too got turned off. I included an entry for Google here because many people will be searching around the net and find references to using Google Finance's API but be unsure why it's not working as expected.

yfinance Python Library

yfinance aims to solve this problem by offering a reliable, threaded, and Pythonic way to download historical market data from Yahoo! finance.

Jack from FXGears.com has provided a basic daily bar download script for yfinance in Python, but check out the yfinance docs for more advanced features:

Make sure you have yfinance installed. From your command line:

pip install yfinance
import yfinance as yf
import datetime
import os

# define start date, go back further if you need but not all years are available for all symbols.
start_date = '2020-01-01'

end_date = datetime.date.today() - datetime.timedelta(days=1)
end_date = end_date.strftime(format="%Y-%m-%d")

symbols = ['SPY', 'IBM', 'BAC']

for item in symbols:
    working_df = yf.download(item, start=start_date, end=end_date)
    working_df.reset_index(inplace=True)
    working_df.to_csv('{}_{}.csv'.format(item, end_date), index=False)

Note: You will have to know the Yahoo! Finance symbology to download your target symbols. (It's sometimes not intuitive, "CAD=X" is USD/CAD for example.)

Forex [Tick Data]

Quality of data matters and the below options are some of the better quality sources available for free.

Pepperstone / Integral / TrueFX

https://www.truefx.com/truefx-historical-downloads/

Pepperstone relies on price feeds and liquidity very similar to Integral's offering, so similar that for a while Pepperstone used to publish Integral's data on their own FTP for easy customer access. Unfortunately, they stopped offering this FTP access some time ago (thus why most online tutorials referencing them are out of date) and the source of data that Pepperstone currently recommends is Integral's TrueFX data service offering. A free account at TrueFX.com' will get you access to tick data on most major and minor currency pairs from the past year only (Currently only 2019 YTD is available for free.) I encouraged Pepperstone to bring back their historical data access to regain access to years prior to 2019 and if they ever open back up then I'll update this spot here with access info.​

Crypto Tick and Bar Data - Free API and Script Provided

We have a dedicated page with working code for this here!

Crypto Tick and Bar Data - Free API and Script Provided

Related Wikis

Readers of Editing Tick Data for Backtesting and Algo Trading also viewed: