1/25

I promised that when @FTX_Official launched tokenized stocks, I'd show you how to build your own *SUPER SIMPLE* auto-balancing ETF using their Quant Zone: https://ftx.com/quant-zone#a=stocktrades

This won't turn you into @SBF_Alameda but its good for beginners!

Follow along 👇👀
2/25

This is a simple auto balancing ETF, designed to hold 4 different stocks (you can add as many as you like). It aims for each stock to be roughly 25% of your total position. When a stock rises to >31.25% of your position it sells the stock for USD.
3/25

When a stock is < 20% of your position and it has free cash, it will buy that stock.

On FTX click on subaccounts and created a dedicated subaccount for your autobalance ETF: https://ftx.com/subaccounts#a=stocktrades
4/25

Make sure you are in your subaccount and go to the Quant Zone: https://ftx.com/quant-zone/rules#a=stocktrades

Here we're going to create a series of rules that tell the system when & what we want to buy and sell.

For our 4 stocks, we'll have 8 rules in total.
5/25

First, we'll start off by creating 4 rules for when we want to buy stocks:
6/25

Each rule starts with a "Trigger". This is basically a true or false question. Such as "is AAPL less than 25% of my portfolio?"

If the answer is yes, then we want to buy AAPL.

But, the system does this in a scripting language.
7/25

For our trigger we're going to put:

((balance("AAPL") * (bid_price("AAPL/USD"))) < (collateral * 0.20)) and ((bid_price("AAPL/USD")) < (balance("USD"))) and ((balance("USD") > (collateral * 0.05)))
8/25

What this says is:

1. If my balance of AAPL is less than 20% of my collateral value.

2. And, if I have more money than the AAPL price.

3. And, if my USD balance is more than 5% of my collateral value.
9/25

In this case, we want it to then buy more AAPL.

We're going to tell it that if all of those "Triggers" are true, it should take the "Action" of "Place Custom Order"

We'll have it place a "Limit Order" to "Buy" "AAPL/USD"
10/25

When we are buying, we likely don't want to buy all at once as that spikes the market price. We want to buy over time with a TWAP (time weighted price average).

Since the Quant Zone already checks each rule every 15 seconds for us, we can easily make a TWAP.
11/25

To do this, we set the "Order Size" to this:

balance("USD") * 15 / (60 * 60 * price("AAPL/USD"))

This command says we want to spend our available USD balance buying AAPL stock, but spread out evenly across the next hour.
12/25

If you want to spread your buying out over a longer period such as 24 hours, you can simply add in an extra variable:

balance("USD") * 15 / (60 * 60 * 24 * price("AAPL/USD"))
13/25

Now for the "Limit Price" we'll set:

bid_price("AAPL/USD") - (bid_price("AAPL/USD") * 0.00005)

This tells the system to place the buy order at 0.0005% lower than the current order.

This ensures we are always the market maker and get lower fees.
14/25

We also want to set the order to "Cancel and place a new order" if an order already exists (as that means the market moved) and "Cancel order if rule is no longer triggered"
15/25

Now we can save the draft on that.

Duplicate this rule for the other 3 stocks you want to add. All you need to do is update anywhere it says "AAPL".

Now we are going to create the sell rules.
16/25

For this one we'll set the Trigger like so:

((balance("AAPL") * (bid_price("AAPL/USD"))) > (collateral * 0.3125))

This basically says, if Apple becomes more than 31.25% of our portfolio, we want to trigger the action.
17/25

We'll trigger another custom limit order, this time to sell AAPL/USD.

For our "Order Size" we'll do:

(((balance("AAPL") * (bid_price("AAPL/USD"))) - (collateral * 0.25)))/(bid_price("AAPL/USD"))
18/25

This says, we want to sell as many AAPL stock as represent the value between our current portfolio allocation and our target of 25%.

Now we need to set our limit price, we'll do the same thing we did on the sell side, but in reverse.
19/25

offer_price("AAPL/USD") + (offer_price("AAPL/USD") * 0.00005)

This says sell our AAPL stock at slightly above the current best offer price, so we are on the maker side.

Cancel and place new order if one is already on the books and cancel the order if the rule isn't true
20/25

Now you can duplicate that rule for each of the stocks in your portfolio.

Once all your stocks are set, decide how much you want to put into your ETF - and on the "Manage Subaccounts" page transfer in that amount
21/25

Before you start, purchase the four stocks with roughly 25% of your USD balance (as the ETF is set up to rebalance and not to handle the initial buying).

Once ready, you can hit 'save and run' on each of them.
22/25

This is a super simple example, and I don't necessarily recommend these rules and haven't robustly tested this balancing script.

It works, but it is a bit clunky, unoptimized and has a few edge cases that I don't like.
23/25

But it will get the job done.

You should tinker with the variables and settings to see what works well with you, and always run these trades in a subaccount with balances you can afford to lose.
24/25

This is not investment advice. I'm not recommending these stocks, these variables or these systems. You could lose money following these exact steps.

People were asking me for an example of a balance for Quant Zone which still has his limits, so I whipped this up.
25/25

Quant zone is a powerful, but still beta tool that has its limits.

This script is likely too simple of a version to use without tweaking and monitoring.

I'm still working on more advanced ones with extra layers of logic. But hopefully this helps you get started!
You can follow @adamscochran.
Tip: mention @twtextapp on a Twitter thread with the keyword “unroll” to get a link to it.

Latest Threads Unrolled: