assetHistory(string Name, int Mode)
Loads price history of an asset from online data providers such as Quandl™, or from the broker's price server.
Asset name used by the price source, or Quandl code, 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™ (Zorro S required).
FROM_YAHOO - download daily (D1) price data from Yahoo™ Finance (currently inoperational).
FROM_YAHOO|UNADJUSTED - use unadjusted prices.
1 - download one-minute (M1) price data from the selected broker or price source.
0 - download tick quote (T1) data from the selected broker or price source (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 Yahoo, Google, or Quandl is stored in History\history.csv. If the download fails due to a problem with the asset or a server issue, this file usually contains a detailed error message from the price server.
- The Quandl database name and '/', '.', or ':' characters are stripped from the historical data file names.
- D1 price data is not split into year files, but stored in a single .t6 file starting with 1990. For testing parts of a multi-year .t6 file, use an 8-digit StartDate or EndDate.
- Connection to a broker is not required for downloading Yahoo, Google, AlphaVantage or Quandl daily data. Yahoo, AlphaVantage, and Quandl prices are automatically adjusted for splits and dividends when the UNADJUSTED flag is not added. Google prices are adjusted for splits only, unadjusted prices are not available. Yahoo Finance is currently inoperational and unlikely to be fixed soon or ever. Google download fails on a few assets for no apparent reason, even though they can be downloaded manually. AlphaVantage data loads slow, partially due to huge file sizes caused by the JSON format. The Quandl WIKI, CHRIS/CME, and CHRIS/ICE free EOD databases are supported for price history. Other Quandl databases in different format can be downloaded with the dataDownload function. 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, or BRK-B dependent on the price source.
- Outliers in the price history are automatically fixed.
- 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.
- 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. It is stored in the format described under Data Import. 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.
- The historical data format is described under Import. Single price quotes in T1 format can be loaded by setting mode to 0 (with Zorro S). For this 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