assetHistory(string Name, int Mode)
Loads price history of an asset from online servers, such as Yahoo™, or from the broker's server.
Asset name used by Yahoo, or Quandl code, or 0 for the current asset.
||FROM_YAHOO - download daily (D1) price data from Yahoo Finance.
FROM_YAHOO|UNADJUSTED - use unadjusted prices.
FROM_QUANDL - download daily (D1) price data from Quandl (Zorro S required).
1 - download one-minute (M1) price data from the broker's server.
0 - download tick quote (T1) data from the broker's server (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 from Yahoo or Quandl prior to the first asset call. This works for daily data only.
- The raw .csv data from Yahoo 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 no CSV data, but an error message from the Yahoo or Quandl server.
- The Quandl database name and '/' or '.' characters are stripped from the historical data file names.
- D1 price data from Yahoo or Quandl 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 or Quandl data. Yahoo Open, high, low, and close prices are automatically adjusted for splits and dividends when the UNADJUSTED flag is not added. The unadjusted close price is stored in the marketVal stream. Yahoo data is downloaded from ichart.finance.yahoo.com, Quandl data from www.quandl.com/api/v3/datasets. The Quandl CHRIS/CME, CHRIS/ICE, and YAHOO EOD databases are supported for price history. Any other Quandl database can be downloaded with the dataDownload function. Check the correct spelling of the asset name or Quandl code.
- Outliers in the price history from Quandl and Yahoo 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. IB provides 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