Description Usage Arguments Details Value Note Author(s) See Also Examples
Given 2 products, calculate spread values for as many columns as practicable.
1 2 3 4 5 |
prod1 |
chr name of instrument that will be the 1st leg of a 2 leg spread (Can also be xts data for first product) |
prod2 |
chr name of instrument that will be the 2nd leg of a 2 leg spread (Can also be xts data for second product) |
ratio |
Hedge ratio. Can be a single number, or a vector of same length as data. |
currency |
chr name of currency denomination of the spread |
from |
from Date to pass through to getSymbols if needed. |
to |
to Date to pass through to getSymbols if needed. |
session_times |
ISO-8601 time subset for the session time, in GMT, in the format 'T08:00/T14:59' |
notional |
TRUE/FALSE. Should the prices be multiplied by contract multipliers before calculating the spread? |
unique_method |
method for making the time series unique |
silent |
silence warnings? (FALSE by default) |
auto.assign |
If |
env |
If |
... |
other arguments to pass to |
prod1
and prod2
can be the names of instruments, or the xts
objects themselves. Alternatively, prod2
can be omitted, and a vector
of 2 instrument names can be given to prod1
. See the last example for
this usage.
If prod1
and prod2
are names (not xts data), it will try to get
data for prod1
and prod2
from env
(.GlobalEnv by
default). If it cannot find the data, it will get it with a call to
getSymbols. Prices are multiplied by multipliers and exchange rates to get
notional values in the currency specified. The second leg's notional values
are multiplied by ratio
. Then the difference is taken between the
notionals of leg1 and the new values for leg2.
‘make.index.unique’ uses the xts function make.index.unique
‘least.liq’ subsets the spread time series, by using the timestamps
of the leg that has the fewest rows.
‘duplicated’ removes any duplicate indexes.
‘price.change’ only return rows where there was a price change in the
Bid, Mid or Ask Price of the spread.
an xts object with Bid, Ask, Mid columns, or Open, Close, Adjusted columns, or Open, Close columns. or Price column.
requires quantmod
Lance Levenson, Brian Peterson, Garrett See
buildSpread
synthetic.instrument
formatSpreadPrice
buildRatio
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | ## Not run:
currency("USD")
stock("SPY", "USD")
stock("DIA", "USD")
getSymbols(c("SPY","DIA"))
#can call with names of instrument/xts ojects
fSB <- fn_SpreadBuilder("SPY","DIA")
fSB2 <- fn_SpreadBuilder(SPY,DIA) # or you can pass xts objects
#assuming you first somehow calculated the ratio to be a constant 1.1
fSB3 <- fn_SpreadBuilder("SPY","DIA",1.1)
head(fSB)
# Call fn_SpreadBuilder with vector of 2 instrument names
# in 1 arg instead of using both prod1 and prod2.
fSB4 <- fn_SpreadBuilder(c("SPY","DIA"))
#download data and plot the closing values of a spread in one line
chartSeries(Cl(fn_SpreadBuilder(getSymbols(c("SPY","DIA")),auto.assign=FALSE)))
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.