Ensure that the orders submitted to a trader() are within specified constraints.

constrain_orders(
  solved_portfolio,
  connection,
  daily_vol_pct_limit = 0.02,
  min_order_size = 1000,
  max_order_size = 10000,
  buy_only = FALSE,
  terse = TRUE
)

Arguments

solved_portfolio

the output of the function solve_portfolio()

connection

a backend data connection to obtain daily trade volume data

daily_vol_pct_limit

limit the percentage of average trailing 10 day volume for any trade

min_order_size

minimum order size threshold

max_order_size

maximum order size threshold

buy_only

TRUE/FALSE should we omit any sell orders

terse

TRUE/FALSE should the return value be as terse as possible for downstream processing?

Value

a data frame of orders that meet the constraints

Examples

if (FALSE) {
t_conn <- alpaca_connect('paper',
                         Sys.getenv("ALPACA_PAPER_KEY"),
                         Sys.getenv("ALPACA_PAPER_SECRET"))
d_conn <- alpaca_connect('data',
                         Sys.getenv("ALPACA_LIVE_KEY"),
                         Sys.getenv("ALPACA_LIVE_SECRET"))

portfolio_model <- read_portfolio_model(system.file(package='rblncr','extdata/sample_portfolio.yaml'))

get_portfolio_current(t_conn) |>
  load_portfolio_targets(portfolio_model) |>
  price_portfolio(connection = d_conn, price_type = 'close') |>
  solve_portfolio() |>
  constrain_orders(d_conn)
}