In my last article, I discussed
the evolution of my passion
project NexusTrade.io — a no-code
algorithmic trading platform.
If you can’t beat them… steal
their idea Pt 2: Designing the
rebalance action
In my last article, I discussed the evolution
of my passion project
NexusTrade.io — a no-code algorithmic
trading platform. I described
my goal of creating a platform
that can express any idea you
could possibly imagine. This
is made possible with
NexusTrade’s “Strategy” — a
rule that defines how much of
an asset to trade and when to
execute that trade. I also
discussed the architectural
changes needed to implement
the “rebalance” action — an
action within the
Composer
platform that allows a trader
to dynamically control the
relative weights of the assets
in a portfolio. One of the
biggest changes I made in that
article was refactoring the
“Strategy” interface.
// A strategy says to execute action when condition evaluates to true
interface IStrategy {
_id?: Id;
name: string;
condition?: Condition;
action: Action;
}
// An action is the config needed for "buy", "sell", and "rebalance" actions
interface Action {
type: ActionEnum; // buy, sell, or rebalance
targetAsset?: AbstractAsset; // needed for buy/sell
amount?: {amount: number, type: AllocationEnum}; // shares, dollars, etc
// the rebalance parameters will be explained in detail
}
This article will be a
continuation of the last
article. I will discuss the
NexusTrade’s “rebalance”
implementation in great
detail. For this article, I’ll
assume you read the previous
article and understand the
difference between a
NexusTrade Strategy and a
Composer Symphony. I’ll also
assume you have some knowledge
of trading and basic concepts
within algorithmic trading,
including backtesting and
creating algorithmic trading
strategies. If you’re not as
familiar with those concepts,
check out this article
first before you continue
reading.
What is Portfolio
Rebalancing?
Portfolio rebalancing is the
process of buying and selling
assets in your portfolio to
maintain a desired level of
asset allocation. For example,
if you want to maintain a
60/40 split between stocks and
bonds, but market movements
have caused your stocks to now
make up 70% of your portfolio,
you would sell some stocks and
buy bonds to get back to your
60/40 target.
Rebalancing helps manage
risk, encourages disciplined
investing, and has been shown
to improve long-term returns.
NexusTrade’s rebalance action
allows users to automate this
process based on customizable
rules without writing complex
code.
With this context in mind,
let’s dive into how NexusTrade
has implemented this powerful
feature…
Lights, Camera, Action:
Rebalance
My goal isn’t just to copy
Composer’s features and claim
I have “feature parity”. I
want to build a better, more
flexible, and more powerful
rebalance action. Here’s how I
will do it.
I will start by extending the
Action interface. It will now
look something like
this.
interface RebalanceAction extends Action {
type: ActionEnum.rebalance;
sort: Indicator;
limit: number;
weightingMetric: "ProportionalToIndicator" | "EqualWeight"
fixedAssets: Array<FixedAssetConfig>;
variableAssets: Array<AbstractAsset>;
}
interface FixedAssetConfig {
asset: AbstractAsset;
comparator: Comparator;
percent: number; // between 0 and 100
}
A lot of this will look
confusing (especially if
you’re not a software
engineer). So allow me to
explain.
The Rebalance Action will be
another action (like Buy and
Sell). The goal of the
rebalance action is to define
the relative weights of all of
the assets in a
portfolio.
Unlike a traditional “buy” or
“sell” action, the rebalance
action will involve executing
multiple buys and sells
simultaneously. For the sake
of simplicity, we’ll default
all orders to use market
orders.
After the rebalance action
resolves, the end result is a
portfolio with all of the
assets in it at the proportion
that the user defined. This
might sound complicated and
abstract, so let’s bring this
to life with an example.
User Story: A Category 3
Investor Wants to Trade Big
Tech Stocks
I am a category 3
investor, meaning I’m knowledgeable
about the markets and know
what kind of strategy I want
to execute. I want to create a
portfolio with the following 7
trading rules that have served
me well. Please note, these
don’t reflect my true
opinions; this is an
example:
-
I LOVE Tesla. Regardless of
how its doing, I always want
to have
at least 10%
of my portfolio invested in
Tesla
-
I strongly believe in
Bitcoin, but I think its
very risky. Thus, I always
want to have
exactly 10%
of my portfolio invested in
Bitcoin
-
I was fired from Amazon and
have a personal vendetta
against them. Thus, I never
want to have
more than 5%
of my portfolio in
Amazon
-
I believe less is more and
only want to be invested in
5
stocks at a time
-
I’m a strong believer in
Mr. Wonderful’s investing
philosophy
and want to invest in the
company’s with the highest
free cash flows.
-
I will rebalance my
portfolio
every
14 days.
-
My total investing universe
is every stock in the
market
To my knowledge, you can’t execute a set of
complicated rules like this
using the
Composer.trade
platform. If I’m wrong, please
correct me in the comments and
I will update this
section.
With the implementation of
the rebalance action in
NexusTrade, we can create
this. Here’s how.
For starters, we would create
a new portfolio using Aurora,
NexusTrade’s AI Copilot.
Aurora can translate plain
English into a configuration
NexusTrade understands
After describing the strategy
as above, Aurora will create a
strategy utilizing the
following action.
const rebalanceAction: Action {
type: ActionEnum.rebalance;
limit: 5;
weightingMetric: ProportionalToIndicator<FreeCashFlow>
fixedAssets: [
{asset: "TSLA", comparator: Comparator.greaterThan, percent: 10},
{asset: "BTC", comparator: Comparator.equal, percent: 10},
{asset: "AMZN", comparator: Comparator.lessThan, percent: 5},
],
variableAssets: [
// every stock in the stock market
],
}
Notice how the user doesn’t
have to configure it using a
complex form or writing custom
trading logic. They can
literally just describe their
natural thought processes when
formulating a trading
strategy, and execute that
strategy using the
platform.
Aurora will also
automatically perform
validation logic before saving
this action to a strategy. For
example, depending on the
implementation choices, I may
want to have the following
validation rules:
-
The minimum of the fixed
assets’ percents must add up
to 100 or less
-
The value of limit must be
greater than or equal to
fixed assets
The reasons for these
limitations should be more
clear after describing the
control flow of the rebalance
action.
Executing the rebalance
action
Here is a diagram
representing what I’m calling
“the Rebalance
Algorithm”.
The “Rebalance Algorithm” for
the rebalance action
The “Rebalance Algorithm” is
a sequential series of steps
that executes the rebalance
action. The algorithm is
designed to output a
portfolio, with all of the
positions of the portfolio
specified by the rebalance
action.
By executing the rebalance
action (as described by the
user earlier), the user will
create a portfolio with at
least 10% of their portfolio
in Tesla. Depending on Tesla’s
free cash flow, there might be
even more.
I will also have other
companies with high free cash
flows in my portfolio like
Microsoft, Apple, Google, and
Amazon. However importantly,
I will never have more than
5% of my portfolio value in
Amazon.
The relative weights of all
of the other assets in my
portfolio will be relative to
their free cash flows. The
higher the free cash flow, the
greater the weighting.
The end result is a portfolio
with 5 stocks in it that
confirms to the rebalance
action configuration. How cool
is that!
Concluding Thoughts: The End
Results Matches the
Mission
In this article, I hoped to
have articulated how I
implemented the rebalance
action in a way that’s more
flexible and powerful than
Composer, another no-code
algorithmic trading platform.
I’ve explained how a
professional trader can use
the NexusTrade platform to
create a sophisticated trading
strategy. The end result
brings us closer to
actualizing my mission of
developing a platform that can
configure any idea you can
imagine.
Additionally, I’ve shown how
Aurora, a trading copilot, can
take the rules as described by
the trader and automatically
generate the resulting
rebalance action
configuration. I then showed
how the “Rebalance Algorithm”
results in a portfolio that
correspond to this
configuration.
I hope that by enabling
traders to execute their
complex logic on a simple
platform, that I can make
people realize that
algorithmic trading isn’t just
for the big hedge funds and
large prop shops. It’s now
accessible to everybody with
an IPhone. The potential of it
is limitless, and
NexusTrade.io
will be at the forefront of
the innovations.
Want to experience
next-generation algorithmic
trading?
Try NexusTrade today for
free.