assetHistory(string Name, int Mode)
Loads price history of an asset from online data providers or from a broker's price server.
Asset symbol or code used by the price source, or 0 for the current asset.
FROM_GOOGLE - download daily (D1) price data from Google™ Finance.
FROM_QUANDL - download daily (D1) price data from Quandl™ (Zorro S required).
FROM_AV - download daily (D1) price data from AlphaVantage™.
FROM_STOOQ - download daily (D1) price data from Stooq™.
FROM_YAHOO - download daily (D1) price data from Yahoo™ Finance (currently inoperational).
+UNADJUSTED - use unadjusted prices.
1 - download unadjusted one-minute (M1) price data from the selected broker.
0 - download unadjusted tick quote (T1) data from the selected broker (Zorro S required).
- For trading with brokers that do not support historical prices in their API, set the PRELOAD flag and use assetHistory() for downloading recent historical data prior to the first asset call. This works for D1 data only.
- The raw .csv data from websites (Google, Quandl, etc) is stored in History\history.csv. If the download fails due to a problem with the asset, the server, ot the Internet, this file usually contains a detailed error message from the price server. The function will attempt twice to download the data before giving up.
- By default, the price history is stored in the History folder under Name plus .t6 extension for D1 data, Name plus year plus .t6 for M1 data, and Name plus year plus .t1 for T1 data. The Quandl database name, an appended ".US" by Stooq, and '/', '.', or ':' characters are automatically stripped from the historical data file names. If the name is otherwise different to the asset name, use file_copy to copy the downloaded file to the correct asset name (f.i. file_copy("History\\ICE.t6","History\\LONDONICE.t6").
- D1 price data that is stored in a single .t6 file that can go back until 1990. For testing only parts of a multi-year .t6 file, use an 8-digit StartDate or EndDate.
- If the price source does not deliver price data, but some error message instead, a "Bad file format" error is displayed. The error message is then usually contained in the downloaded History\history.csv file.
- Google prices are adjusted for splits only, unadjusted prices are not available. Google download is known to fail on certain assets for no apparent reason, even though they can be downloaded manually.
- Yahoo Finance is currently inoperational for data downloads.
- AlphaVantage data loads relatively slow when there is much traffic. The data is of good quality.
- Stooq normally requires a currency identifier appended to the asset name, f.i. "SPY.US". The data loads fast and is of good quality. There is a limit to the number of downloads per day, identified through the IP address.
- Quandl data from the WIKI, CHRIS/CME, and CHRIS/ICE free EOD databases are supported. Other Quandl databases in different formats can be downloaded with the dataDownload function. Quandl data loads fast and is of good quality.
- MT4 servers usually have no long price history, so the command will print an error message or only partially download the history.
- Some brokers, such as IB, also provide only limited price history. FCXM servers provide price history from 2002 for currencies, and from 2008 for some CFDs. Before downloading prices, check if they are not already available in the History folder or on the Zorro download page.
- Check the correct spelling of the asset name or code. Spelling often differs slightly, f.i. the same stock can be named BRK.B, BRK_B, BRK-B, or BRK-B.US dependent on the website or price source.
- Outliers in the price history are automatically fixed.
- When downloading data from a broker, the asset is subscribed automatically (if possible via API). The recent values of the asset's Spread, PipCost, etc. are updated to the Assets.dta file even if no price history is downloaded. This way new assets can be added and available assets can be set up to their current parameter values for further simulations.
- The price history is loaded either for the number of recent years given by NumYears, or for all years between StartDate and EndDate. If a price history file already exists, or if NumYears is set to -1, no price data is downloaded. If the price history of the current year is not up to date, new price data is downloaded and added to the existing file. Make sure that the time resolution of the downloaded prices matches the resolution of the historic data files - the included files are based on 1-minute data.
- For backtesting price history, BarPeriod can not be less than one price history bar. Set it to 1440 for testing D1 price data.
- A price history file with length 0 prevents downloading prices for that particular year. This way, by storing a 0-byte file, price data that is not available or that is of bad quality can be excluded from download attempts and from the backtest.
- For using the newest prices, load the price history before calling asset(), otherwise the asset will use the existing price data files. Use UpdateDays for calling assetHistory automatically to keep the price history up to date.
- For T1 data, the price server of the broker must support quote-based price data; this is the case for FXCM price history back to 2008, but not for IB or for most MT4 brokers. Dependent on the price server speed, downloading T1 quotes can take a long time, such as a whole day for one year of price quotes.
// Update M1 price history of all assets
NumYears = 2;
// Download AAPL D1 prices from Quandl
price, asset, UpdateDays, loadStatus, Import, dataDownload