TradingView strategy research

Market neutral strategy: dollar, beta and factor neutrality

A market neutral strategy seeks to limit exposure to specified market risks while taking long and short positions. Equal long and short dollars do not establish that neutrality: the two sides can respond differently to the market. A beta neutral portfolio offsets estimated market sensitivity; factor neutrality adds constraints for selected risks such as sectors or styles. Each claim needs a benchmark, an estimation date and a measured exposure. None eliminates losses.

See the decision guide

Specify the denominator and the risk model

For same-currency cash equities, let signed value v(i) = shares(i) × price(i), positive for a long and negative for a short. Gross exposure G = sum |v(i)| and net dollars D = sum v(i). Define weights w(i) = v(i) / G when G > 0. These gross-normalized weights do not sum to one, and G is neither account equity nor available buying power.

  • A single-market estimate is beta(i) = Cov(asset excess return, benchmark excess return) / Var(benchmark excess return). Use a stated return frequency, training window, benchmark and financing convention. Zero benchmark variance makes this estimate undefined.
  • For a multi-factor model, estimate the coefficients jointly: excess return(i) = alpha(i) + beta(i) × market factor + loading(i) × another factor + residual(i). A market coefficient from this joint regression need not equal the single-factor beta.
  • The examples below assume known coefficients in that joint linear model. Cvxportfolio documents dollar, market and factor constraints separately. Neutrality describes these selected exposures at a point in time; it does not establish a forecast of alpha.
ConstraintDollar equationInterpretation
Dollar neutralD = sum v(i) = 0Long market value equals absolute short market value.
Market beta neutralB = sum v(i) × beta(i) = 0Estimated response to one specified market return is zero.
Selected factors neutralF(k) = sum v(i) × loading(i,k) = 0 for every kOffsets the modeled exposure to each selected factor. Include market beta explicitly if it is required.

One four-asset book, three allocations

Assume four fictional USD stocks and a fixed $100,000 gross budget. A and B remain long; C and D remain short. The extra factor is a hypothetical sector shock that affects A and D with loading 1 and B and C with loading 0. All prices and coefficients are invented for arithmetic, not observations or recommended positions.

  • Dollar-only market exposure is 40,000 × 1.6 + 10,000 × 0.8 - 20,000 × 1.2 - 30,000 × 1.0 = $18,000. B/G = 0.18 means 18% of gross has the modeled sensitivity of a beta-one market position. It is not the portfolio beta relative to an unspecified equity balance.
  • For the middle column, fix both shorts at $25,000 and write the A long as x and the B long as 50,000 - x. The market constraint is 1.6x + 0.8(50,000 - x) - 1.2(25,000) - 25,000 = 0, so x = $18,750. The remaining sector exposure is 18,750 - 25,000 = -$6,250.
  • For the final column, sector neutrality requires A and D to have equal absolute values x. Dollar neutrality and gross $100,000 then give B and C values of 50,000 - x. The market equation becomes 1.6x + 0.8(50,000 - x) - 1.2(50,000 - x) - x = x - 20,000 = 0. Thus x = $20,000.
  • These are constrained examples, not an optimal portfolio. All three retain the same four names and trade directions, but different weights change concentration, expected returns and costs. A general optimizer also needs an explicit objective, gross limit, name limits and feasible borrow.
AssetPrice / market beta / sector loadingDollar-only valuesDollar + beta valuesDollar + beta + sector values
A$50 / 1.6 / 1+$40,000+$18,750+$20,000
B$100 / 0.8 / 0+$10,000+$31,250+$30,000
C$40 / 1.2 / 0-$20,000-$25,000-$30,000
D$80 / 1.0 / 1-$30,000-$25,000-$20,000
Net dollars Dsum signed values$0$0$0
Market exposure Bsum value × beta+$18,000$0$0
Sector exposure Fvalue(A) + value(D)+$10,000-$6,250$0

Zero net dollars can lose money in a market decline

Apply a hypothetical market factor return of -5% and sector factor return of +3%, with alpha and residual returns set to zero. The model gives gross P&L = B × (-0.05) + F × 0.03. This is a sensitivity calculation using starting exposures, not a historical backtest.

  • A separate residual stress sets both long returns to -2% and both short returns to +2%, with factor returns zero. Every column loses $2,000 because each has $50,000 on each side. Neutral factor exposures cannot remove this adverse selection risk.
  • If the final book was built with A beta 1.6 but its next-period market response is 1.9, actual B becomes $20,000 × 0.3 = $6,000. A -5% market move then contributes -$300 before costs. Estimated neutrality is only as accurate as the exposure model.
  • For market beta neutralization alone, unequal long and short dollars can also satisfy B = 0. Keeping D = 0 is a separate choice. A factor-neutral label is incomplete unless the required factors and tolerances are listed.
AllocationMarket contributionSector contributionCombined gross P&L
Dollar only-$900+$300-$600
Dollar + beta$0-$187.50-$187.50
Dollar + beta + sector$0$0$0 under this model

Rounding and price movement change the result

At the stated prices, the final allocation is +400 A, +300 B, -750 C and -250 D shares. Hold those shares fixed and let only A rise 5% to $52.50. Long value becomes $51,000, short value stays $50,000 and gross becomes $101,000. Net dollars are now $1,000; market exposure is $1,600 and sector exposure is $1,000, even if all loadings stay unchanged.

  • The normalized monitor outputs are D/G = 0.990099%, B/G = 1.584158% and F/G = 0.990099%. None is a return. Recompute exposures from actual holdings and current marks after every trade and corporate action.
  • The middle allocation requires fractional shares at these prices: +375 A, +312.5 B, -625 C and -312.5 D. Rounding B to +312 and D to -312 leaves D = -$10, B = $0 and F = -$6,210. Preserving one constraint by accident does not preserve the others.
  • If borrow on C disappears, removing it from the final book leaves $30,000 net long and $36,000 of market exposure. Solve the remaining constraints again or reduce positions under a declared risk policy; deleting a short is not a neutral adjustment.

A rebalance needs a trade and cost record

At unchanged example prices, moving from the middle allocation to the final allocation trades $1,250 of A, $1,250 of B, $5,000 of C and $5,000 of D in absolute value. Total traded notional is $12,500, or 12.5% of the fixed gross budget. At an assumed 5 basis points per traded dollar, that adjustment costs $6.25 before borrow and financing.

  • In a separate flat-price round-trip scenario, entry and liquidation trade $200,000 in total, costing $100 at the same allowance. A constant $50,000 short fee base at an illustrative 6% annual rate for ten calendar days on a 360-day basis costs $83.33. The flat-price loss is therefore $183.33 before other cash flows.
  • These rates are assumptions. Broker fee bases, daily borrow rates, collateral interest, debit financing and dividends can change the ledger. Record them separately; when fills already include slippage, do not deduct the same slippage again.
  • Choose tolerance bands and a review schedule before evaluation. For example, an absolute exposure ratio above 1% of gross can flag a review at a completed daily close. This arbitrary research threshold requests investigation, not an immediate fill or a safety guarantee.
  • A pending rebalance can leave unmatched legs. Test failed shorts, partial fills, widening spreads and borrow recalls. More frequent adjustment reduces some exposure drift but increases turnover and execution dependence.

Observe exposure drift in Pine Script

This Pine v6 indicator calculates signed current values from fixed shares and synchronized daily closes. It plots dollar, market and one additional factor exposure divided by current gross value. The symbol defaults are feed placeholders; the quantities and coefficients come from the fictional example and are not estimates for those ETFs. Enter your own holdings and coefficients saved before the evaluation period.

  • Use standard daily candles and compatible feeds in one currency with consistent adjustment settings. Missing or mismatched bar timestamps produce blank plots, and all-zero holdings produce blanks rather than division by zero. Matching timestamps alone cannot prove feed accuracy or executable quotes.
  • Create the alert from the indicator and select once per bar close. The condition stays true on every eligible close outside the band; it is a review flag, not a crossing-only event. Missing observations cannot generate a review flag, so check data health separately.
  • The example prices 50, 100, 40 and 80 produce all three exposures equal to zero. Changing A to 52.50 reproduces the drift ratios above. The listed ETF feeds will not reproduce those invented prices.
  • Editing holdings or coefficients recalculates the displayed history. Use a saved snapshot for each holding interval and preserve the rebalance ledger externally. This monitor does not provide historical holdings, rolling coefficient estimates or point-in-time factor data.
Indicator only: fixed holdings, frozen coefficients and a close-based review condition. It does not estimate factors, submit orders or backtest a multi-asset account.pine
//@version=6
indicator("Four-asset neutrality monitor", overlay = false)
string a = input.symbol("AMEX:SPY", "Asset A")
string b = input.symbol("NASDAQ:QQQ", "Asset B")
string c = input.symbol("AMEX:IWM", "Asset C")
string d = input.symbol("AMEX:DIA", "Asset D")
float qa = input.float(400, "A signed shares")
float qb = input.float(300, "B signed shares")
float qc = input.float(-750, "C signed shares")
float qd = input.float(-250, "D signed shares")
float ba = input.float(1.6, "A frozen market loading")
float bb = input.float(0.8, "B frozen market loading")
float bc = input.float(1.2, "C frozen market loading")
float bd = input.float(1.0, "D frozen market loading")
float fa = input.float(1, "A frozen extra-factor loading")
float fb = input.float(0, "B frozen extra-factor loading")
float fc = input.float(0, "C frozen extra-factor loading")
float fd = input.float(1, "D frozen extra-factor loading")
int start = input.time(timestamp("01 Jan 2026 00:00 +0000"), "Holdings effective from")
float limit = input.float(1.0, "Review band (% of gross)", minval = 0.0)
if not timeframe.isdaily or timeframe.multiplier != 1
    runtime.error("Use standard one-day candles with matching sessions.")
[pa, ta, ea] = request.security(a, "1D", [close, time, time_close], gaps = barmerge.gaps_on, lookahead = barmerge.lookahead_off)
[pb, tb, eb] = request.security(b, "1D", [close, time, time_close], gaps = barmerge.gaps_on, lookahead = barmerge.lookahead_off)
[pc, tc, ec] = request.security(c, "1D", [close, time, time_close], gaps = barmerge.gaps_on, lookahead = barmerge.lookahead_off)
[pd, td, ed] = request.security(d, "1D", [close, time, time_close], gaps = barmerge.gaps_on, lookahead = barmerge.lookahead_off)
bool prices = not na(pa) and not na(pb) and not na(pc) and not na(pd) and pa > 0 and pb > 0 and pc > 0 and pd > 0
bool aligned = ta == time and tb == time and tc == time and td == time and ea == time_close and eb == time_close and ec == time_close and ed == time_close
float va = qa * pa
float vb = qb * pb
float vc = qc * pc
float vd = qd * pd
float gross = math.abs(va) + math.abs(vb) + math.abs(vc) + math.abs(vd)
bool ready = prices and aligned and barstate.isconfirmed and time >= start and gross > 0
float dollars = ready ? 100 * (va + vb + vc + vd) / gross : na
float market = ready ? 100 * (va * ba + vb * bb + vc * bc + vd * bd) / gross : na
float factor = ready ? 100 * (va * fa + vb * fb + vc * fc + vd * fd) / gross : na
plot(dollars, "Net dollars / gross (%)", color = color.blue, style = plot.style_linebr)
plot(market, "Market exposure / gross (%)", color = color.orange, style = plot.style_linebr)
plot(factor, "Extra-factor exposure / gross (%)", color = color.purple, style = plot.style_linebr)
hline(0, "Zero", color = color.gray)
hline(limit, "Upper review band", color = color.gray)
hline(-limit, "Lower review band", color = color.gray)
bool review = ready and (math.abs(dollars) > limit or math.abs(market) > limit or math.abs(factor) > limit)
alertcondition(review, "Exposure review", "A frozen-model exposure exceeds its review band.")

Validate the portfolio beyond the chart

TradingView can request other symbols for calculations, but request.security does not create orders in those symbols. The strategy broker emulator uses chart data. A single-chart Strategy Tester report cannot supply the independent fills, borrow, cash flows and margin of this four-asset book. Keep the portfolio execution test in a separate simulator or reconciled ledger.

  • Save the universe, factor definitions, training endpoint, coefficients and allocation rule before the later evaluation period. Fit on past information only. Report exposure drift and net results across untouched periods, including failed models and infeasible rebalances.
  • Compare factor estimates across plausible training windows, then stress coefficient errors, idiosyncratic losses and execution costs. Low realized correlation in one sample does not prove stable market neutrality.
  • Pine Script AI Coding Agent can help draft the observable calculations and request syntax checks. Strategy Optimizer can compare supported inputs of a separate TradingView strategy after timing and costs are checked. The indicator here has no simulated trades for that optimizer to evaluate as a portfolio.
Where Pineify fits

Pine Script AI Coding Agent

Draft a holdings monitor from explicit exposure formulas, request syntax validation and inspect the output against a saved portfolio snapshot.

Also useful: Strategy Optimizer. Compare supported strategy input combinations after checking decision timing and cost assumptions. A multi-symbol indicator is not a portfolio backtest.

Draft an exposure monitor

Frequently asked questions

Educational research, not investment advice. All allocations, prices, coefficients, shocks and cost rates are hypothetical. No historical performance or suitable investment is established. Neutrality depends on the stated model and does not prevent losses. Syntax checking cannot establish financial validity.

Sources and verification

Published by Pineify. Pineify is an independent product and is not affiliated with TradingView. Sources support the technical explanations; examples do not establish trading performance.