Results
Portfolio Margin Plots
Introduction
The portfolio margin chart is a stacked area chart where each color represents the proportion of your available margin that a security consumes over time.
Margin plots can appear counter intuitive and hard to understand. To simplify things, this chart only draws the top 5-10 holdings at a given point in time. It group the smaller holdings into an area called "Others".
Cash vs Margin
When you trade with a margin account, orders consume your cash before borrowing anything on margin. This order of precedence minimizes the interest charges on your margin loans.
This algorithm produces the following portfolio margin plot. When the initial trades fill, the orders consume available cash before borrowing anything available from the margin. Consuming available cash first avoids interest charges on the margin-loan and avoids margin calls during market downturns. This results in a relatively steady line hovering on 50% as there is no free cash to purchase with, but only the remaining 50% margin.
This algorithm is the same buy-and-hold strategy as the previous algorithm, but it only targets 50% exposure during the initial trades. The following portfolio margin plot shows the results. This version only consumes 16% of the available margin for each security, leaving a substantial amount of cash free. As the portfolio value grows, the fraction of the margin that this cash represents shrinks, showing an upward trending plot as the holdings of AAPL grow in value.
Examples
The following examples provide insight into portfolio margin calculations and show the functionality of the portfolio margin chart.
Buying Put Options
This algorithm demonstrates that when you buy a put Option contract and you long the underlying asset, it reduces the margin used by the underlying asset. In the following image, the gray area represents the underlying Equity and the blue area represents the put Option contract. The algorithm buys SPY on 10/07/2013, buys the put Option contract on 01/02/2014, and then exercises the contract on 06/21/2014.
Buying Options Spreads
This algorithm demonstrates that when you long and short two Option contracts at the same time, they combine together to reduce your margin usage. In the following image, the blue area represents a short position in a call Option contract and the gray area represents a long position in a call Option contract. The algorithm forms a bear call spread one leg at a time, shorting an in-the-money contract on 02/03/2023 and then longing an out-of-the-money contract on 02/14/2023.
Buying Futures
This algorithm demonstrates that Futures have a fixed, USD-denominated margin requirement. In the following image, the blue area represents the percentage of the available margin that the Futures contract uses. The algorithm buys the contract on 10/02/2023 and holds it until the end of the backtest. As the total portfolio value decreases during the last two week in the backtest, the amount of available margin in the portfolio decreases. However, the USD amount of margin used by the Futures contract is constant, so the proportion of portfolio margin used by the contract increases at the same time.
Buying Forex
This algorithm demonstrates how the 50x leverage available for Forex impacts the portfolio margin chart. In the following image, the blue area represents the percentage of the available margin that the Forex position uses. The algorithm buys 500% exposure to the EURUSD pair on 01/02/2018 and holds it until the end of the backtest. The portfolio margin chart shows that only 10% of the available margin is used to enter the trade since 500% / 50 = 10%.
Series Color Changes
The portfolio margin plot updates daily as the backtest runs. However, the color of a specific security in the plot isn't finalized until the end of the backtest. For instance, the following image shows an example plot during execution:
The following image shows what the plot looks like at the end of the backtest:
Series Names
The series names in the chart are the last known tickers for the respective assets (for example, SPY and XLE). Therefore, if you trade multiple assets throughout a backtest that share the same last known ticker (for example, FB in 1998 and FB in 2014), the chart labels them under the same series name.