Setting u p a strateg y I FIN AN C IAL TR AD IN G IN R Il y a Kipnis Professional Q u antitati v e Anal y st and R programmer
Three important dates Q u antstrat needs an initDate , a from date , and a to date . YYYY - MM - DD , eg “2000-01-01” initdate <- "1999-01-01" from <- "2003-01-01" to <- "2015-12-31" FINANCIAL TRADING IN R
Setting u p q u antstrat # Set system environment timezone: Sys.setenv(TZ = "UTC") # Set currency (we’ll use USD for now): currency("USD") # Obtain financial data: getSymbols("LQD", from = from, to = to, src = "yahoo", adjust = TRUE) # Treat as basic equity stock("LQD", currency = "USD", multiplier = 1) FINANCIAL TRADING IN R
O v er v ie w initDate = "1999-01-01" from = "2003-01-01" to = “2015-12-31" Sys.setenv(TZ = "UTC") currency("USD") getSymbols("LQD", from = from, to = to, src = "yahoo", adjust = TRUE) FINANCIAL TRADING IN R
Let ' s practice ! FIN AN C IAL TR AD IN G IN R
Setting u p a strateg y II FIN AN C IAL TR AD IN G IN R Il y a Kipnis Professional Q u antitati v e Anal y st and R programmer
Trade si z e and initial eq u it y In order to w ork w ith ret u rns , y o u need to de � ne trade si z e and initial eq u it y to calc u late pro � t and loss tradesize <- 100000 initeq <- 100000 tradesi z e sho u ld not be more than initeq FINANCIAL TRADING IN R
Three important objects Acco u nt Portfolio Strateg y FINANCIAL TRADING IN R
Naming acco u nt , portfolio , and strateg y Naming the acco u nt , portfolio , and strateg y all the same name s u� ces for basic strategies strategy.st <- portfolio.st <- account.st <- "firststrat" FINANCIAL TRADING IN R
Remo v ing e x isting strateg y If y o u ran the strateg y alread y, y o u need to remo v e it from y o u r en v ironment rm.strat(strategy.st) FINANCIAL TRADING IN R
Initiali z e … Portfolio Acco u nt Orders Strateg y FINANCIAL TRADING IN R
Initiali z ing portfolio Portfolio initiali z ation is called w ith initPortf() initPortf() req u ires portfolio name , s y mbols , initiali z ation date , and c u rrenc y initPortf(portfolio.st, symbols = "LQD", initDate = initdate, currency = "USD") FINANCIAL TRADING IN R
Initiali z ing acco u nt Acco u nt initiali z ation is called w ith initAcct() initAcct() req u ires acco u nt name , portfolios , initiali z ation date , c u rrenc y, and initial eq u it y initAcct(account.st, portfolios = portfolio.st, initDate = initdate, currency = "USD", initEq = initeq) FINANCIAL TRADING IN R
Initiali z ing orders Order initiali z ation is called w ith initOrders() initOrders() req u ires portfolio name and initiali z ation date initOrders(portfolio.st, initDate = initdate) FINANCIAL TRADING IN R
Initiali z ing strateg y Strateg y initiali z ation is called w ith strategy() strategy(strategy.st, store = TRUE) FINANCIAL TRADING IN R
O v er v ie w tradesize <- 100000 initeq <- 100000 strategy.st <- portfolio.st <- account.st <- "firststrat" rm.strat(strategy.st) initPortf(portfolio.st, symbols = "LQD", initDate = initdate, currency = "USD") initAcct(account.st, portfolios = portfolio.st, initDate = initdate, currency = "USD", initEq = initeq) initOrders(portfolio.st, initDate = initdate) strategy(strategy.st, store = TRUE) FINANCIAL TRADING IN R
Let ' s practice ! FIN AN C IAL TR AD IN G IN R
Recommend
More recommend