← All Articles

I built custom portfolio rebalancing with AI. Here is how it works.

Austin Starks

Austin Starks

6 min read

Start with the monthly rebalance

This February 2025 feature introduction shows a monthly Magnificent 7 rule in the actual editor below. The screenshot shows configuration, not an executed rebalance. A monthly rule sets when to evaluate; its target weights set what allocation to aim for.

You can also create simple rebalancing rules, such as “Rebalance the Magnificent 7 every month”

Prepare the monthly rebalance draft in Aurora. Inspect its saved schedule and weights before testing. In the historical output, check one rebalance against its intended trigger and orders. Preparing this request does not place orders.

See the allocation arithmetic

For example, an investor targets 60% TQQQ and 40% cash, but the portfolio drifts to 75% TQQQ and 25% cash. In a hypothetical portfolio whose total value remains $10,000, that is $7,500 TQQQ and $2,500 cash; the target is $6,000 and $4,000. The target adjustment would sell $1,500 of TQQQ before fees and fill effects. This is allocation arithmetic, not a recorded executed rebalance.

Read the original development story
Rebalancing a portfolio

I think about this quote from Mark Zuckerberg’s every single day.

“Ideas don’t come out fully formed. They only become clear as you work on them.” – Mark (source)

I thought about this when I built NextTrade, an open-source algorithmic trading platform.

GitHub - austin-starks/NextTrade: A system that performs algorithmic trading

A system that performs algorithmic trading. Contribute to austin-starks/NextTrade development by creating an account on…

github.com

I thought about this when I built NexusTrade, an integrated LLMs for both financial analysis, sentiment analysis, and algorithmic trading.

Using NexusTrade to get recent news data about particular stocks

That quote has stayed with me as I rolled out custom portfolio rebalancing in February 2025. The examples below show how to define triggers and weights in natural language, then inspect historical behavior.

What is portfolio rebalancing?

Portfolio rebalancing is the process of periodically adjusting the composition of an investment portfolio to maintain a desired asset allocation. When investors initially create a portfolio, they typically select an allocation of various asset classes — such as stocks, bonds, commodities, or cryptocurrencies — to align with their risk tolerance, investment goals, and time horizon.

However, as the market fluctuates over time, certain assets may grow disproportionately compared to others, causing the portfolio’s to drift away from its original target.

Portfolio rebalancing corrects this imbalance by selling portions of assets that have become overweight and reallocating the funds into underperforming or underweighted assets, thus restoring the original balance.

What are the challenges with portfolio rebalancing for a no-code platform?

For this no-code feature, I needed to answer three practical questions:

For example:

  1. When will the rebalance trigger? Define the condition or schedule that should start it.
  2. How will we allocate it? Choose fixed weights or specify the inputs used to calculate them.
  3. How do we test these allocations? Inspect historical weights and actions before accepting the configuration.

Those three questions shaped the NexusTrade feature. The examples here describe its behavior; this article does not present a dated comparison of competing tools.

So when building the portfolio re-balancing functionality for NexusTrade, I made sure I created something truly different.

What can the rebalancing rules express?

Creating a highly complex rebalancing strategy that rebalances based on the ratio of a stock’s net income to their revenue using natural language

In the examples below, NexusTrade lets you specify the rebalance trigger and relative weights in natural language. Historical testing lets you inspect the resulting behavior. The precedence and data limitations still matter.

You can do ALL of this… with just natural language.

With NexusTrade, you’re not limited to just “rebalancing actions”; you can also add buy and sell rules to your investing strategy. No matter what strategy you create, the performance of it is automatically backtested on historical data, so you have an idea of exactly how the portfolio performed in the past.

You can combine rebalance action with traditional buy and sell actions too

The architecture for this is extremely extensible. You can, quite literally, rebalance a portfolio based on indicators you would never have imagined. This includes moving averages, fundamental indicators, price-based indicators, earnings data, and more.

Arithmetic operations let you combine inputs in the weight calculation. The next screenshot uses a price z-score, which measures how far the price is from its mean in standard-deviation units.

Rebalancing the Magnificent 7 based on the “z-score” of its price

With this architecture, the possibilities are almost endless. However, the solution isn’t perfect for two key reasons.

Limitations of the Rebalancing Architecture

The rebalance action in NexusTrade is revolutionary, but with its extensibility comes high complexity. Some little things about the action are hidden under the hood, away from the user. For example:

  • If multiple rebalance actions are triggered at the same time, only the first one is executed
  • If a rebalance action is triggered, buy and sell actions cannot be triggered at the same timestep

Additionally, building the entire “rebalance action object” is complex. While the process is abstracted away due to LLMs, it can make mistakes.

Finally (and most importantly), the rebalance action depends significantly on accurate data.

The rebalance action depends on the historical inputs. For one recorded event, compare the timestamp and input values with the saved trigger, check the calculated target weights, then compare those targets with the emitted orders. If two rebalance rules trigger together, check which came first; the first rule wins in this version. The screenshots here show configurations, but do not include a complete event record for that inspection.

Want high-quality historical data for your investing platform? Sign up for EODHD using my affiliate link. Creating an account is 100% free!

Concluding Thoughts

This February 2025 feature combines natural-language rules, configurable weights and historical testing. The monthly Magnificent 7 example is a simple starting point; the net-income-to-revenue and price z-score examples show how calculated weights change the configuration.

Like Mark Zuckerberg said, ideas don’t emerge fully formed. The journey from NextTrade to NexusTrade has been one of constant evolution and pushing boundaries. What started as a no-code algorithmic trading platform has transformed into something far more powerful: a comprehensive system that gives everyday investors the tools they need to create truly sophisticated investment strategies.

The rules are flexible, and that flexibility requires careful inspection. Check the saved configuration and a recorded rebalance before deciding whether the behavior matches your intention.

I have used custom rebalancing rules in my own portfolio. This article shows their configuration, but does not include a matched performance comparison for those personal results.

So what are you waiting for?

NexusTrade - No-Code Automated Trading and Research

Perform financial research and deploy algorithmic trading strategies

nexustrade.io

🤝 Connect with me on LinkedIn

🐦 Follow me on Twitter

👨‍💻 Explore my projects on GitHub

📸 Catch me on Instagram

🎵 Dive into my TikTok

Put your research to work

Create a free account to research a company, build a strategy with Aurora, or inspect a historical backtest. Choose the task you want to try.

or

Free to browse. No credit card required.

Discussion

Sign in or create a free account to join the discussion.

No comments yet.