9.4 Buy and Hold
We want to compare buy and hold strategy.
We first get the data
9.4.1 Step 1: Initialization
9.4.2 Steps 2-4: Applying trading rule
Since buy and sell are not given by trading rule, we directly add transaction to it.
We first add the transaction to buy at the beginning:
FirstDate <- first(time(SPY))
# Enter order on the first date
BuyDate <- FirstDate
equity <- getEndEq("buyHold", FirstDate)
FirstPrice <- as.numeric(Cl(SPY[BuyDate,]))
UnitSize = as.numeric(trunc(equity/FirstPrice))
addTxn("buyHold", Symbol = "SPY",
TxnDate = BuyDate, TxnPrice = FirstPrice,
TxnQty = UnitSize, TxnFees = 0)
We first add the transaction to sell at the end:
9.4.3 Step 5: Evaluation
We update our portfolio, account, and equity:
After updates, we can plot the trading position.
Now we are ready to compare buy-hold and the simple trading rule.