Reputation: 634
I have several currency pairs, not necessarily downloaded from online resources, it could be a regular file from disk, but for simplicity of the example and reproducibility I will download from the network.
library(quantmod)
getSymbols("AUD/CAD",src="oanda",from="2024-01-01")
getSymbols("CAD/CHF",src="oanda",from="2024-01-01")
getSymbols("USD/JPY",src="oanda",from="2024-01-01")
Now let’s calculate a simple “buy and hold” strategy in points
# buy and hold P&L in points
BH_AUDCAD <- AUDCAD - c(coredata(AUDCAD[1]))
BH_CADCHF <- CADCHF - c(coredata(CADCHF[1]))
BH_USDJPY <- USDJPY - c(coredata(USDJPY[1]))
Now I would like to calculate p&l
in USD
but I’m a little confused and don’t know how to do it correctly
library(FinancialInstrument)
currency(c("AUD", "CAD", "CHF", "USD", "JPY"))
stock(c("AUDCAD", "CADCHF", "USDJPY"), currency="USD")
PnL_USD_AUDCAD <- ....
PnL_USD_CADCHF <- ....
PnL_USD_USDJPY <- ....
Upvotes: 0
Views: 16