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
)
the output of the function solve_portfolio()
a backend data connection to obtain daily trade volume data
limit the percentage of average trailing 10 day volume for any trade
minimum order size threshold
maximum order size threshold
TRUE/FALSE should we omit any sell orders
TRUE/FALSE should the return value be as terse as possible for downstream processing?
a data frame of orders that meet the constraints
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)
}