理解初始化设置 - III
继续完善您的策略设置。首先,在名为 tradesize 的对象中将交易规模设为 100,000 USD,用于指定每笔交易的下注金额。其次,在名为 initeq 的对象中将初始权益设为 100,000 USD。
Quantstrat 需要 3 类对象来运行:account、portfolio 和 strategy。一个 account 由多个 portfolio 组成,而一个 portfolio 由多个 strategy 组成。对于您的第一个策略,只有 1 个 account、1 个 portfolio 和 1 个 strategy。我们把它们都命名为 "firststrat"(即 first strategy)。
最后,在继续之前,您必须使用策略移除命令 rm.strat() 清除任何已存在的策略。该函数接收一个策略名称字符串作为输入。
已为您加载 quantstrat 和 quantmod 包。
本练习是课程的一部分
R 中的金融交易
练习说明
- 将
tradesize和initeq定义为表示 $100,000 的整数对象。 - 将
strategy.st、portfolio.st和account.st都设为"firststrat"。 - 使用
rm.strat()移除已存在的策略strategy.st。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Define your trade size and initial equity
tradesize <- ___
initeq <- ___
# Define the names of your strategy, portfolio and account
strategy.st <- ___
portfolio.st <- ___
account.st <- ___
# Remove the existing strategy if it exists
rm.strat(___)