While the Excel-based rebalancing tool already saves a lot of time, some investors want to go further than this and fully automate their trading. Most brokerages offer an API to query the account status and place orders, and a fully automated system can be created by scripting some glue logic to connect the two.

Key Considerations for Fully Automated Trading Systems

  • Perform the necessary cleanup steps before using the API data as described for the Excel-based rebalancing tool.
  • Check the rebalanceDate field and avoid rebalancing on days when this is not required. While the weights should be adjusted appropriately, rounding errors might still lead to additional churn.
  • Schedule all API operations late enough in the day. We recommend not relying on the API information any earlier than 6 hours after the markets have closed. If possible, rebalancing should be scheduled closer to the market opening.
  • The API might not return a separate row for assets with zero weight, leading to situations where the account may hold assets that are not mentioned in the allocation returned by the API. Your code will need to handle these situations.
  • Avoid rebalancing of tiny quantities. Brokerages often charge a minimum commission, and the value of the assets rebalanced should be much larger than this minimum commission.
  • Make sure to cancel any pending orders before submitting new orders. Otherwise, you might end up in situations where orders are emitted multiple times, leading to erroneous results.
  • Think long and hard about authentication. Where and how do you store your account credentials? Can these be stolen or used in malicious ways? If at all possible, you should avoid storing your account credentials.

Popular Brokerage APIs: