### Calculate Periodic Returns Examples Source: https://www.quantmod.com/documentation/periodReturn.html Examples demonstrating how to calculate returns for various periods and subsets using quantmod. ```R ## Not run: getSymbols('QQQQ',src='yahoo') allReturns(QQQQ) # returns all periods periodReturn(QQQQ,period='yearly',subset='2003::') # returns years 2003 to present periodReturn(QQQQ,period='yearly',subset='2003') # returns year 2003 rm(QQQQ) ## End(Not run) ``` -------------------------------- ### Download exchange rates examples Source: https://www.quantmod.com/documentation/getFX.html Examples showing how to retrieve exchange rates for specific currency pairs and date ranges. ```R getFX("USD/JPY") getFX("EUR/USD",from="2005-01-01") ``` -------------------------------- ### Example of addADX Source: https://www.quantmod.com/documentation/addADX.html Demonstrates the basic execution of the addADX function. ```R ## Not run: addADX() ## End(Not run) ``` -------------------------------- ### Example Usage of OHLC Transformations Source: https://www.quantmod.com/documentation/OHLC.Transformations.html This example demonstrates how to fetch stock data using `getSymbols` and then apply various OHLC transformation functions. Remember to remove symbols after use. ```R getSymbols('IBM',src='yahoo') Ad(IBM) Cl(IBM) ClCl(IBM) seriesHi(IBM) seriesHi(Lo(IBM)) removeSymbols('IBM') ``` -------------------------------- ### ChartSeries Examples Source: https://www.quantmod.com/documentation/chartSeries.html Examples demonstrating the usage of the chartSeries function for visualizing financial data with various options and indicators. ```APIDOC ## ChartSeries Usage Examples This section provides examples of how to use the `chartSeries` function to visualize financial data. ### Example 1: Basic Chart ```R getSymbols("YHOO") chartSeries(YHOO) ``` ### Example 2: Subset by Time Period ```R # Last 4 months chartSeries(YHOO, subset='last 4 months') # Specific date range chartSeries(YHOO, subset='2007::2008-01') ``` ### Example 3: Custom Theme ```R chartSeries(YHOO, theme=chartTheme('white')) ``` ### Example 4: No Volume ```R chartSeries(YHOO, TA=NULL) #no volume ``` ### Example 5: Adding Technical Indicators ```R # Add Volume and Bollinger Bands from TTR package chartSeries(YHOO, TA=c(addVo(),addBBands())) ``` ### Example 6: Adding MACD Indicator ```R # Add MACD indicator to the current chart addMACD() # Redraw chart with all indicators present setTA() chartSeries(YHOO) ``` **Note:** The examples marked with `## Not run:` are intended for demonstration and may not execute directly without specific package installations or data availability. ``` -------------------------------- ### Example: Interactive Zooming Source: https://www.quantmod.com/documentation/zoomChart.html An interactive example demonstrating the `zooom` function. This function requires user clicks to define the zoom area. ```R zooom() # interactive example ``` -------------------------------- ### Example of addExpiry Source: https://www.quantmod.com/documentation/addExpiry.html Demonstrates the basic execution of the addExpiry function. ```R ## Not run: addExpiry() ## End(Not run) ``` -------------------------------- ### Configure and Retrieve Symbol Lookups Source: https://www.quantmod.com/documentation/setSymbolLookup.html Examples of setting symbol sources and retrieving the current lookup configuration. ```R setSymbolLookup(QQQQ='yahoo',DIA='MySQL') getSymbolLookup('QQQQ') getSymbolLookup(c('QQQQ','DIA')) ``` -------------------------------- ### Example of addSAR Source: https://www.quantmod.com/documentation/addSAR.html Demonstrates the basic execution of the addSAR function. ```R ## Not run: addSAR() ## End(Not run) ``` -------------------------------- ### Moving Average Usage Examples Source: https://www.quantmod.com/documentation/addMA.html Basic implementation examples for adding moving averages to a chart. ```R ## Not run: addSMA() addEMA() addWMA() addDEMA() addEVWMA() addZLEMA() ## End(Not run) ``` -------------------------------- ### Example of addSMI Source: https://www.quantmod.com/documentation/addSMI.html Demonstrates the basic invocation of the addSMI function. ```R ## Not run: addSMI() ## End(Not run) ``` -------------------------------- ### Download Symbols with Custom Lookups Source: https://www.quantmod.com/documentation/setSymbolLookup.html Example of using configured lookups to download data. ```R ## Not run: ## Will download QQQQ from yahoo ## and load DIA from MySQL getSymbols(c('QQQQ','DIA')) ## End(Not run) ``` -------------------------------- ### Examples of Next function usage Source: https://www.quantmod.com/documentation/Next.html Demonstrates advancing a zoo time series and merging it with original data, along with model specification examples. ```R Stock.Close <- c(102.12,102.62,100.12,103.00,103.87,103.12,105.12) Close.Dates <- as.Date(c(10660,10661,10662,10665,10666,10667,10668),origin="1970-01-01") Stock.Close <- zoo(Stock.Close,Close.Dates) Next(Stock.Close) #one period ahead Next(Stock.Close,k=1) #same merge(Next(Stock.Close),Stock.Close) ## Not run: # a simple way to build a model of next days # IBM close, given todays. Technically both # methods are equal, though the former is seen # as more intuitive...ymmv specifyModel(Next(Cl(IBM)) ~ Cl(IBM)) specifyModel(Cl(IBM) ~ Lag(Cl(IBM))) ## End(Not run) ``` -------------------------------- ### Example: Building a linear model with quantmod Source: https://www.quantmod.com/documentation/buildModel.html Demonstrates fetching symbols, specifying a model formula, and building the model using the 'lm' method. ```R ## Not run: getSymbols('QQQQ',src='yahoo') q.model = specifyModel(Next(OpCl(QQQQ)) ~ Lag(OpHi(QQQQ),0:3)) buildModel(q.model,method='lm',training.per=c('2006-08-01','2006-09-30')) ## End(Not run) ``` -------------------------------- ### Download financial data examples Source: https://www.quantmod.com/documentation/getSymbols.yahoo.html Demonstrates standard methods for fetching stock data using getSymbols and the recommended configuration approaches. ```R ## Not run: # All 3 getSymbols calls return the same # MSFT to the global environment # The last example is what NOT to do! ## Method #1 getSymbols('MSFT',src='yahoo') ## Method #2 setDefaults(getSymbols,src='yahoo') # OR setSymbolLookup(MSFT='yahoo') getSymbols('MSFT') ######################################### ## NOT RECOMMENDED!!! ######################################### ## Method #3 getSymbols.yahoo('MSFT',env=globalenv()) ## End(Not run) ``` -------------------------------- ### Examples of getMetals usage Source: https://www.quantmod.com/documentation/getMetals.html Demonstrates how to fetch pricing data for specific metals using names or symbols. ```R ## Not run: getFX(c("gold","XPD")) getFX("plat",from="2005-01-01") ## End(Not run) ``` -------------------------------- ### Example of addMACD Source: https://www.quantmod.com/documentation/addMACD.html Demonstrates the basic invocation of the addMACD function. ```R ## Not run: addMACD() ## End(Not run) ``` -------------------------------- ### Retrieve dividend data examples Source: https://www.quantmod.com/documentation/getDividends.html Demonstrates basic usage for fetching dividend data for a stock symbol. ```R ## Not run: getSymbols("MSFT") getDividends("MSFT") getDividends(MSFT) ## End(Not run) ``` -------------------------------- ### Get Yahoo Finance Quote Fields using yahooQF Source: https://www.quantmod.com/documentation/getQuote.html An interactive tool to select specific data fields from Yahoo Finance for use with getQuote. This example shows how to retrieve 'Bid' and 'Ask' fields. ```R yahooQF(c("Bid","Ask")) ``` -------------------------------- ### Example of specifyModel Usage Source: https://www.quantmod.com/documentation/specifyModel.html Demonstrates how to specify a model formula using Next, OpCl, Lag, and Hi functions. If QQQQ is not in the Global environment, it will be retrieved from the source specified with getSymbols.Default. ```R specifyModel(Next(OpCl(QQQQ)) ~ Lag(OpHi(QQQQ),0:3) + Hi(DIA)) ``` -------------------------------- ### Build and Extract Fitted Model Source: https://www.quantmod.com/documentation/fittedModel.html Demonstrates building a linear model using `buildModel` and then extracting the fitted model using `fittedModel`. This example is not run by default. ```R x <- specifyModel(Next(OpCl(DIA)) ~ OpCl(VIX)) x.lm <- buildModel(x,method='lm',training.per=c('2001-01-01','2001-04-01')) fittedModel(x.lm) coef(fittedModel(x.lm)) cof(x.lm) # same vcov(fittedModel(x.lm)) vcov(x.lm) # same ``` -------------------------------- ### Retrieve Data from SQLite Example Source: https://www.quantmod.com/documentation/getSymbols.SQLite.html Demonstrates how to trigger the SQLite data retrieval method through the primary getSymbols interface. ```R ## Not run: getSymbols("QQQQ",src="SQLite") ## End(Not run) ``` -------------------------------- ### Example of getModelData usage Source: https://www.quantmod.com/documentation/getModelData.html Demonstrates updating a model created with specifyModel using the getModelData function. ```R ## Not run: my.model <- specifyModel(Next(OpCl(QQQQ)) ~ Lag(Cl(NDX),0:5)) getModelData(my.model) ## End(Not run) ``` -------------------------------- ### Validate OHLC Data Example Source: https://www.quantmod.com/documentation/has.html Example usage of OHLC validation functions on a retrieved symbol. ```R ## Not run: getSymbols("YHOO") is.OHLC(YHOO) has.OHLC(YHOO) has.Ad(YHOO) ## End(Not run) ``` -------------------------------- ### Download and Access Financial Data Source: https://www.quantmod.com/documentation/getFinancials.html Examples of downloading financial data and accessing specific statement components. ```R ## Not run: JAVA <- getFinancials('JAVA') AAPL <- getFin('AAPL') JAVA$IS$Q # Quarterly Income Statement AAPL$CF$A # Annual Cash Flows str(AAPL) ## End(Not run) ``` -------------------------------- ### Example: Charting and Zooming Data Source: https://www.quantmod.com/documentation/zoomChart.html Demonstrates charting sample data and then zooming into a specific date range. Resets the chart to the full data range when called with no arguments. ```R data(sample_matrix) chartSeries(sample_matrix) zoomChart('2007-04::') zoomChart() ``` -------------------------------- ### Create Default Chart Theme Source: https://www.quantmod.com/documentation/chartTheme.html Creates a default chart theme object. No specific setup or imports are required beyond the function itself. ```R chartTheme() ``` -------------------------------- ### Calculate Contract Expirations using options.expiry and futures.expiry Source: https://www.quantmod.com/documentation/options.expiry.html Demonstrates how to retrieve and use contract expiration indices for options and futures. Ensure the 'quantmod' package is installed and loaded, and a time-indexed zoo object (like AAPL data) is available. ```R getSymbols("AAPL") options.expiry(AAPL) futures.expiry(AAPL) AAPL[options.expiry(AAPL)] ``` -------------------------------- ### Show quantmod Class Structure Source: https://www.quantmod.com/documentation/quantmod-class.html Use this function to display the structure and slots of the quantmod class. No specific setup is required. ```R showClass("quantmod") ``` -------------------------------- ### Load symbols using getSymbols.rda Source: https://www.quantmod.com/documentation/getSymbols.rda.html Examples of how to load data using the rda source, including standard calls and configuration methods. ```R ## Method #1 getSymbols('MSFT',src='rda') getSymbols('MSFT',src='RData') ## Method #2 setDefaults(getSymbols,src='rda') # OR setSymbolLookup(MSFT='rda') # OR setSymbolLookup(MSFT=list(src='rda')) getSymbols('MSFT') ######################################### ## NOT RECOMMENDED!!! ######################################### ## Method #3 getSymbols.rda('MSFT',verbose=TRUE,env=globalenv()) ``` -------------------------------- ### Download USD to EUR Rate from Oanda Source: https://www.quantmod.com/documentation/getSymbols.oanda.html Example of downloading the USD to EUR currency pair from Oanda.com using the getSymbols function. The 'src="oanda"' argument specifies the data source. ```R getSymbols("USD/EUR",src="oanda") ``` ```R getSymbols("USD/EUR",src="oanda",from="2005-01-01") ``` -------------------------------- ### Create Chart Theme with Base Theme Source: https://www.quantmod.com/documentation/chartTheme.html Creates a chart theme object using a specified base theme, such as 'white'. No specific setup or imports are required beyond the function itself. ```R chartTheme('white') ``` -------------------------------- ### Build Data Object with Transformations Source: https://www.quantmod.com/documentation/buildData.html Use buildData to create a data object for modeling. Apply transformations to raw data using a formula mechanism. This example demonstrates using Lag and squared Lag transformations. ```R buildData(Next(OpCl(DIA)) ~ Lag(TBILL) + I(Lag(OpHi(DIA))^2)) ``` ```R buildData(Next(OpCl(DIA)) ~ Lag(TBILL), na.rm=FALSE) ``` ```R buildData(Next(OpCl(DIA)) ~ Lag(TBILL), na.rm=FALSE, return.class="ts") ``` -------------------------------- ### Get Yahoo Finance Quote Fields (Alternative) Source: https://www.quantmod.com/documentation/getQuote.html This function is used to retrieve specific data fields from Yahoo Finance. The example shows a call to retrieve quote fields. ```R yahooFQ() ``` -------------------------------- ### GET modelSignal Source: https://www.quantmod.com/documentation/modelSignal.html Extracts the model signal object from a quantmodResults object. ```APIDOC ## GET modelSignal ### Description Extract model signal object from quantmodResults object as an object of class `zoo`. ### Method GET ### Parameters #### Path Parameters - **x** (quantmodResults) - Required - The quantmodResults object from which to extract the signal. ### Value A `zoo` object indexed by signal dates. ``` -------------------------------- ### GET modelData Source: https://www.quantmod.com/documentation/modelData.html Extracts the dataset created for use in modeling from a quantmod object. ```APIDOC ## GET modelData ### Description Extract from a `quantmod` object the dataset created for use in modelling. This function returns the `zoo` object containing all transformations specified in `specifyModel`. ### Parameters #### Arguments - **x** (quantmod object) - Required - A quantmod object created by specifyModel. - **data.window** (character vector) - Optional - Subset start and end dates to return. - **exclude.training** (logical) - Optional - Whether to remove the training period. ### Value An object of class `zoo` containing all transformations to data specified in `specifyModel`. ### Request Example modelData(m, data.window = c("2023-01-01", "2023-12-31"), exclude.training = FALSE) ### Response - **zoo object** - The combined model frame containing all model inputs. ``` -------------------------------- ### GET getSymbols Source: https://www.quantmod.com/documentation/getSymbols.html Retrieves financial market data for specified symbols from configured sources. ```APIDOC ## GET getSymbols ### Description Loads financial market data for one or more symbols. The source of the data can be defined via setSymbolLookup or setDefaults. ### Method GET ### Endpoint getSymbols(Symbols, src, return.class) ### Parameters #### Path Parameters - **Symbols** (character vector) - Required - A vector of symbols to retrieve. #### Query Parameters - **src** (string) - Optional - The data source (e.g., 'yahoo', 'MySQL', 'FRED'). - **return.class** (string) - Optional - The class of the returned object (e.g., 'ts', 'xts'). ### Request Example getSymbols(c('QQQQ', 'SPY')) ### Response #### Success Response (200) - **data** (object) - The financial data object loaded into the environment. ``` -------------------------------- ### Directly Call getSymbols.google (Method 3 - Not Recommended) Source: https://www.quantmod.com/documentation/getSymbols.google.html This method demonstrates calling getSymbols.google directly. It is explicitly marked as not recommended due to potential issues and is shown for completeness. ```R getSymbols.google('MSFT',verbose=TRUE,env=globalenv()) ``` -------------------------------- ### GET getSymbols.yahoo Source: https://www.quantmod.com/documentation/getSymbols.yahoo.html Downloads OHLC data for specified symbols from Yahoo Finance into a designated environment. ```APIDOC ## getSymbols.yahoo ### Description Downloads OHLC data for specified symbols from finance.yahoo.com. This method is intended to be called internally by getSymbols. ### Usage getSymbols.yahoo(Symbols, env, return.class = 'xts', from = "2007-01-01", to = Sys.Date(), ...) ### Parameters #### Arguments - **Symbols** (character vector) - Required - Names of each symbol to be loaded. - **env** (environment) - Required - The environment where objects should be created. - **return.class** (string) - Optional - The class of the returned object (e.g., 'xts', 'zoo', 'ts'). - **from** (string) - Optional - Retrieve data no earlier than this date (default: "2007-01-01"). - **to** (string) - Optional - Retrieve data through this date (default: Sys.Date()). - **...** (dots) - Optional - Additional parameters. ### Value Loads one object for each Symbol into the specified environment with the class defined by return.class. ``` -------------------------------- ### Download and Chart Stock Data Source: https://www.quantmod.com/documentation/chartSeries.html Demonstrates downloading stock data using getSymbols and charting it with chartSeries. Can specify subsets of data by date. ```R getSymbols("YHOO") chartSeries(YHOO) ``` ```R chartSeries(YHOO, subset='last 4 months') ``` ```R chartSeries(YHOO, subset='2007::2008-01') ``` ```R chartSeries(YHOO,theme=chartTheme('white')) ``` ```R chartSeries(YHOO,TA=NULL) #no volume ``` ```R chartSeries(YHOO,TA=c(addVo(),addBBands())) #add volume and Bollinger Bands from TTR ``` -------------------------------- ### Download MSFT Data Using getSymbols (Method 1) Source: https://www.quantmod.com/documentation/getSymbols.google.html This method demonstrates the primary way to download stock data using getSymbols by specifying the source as 'google'. The data is loaded into the global environment. ```R getSymbols('MSFT',src='google') ``` -------------------------------- ### getSymbols.google Function Signature Source: https://www.quantmod.com/documentation/getSymbols.google.html This is the function signature for getSymbols.google. It is not meant to be called directly but serves as a guide for accepted arguments. ```R getSymbols.google(Symbols, env, return.class = 'xts', from = "2007-01-01", to = Sys.Date(), ...) ``` -------------------------------- ### Download MSFT Data Using setDefaults or setSymbolLookup (Method 2) Source: https://www.quantmod.com/documentation/getSymbols.google.html This method shows an alternative to downloading stock data by first setting default source to 'google' or specifying the lookup for 'MSFT'. Subsequent calls to getSymbols will use these settings. ```R setDefaults(getSymbols,src='google') # OR setSymbolLookup(MSFT='google') getSymbols('MSFT') ``` -------------------------------- ### Retrieve MSFT Data from MySQL (Method 2) Source: https://www.quantmod.com/documentation/getSymbols.MySQL.html Configure default source to 'MySQL' or set symbol lookup for 'MSFT' to 'MySQL', then call getSymbols without specifying the source. This method loads data into the global environment. ```R setDefaults(getSymbols,src='MySQL') # OR setSymbolLookup(MSFT='MySQL') getSymbols('MSFT') ``` -------------------------------- ### Configure and Retrieve Market Data Source: https://www.quantmod.com/documentation/getSymbols.html Configures symbol sources using setSymbolLookup and setDefaults, then retrieves data with getSymbols. ```R ## Not run: setSymbolLookup(QQQQ='yahoo',SPY='MySQL') getSymbols(c('QQQQ','SPY')) # loads QQQQ from yahoo (set with setSymbolLookup) # loads SPY from MySQL (set with setSymbolLookup) getSymbols('F') # loads Ford market data from yahoo (the formal default) setDefaults(getSymbols,verbose=TRUE,src='MySQL') getSymbols('DIA') # loads symbol from MySQL database (set with setDefaults) getSymbols('F',src='yahoo',return.class='ts') # loads Ford as time series class ts ## End(Not run) ``` -------------------------------- ### Download CPI Data using setDefaults and getSymbols (Method 2) Source: https://www.quantmod.com/documentation/getSymbols.FRED.html This method sets the default source to 'FRED' for subsequent getSymbols calls, then downloads CPI data. ```R setDefaults(getSymbols,src='FRED') # OR setSymbolLookup(CPIAUCNS='FRED') getSymbols('CPIAUCNS') ``` -------------------------------- ### Load MSFT Data using getSymbols Source: https://www.quantmod.com/documentation/getSymbols.csv.html Demonstrates multiple methods to load 'MSFT' symbol data from CSV files into the global environment using getSymbols. The third method is explicitly not recommended. ```R ## Method #1 getSymbols('MSFT',src='csv') ## Method #2 setDefaults(getSymbols,src='csv') # OR setSymbolLookup(MSFT='csv') getSymbols('MSFT') ######################################### ## NOT RECOMMENDED!!! ######################################### ## Method #3 getSymbols.csv('MSFT',verbose=TRUE,env=globalenv()) ## End(Not run) ``` -------------------------------- ### Combine OHLC Transformations Source: https://www.quantmod.com/documentation/OHLC.Transformations.html These functions apply one-period transformations to OHLC data. For example, `OpCl(x)` returns the Open to Close of an object. ```R OpCl(x) ``` ```R ClCl(x) ``` ```R HiCl(x) ``` ```R LoCl(x) ``` ```R LoHi(x) ``` ```R OpHi(x) ``` ```R OpLo(x) ``` ```R OpOp(x) ``` -------------------------------- ### Define getFX usage Source: https://www.quantmod.com/documentation/getFX.html Defines the function signature and default parameters for downloading exchange rates. ```R getFX(Currencies, from = "2007-01-01", to = Sys.Date(), env = .GlobalEnv, verbose = FALSE, warning = TRUE, auto.assign = TRUE, ...) ``` -------------------------------- ### Get Variance-Covariance Matrix of Fitted Model Source: https://www.quantmod.com/documentation/fittedModel.html Retrieves the variance-covariance matrix of the fitted model. This is equivalent to calling `vcov` directly on the quantmod object. ```R vcov(fittedModel(x.lm)) ``` -------------------------------- ### Usage of buildModel Source: https://www.quantmod.com/documentation/buildModel.html Standard function signature for building a model. ```R buildModel(x, method, training.per, ...) ``` -------------------------------- ### Get Coefficients of Fitted Model Source: https://www.quantmod.com/documentation/fittedModel.html Retrieves the coefficients of a fitted model extracted from a quantmod object. This is equivalent to calling `coef` directly on the quantmod object. ```R coef(fittedModel(x.lm)) ``` -------------------------------- ### Get Default Quote Format using standardQuote Source: https://www.quantmod.com/documentation/getQuote.html Returns a default quote format object for use with the getQuote function, specifically for Yahoo! data. ```R standardQuote() ``` -------------------------------- ### Download CPI Data using getSymbols.FRED with explicit environment (Method 3 - Not Recommended) Source: https://www.quantmod.com/documentation/getSymbols.FRED.html This method explicitly calls getSymbols.FRED, specifying the symbol and the global environment. This is not the recommended approach. ```R getSymbols.FRED('CPIAUCNS',env=globalenv()) ``` -------------------------------- ### Get Current Stock Quote using getQuote Source: https://www.quantmod.com/documentation/getQuote.html Fetches the current stock quote for a single symbol from Yahoo Finance. Ensure the symbol is valid. ```R getQuote("AAPL") ``` -------------------------------- ### POST buildModel Source: https://www.quantmod.com/documentation/buildModel.html Constructs and attaches a fitted model of a specified type to a quantmod object. ```APIDOC ## POST buildModel ### Description Construct and attach a fitted model of type `method` to a `quantmod` object. ### Method POST ### Parameters #### Request Body - **x** (quantmod object) - Required - An object of class `quantmod` created with `specifyModel` or an R formula. - **method** (string) - Required - A character string naming the fitting method (e.g., lm, glm, loess, rpart, randomForest, svm). - **training.per** (character vector) - Required - Dates in ISO 8601 format "CCYY-MM-DD" or "CCYY-MM-DD HH:MM:SS" of length 2. - **...** (dots) - Optional - Additional arguments to the method call. ### Response #### Success Response (200) - **object** (quantmod) - An object of class `quantmod` with the fitted model attached. ``` -------------------------------- ### Download CPI Data using getSymbols.FRED (Method 1) Source: https://www.quantmod.com/documentation/getSymbols.FRED.html This method directly calls getSymbols with the 'FRED' source to download CPI data to the global environment. ```R getSymbols('CPIAUCNS',src='FRED') ``` -------------------------------- ### Retrieve MSFT Data Directly (Not Recommended) Source: https://www.quantmod.com/documentation/getSymbols.MySQL.html Directly call getSymbols.MySQL to fetch 'MSFT' data, specifying the environment. This method is explicitly marked as not recommended. ```R getSymbols.MySQL('MSFT',env=globalenv()) ``` -------------------------------- ### Customize Chart Theme Colors Source: https://www.quantmod.com/documentation/chartTheme.html Creates a chart theme object based on the 'white' theme, customizing the up and down bar colors to blue and red, respectively. No specific setup or imports are required beyond the function itself. ```R chartTheme('white',up.col='blue',dn.col='red') ``` -------------------------------- ### getFX Function Source: https://www.quantmod.com/documentation/getFX.html Downloads exchange rates or metals prices from Oanda and assigns them to the specified environment. ```APIDOC ## getFX ### Description Download exchange rates or metals prices from oanda. ### Usage getFX(Currencies, from = "2007-01-01", to = Sys.Date(), env = .GlobalEnv, verbose = FALSE, warning = TRUE, auto.assign = TRUE, ...) ### Parameters - **Currencies** (string) - Required - Currency pairs expressed as 'CUR/CUR' - **from** (string) - Optional - Start date expressed in ISO CCYY-MM-DD format - **to** (string) - Optional - End date expressed in ISO CCYY-MM-DD format - **env** (environment) - Optional - Which environment should they be loaded into - **verbose** (boolean) - Optional - Be verbose - **warning** (boolean) - Optional - Show warnings - **auto.assign** (boolean) - Optional - Use auto.assign - **...** (dots) - Optional - Additional parameters to be passed to getSymbols.oanda method ### Value The results of the call will be the data assigned automatically to the environment specified. Additionally, a vector of downloaded symbol names will be returned. ### Request Example getFX("USD/JPY") ### Response - **Return Value** (vector) - A vector of downloaded symbol names ``` -------------------------------- ### Get Multiple Quotes with Specific Fields using getQuote Source: https://www.quantmod.com/documentation/getQuote.html Fetches current quotes for multiple symbols, requesting only 'Bid' and 'Ask' prices. Note that Yahoo Finance has a limit of 200 symbols per call. ```R getQuote("QQQQ;SPY;^VXN",what=yahooQF(c("Bid","Ask"))) ``` -------------------------------- ### Create Open High Low Close Object Source: https://www.quantmod.com/documentation/quantmod.OHLC.html Use `as.quantmod.OHLC` to coerce an object with appropriate columns into the `quantmod.OHLC` class, which extends `zoo`. This is useful for standardizing financial time series data. ```R as.quantmod.OHLC(x, col.names = c("Open", "High", "Low", "Close", "Volume", "Adjusted"), name = NULL, ...) ``` -------------------------------- ### POST tradeModel Source: https://www.quantmod.com/documentation/tradeModel.html Simulates trading of a fitted quantmod object by calculating signals and applying trade rules. ```APIDOC ## POST tradeModel ### Description Simulated trading of fitted quantmod object. Given a fitted model, tradeModel calculates the signal generated over a given historical period, then applies specified trade.rule to calculate and return a tradeLog object. ### Method POST ### Parameters #### Request Body - **x** (quantmod object) - Required - A quantmod object from buildModel - **signal.threshold** (numeric vector) - Optional - A numeric vector describing simple lower and upper thresholds before trade occurs - **leverage** (numeric) - Optional - Amount of leverage to apply - **return.model** (boolean) - Optional - Should the full model be returned? - **plot.model** (boolean) - Optional - Plot the model? - **trade.dates** (string) - Optional - Specific trade interval - **exclude.training** (boolean) - Optional - Exclude the period trained on? - **ret.type** (string) - Optional - A table of period returns (weeks, months, quarters, years) ### Response #### Success Response (200) - **quantmodResults** (object) - A quantmodResults object containing the trade log and performance metrics. ``` -------------------------------- ### getMetals - Download Daily Metals Prices Source: https://www.quantmod.com/documentation/getMetals.html This function downloads daily metals prices from oanda. It serves as a convenience wrapper to getSymbols(x, src='oanda'). ```APIDOC ## GET /websites/quantmod/getMetals ### Description Download daily metals prices from oanda. ### Method GET (simulated via R function call) ### Endpoint /websites/quantmod/getMetals ### Parameters #### Query Parameters - **Metals** (character vector) - Required - Metals expressed in common name or symbol form (e.g., XAU, XAG, XPD, XPT). - **from** (character) - Optional - Start date expressed in ISO CCYY-MM-DD format. Defaults to "2007-01-01". - **to** (character) - Optional - End date expressed in ISO CCYY-MM-DD format. Defaults to Sys.Date(). - **base.currency** (character) - Optional - Which currency should the price be in. Defaults to "USD". - **env** (environment) - Optional - Which environment should they be loaded into. Defaults to .GlobalEnv. - **verbose** (logical) - Optional - Be verbose. Defaults to FALSE. - **warning** (logical) - Optional - Show warnings. Defaults to TRUE. - **auto.assign** (logical) - Optional - Use auto.assign. Defaults to TRUE. - **...** (any) - Optional - Additional parameters to be passed to getSymbols.oanda method. ### Request Example ```R getMetals(Metals = c("gold", "XPD"), from = "2005-01-01") ``` ### Response #### Success Response (200) Data will be assigned automatically to the environment specified (global by default). If auto.assign is set to FALSE, the data from a single metal request will simply be returned from the function call. If auto.assign is used (the default) a vector of downloaded symbol names will be returned. #### Response Example (Returns assigned data in the specified environment or directly) ### See Also `getSymbols`, `getSymbols.oanda` ``` -------------------------------- ### Set Defaults for getSymbols.MySQL Source: https://www.quantmod.com/documentation/getSymbols.MySQL.html Configure default connection parameters for getSymbols.MySQL. This is useful for specifying user, password, and database name once. ```R setDefaults(getSymbols.MySQL,user='jdoe',password='secret', dbname='tradedata') ```