기사 목록으로
May 23, 2025
5분 소요

Portfolio Balancer: Hierarchical Investment Management System

portfolio management
investment system
hierarchical structure
asset management
automation

Imagine you have a complex investment management system where each asset lives in its own "home" — a wallet, and all these homes are organized into a clear hierarchical structure, much like a file system on a computer. This is exactly the approach we will explore.

System Architecture: Three Types of Entities

At the core of the system are three key concepts that function as building blocks:

Wallet — the simplest element that holds only one type of asset. Think of it as a bank vault cell containing only dollars or only bitcoins. No mixing — one wallet, one asset.

Asset — a specific coin, stock, or any other financial instrument. Bitcoin, Apple shares, US dollars — these are all assets.

Portfolio — akin to a folder in a file system, which can contain other folders (portfolios) or files (assets). A portfolio groups related items based on a specific principle.

Tree Structure: From General to Specific

The system organizes all assets into a tree with a clear hierarchy:

Root of the tree — this represents all your assets combined. Imagine it as the main folder "My Investments."

First level — assets are divided by users. If the system serves multiple individuals, each will have their own branch.

Second level — assets are grouped by exchanges. A single user might have assets on Binance, Coinbase, Sberbank, and so on.

Third level — accounts on a specific exchange. On one exchange, you might have a spot account, a futures account, a savings account.

Fourth level — grouping by sectors or strategies. For example, "Tech Stocks," "Cryptocurrencies," "Stablecoins" — like thematic folders.

Fifth level — specific wallets with assets. Here lie your Bitcoin, Ethereum, dollars.

Two System States: Reality and Dreams

The system operates with two parallel trees:

Real Portfolio Tree — this is what you currently own. The system retrieves this data directly from exchanges via API. 1.5 Bitcoin on Binance, 100 Apple shares in Sberbank, 5000 dollars on Coinbase — everything as it is.

Desired Portfolio Tree — this is your plan, expressed in percentages. You say: "I want 60% in stocks, 30% in cryptocurrencies, 10% in cash." The system then calculates the specific amounts.

Balancing Function: From Simple to Complex

The most basic balancing function works as a simple comparison of the two trees:

Diff-algorithm compares the real and desired states, identifies differences, and instructs: "Sell 0.3 Bitcoin, buy stocks for $15,000." It's like a calculator showing what needs to be done to achieve the goal.

However, the function can be much more complex. Advanced balancing considers not only what to buy and sell but also where to do it. It might suggest: "Transfer Bitcoin from Binance to Coinbase because the selling rate is better there" or "Withdraw dollars from the bank to the exchange to buy stocks."

Diff Tree: The Magic of Tree Comparison

Diff Tree is the resulting tree that shows the differences between the real and desired portfolio states. Think of it as an action plan where each node contains instructions on what needs to be done.

Each node in the diff tree contains information:

  • Current amount of the asset
  • Desired amount of the asset
  • Difference (how much to buy or sell)
  • Operation (buy/sell/hold)

For example, if you have 1 Bitcoin but need 0.7, the diff tree node for this asset will indicate: "Sell 0.3 Bitcoin." If you have 50% in stocks but need 60%, the system will show: "Buy stocks worth X dollars."

The diff tree construction algorithm works recursively — it first calculates differences at higher levels (portfolios), then drills down to specific assets. This allows understanding not only what to buy/sell but also in what sequence to do it.

The diff tree becomes the basis for executing balancing operations. The system first performs sell operations (freeing up funds), then buy operations (investing the freed funds into underweighted assets).

Virtual Trees: When Complex Logic is Needed

The most intriguing part of the system is the ability to create virtual trees for special tasks. Imagine you have an arbitrage bot that needs to maintain an equal amount of Litecoin on two different exchanges to exploit price differences.

Instead of a single wallet "LTC 100%," the system creates two separate wallets: "LTC 10%" and "LTC 90%." The arbitrage bot's virtual tree references the 10% wallet. The system marks this 10% as locked and specifies by whom — the arbitrage bot.

It's as if you could create virtual "envelopes" for different purposes in your banking app, while the money physically remains in one account.

Practical Application

Such a system solves real investor problems:

Automation of routine tasks — no need to manually calculate what to sell and buy. The system does all the calculations for you.

Control over complex strategies — you can simultaneously manage multiple trading bots, arbitrage strategies, and long-term investments.

Transparency — the entire asset structure is visible at a glance. It's clear where everything is and why.

Flexibility — you can easily change strategies, redistribute assets between exchanges, and add new instruments.

This system transforms chaotic management of numerous assets across different platforms into a structured, understandable process. It's like turning a messy closet into a neatly organized wardrobe system — but for investments.

Conclusion

Portfolio Balancer demonstrates how modern technologies can simplify complex investment processes. The system shows that portfolio management is not magic but a structured approach with clear algorithms and understandable logic.

You can view a demo of the system at: https://portfolio-balancer-tau.vercel.app/en

The project's source code is available on GitHub: https://github.com/suenot/portfolio-balancer

Citation

@software{soloviov2025portfoliobalancer,
  author = {Soloviov, Eugen},
  title = {Portfolio Balancer: Hierarchical Investment Management System},
  year = {2025},
  url = {https://marketmaker.cc/en/blog/post/portfolio-balancer},
  version = {0.1.0},
  description = {An overview of the Portfolio Balancer investment management system, which organizes assets into a hierarchical structure similar to a file system to simplify complex investment processes.}
}

MarketMaker.cc Team

퀀트 리서치 및 전략

Telegram에서 토론하기