<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[ERROR! The max exposure is too high]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="http://quantiacs.com/community/uid/12">@support</a><br />
After I tested my strategy,<br />
I got the warnings below:<br />
<img src="/community/assets/uploads/files/1748793387491-%E8%9E%A2%E5%B9%95%E6%93%B7%E5%8F%96%E7%95%AB%E9%9D%A2-2025-06-01-234009.png" alt="螢幕擷取畫面 2025-06-01 234009.png" class="img-responsive img-markdown" /><br />
It stated that:</p>
<ol>
<li>WARNING! The kind of the data and the output are different.<br />
The kind of the data is None and the kind of the output is stocks_s&amp;p500<br />
The output will be cleaned with the data kind.</li>
<li>ERROR! The max exposure is too high.<br />
Max exposure: [0.05555556 0.05555556 0.05555556 ... 0.05882353 0.05882353 0.05882353] Hard limit: 0.1<br />
Use qnt.output.cut_big_positions() or normalize_by_max_exposure() to fix.</li>
</ol>
<p dir="auto">Do I need to fix the exposure? Exposure of 0.0588 is below the hard limit 0.1, so it seems that I don't need to decrease the current weights. Am I correct?</p>
<p dir="auto">BTW, can I just ignore the warning " WARNING! The kind of the data and the output are different." ?<br />
I don't know what should I fix according to this warning.</p>
]]></description><link>http://quantiacs.com/community/topic/698/error-the-max-exposure-is-too-high</link><generator>RSS for Node</generator><lastBuildDate>Tue, 10 Mar 2026 09:30:15 GMT</lastBuildDate><atom:link href="http://quantiacs.com/community/topic/698.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 01 Jun 2025 15:59:21 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to ERROR! The max exposure is too high on Mon, 16 Jun 2025 07:34:21 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="http://quantiacs.com/community/uid/20">@antinomy</a><br />
Hi! Don’t worry about leverage — it isn’t allowed on the Quantiacs platform: all user-supplied weights are automatically normalized when your strategy is saved. Here’s how that works with two instruments.<br />
Source code of the normalize function <a href="https://github.com/quantiacs/toolbox/blob/main/qnt/output.py:" rel="nofollow ugc">https://github.com/quantiacs/toolbox/blob/main/qnt/output.py:</a></p>
<pre><code class="language-python">def normalize(output, per_asset=False):
    from qnt.data.common import ds
    output = output.where(np.isfinite(output)).fillna(0)
    if ds.TIME in output.dims:
        output = output.transpose(ds.TIME, ds.ASSET)
        output = output.loc[
            np.sort(output.coords[ds.TIME].values),
            np.sort(output.coords[ds.ASSET].values)
        ]
    if per_asset:
        output = xr.where(output &gt; 1, 1, output)
        output = xr.where(output &lt; -1, -1, output)
    else:
        s = abs(output).sum(ds.ASSET)
        if ds.TIME in output.dims:
            s[s &lt; 1] = 1
        else:
            s = 1 if s &lt; 1 else s
        output = output / s
    try:
        output = output.drop_vars(ds.FIELD)
    except ValueError:
        pass
    return output
</code></pre>
<p dir="auto">Example with two assets</p>
<pre><code class="language-python">import xarray as xr
from qnt.data.common import ds
from qnt.output import normalize

times  = ['2025-06-16']
assets = ['Asset1', 'Asset2']

out1 = xr.DataArray(&lsqb;&lsqb;1.5, 0.5&rsqb;&rsqb;,
                    coords={ds.TIME: times, ds.ASSET: assets},
                    dims=[ds.TIME, ds.ASSET])
print(normalize(out1).values)

out2 = xr.DataArray(&lsqb;&lsqb;0.3, -0.2&rsqb;&rsqb;,
                    coords={ds.TIME: times, ds.ASSET: assets},
                    dims=[ds.TIME, ds.ASSET])
print(normalize(out2).values)
</code></pre>
<p dir="auto">Console output</p>
<pre><code class="language-python">&lsqb;&lsqb;0.75 0.25&rsqb;&rsqb;
&lsqb;&lsqb; 0.3  -0.2 &rsqb;&rsqb;
</code></pre>
<p dir="auto"><strong>Example 1:</strong> The absolute exposure is 2 &gt; 1, so every weight is divided by 2, yielding 0.75 and 0.25.</p>
<p dir="auto"><strong>Example 2:</strong> The exposure is 0.5 &lt; 1, so the scaling factor is set to 1 and the weights stay 0.3 and –0.2.</p>
<p dir="auto">In short, even if your strategy outputs more than 100 % exposure, <code>normalize</code> always scales it back so the total absolute exposure never exceeds 1—preventing leverage on the Quantiacs platform.</p>
]]></description><link>http://quantiacs.com/community/post/1978</link><guid isPermaLink="true">http://quantiacs.com/community/post/1978</guid><dc:creator><![CDATA[Vyacheslav_B]]></dc:creator><pubDate>Mon, 16 Jun 2025 07:34:21 GMT</pubDate></item><item><title><![CDATA[Reply to ERROR! The max exposure is too high on Fri, 13 Jun 2025 14:14:42 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="http://quantiacs.com/community/uid/5">@vyacheslav_b</a> Hi, I agree that diversification is always a good idea for trading. It might be helpful if there was an additional function like <code>check_diversification</code> whith a parameter for the minimum number of assets you want to trade. But this function should only warn you and not fix an undiversified portfolio, because the only way would be to add more assets to trade and asset selection should be done by the strategy itself in my opinion.</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="http://quantiacs.com/community/uid/12">@support</a> Hi, I just checked out <code>qnt 0.0.504</code> and the problem I mentioned seems to be fixed now, thanks!<br />
Would you perhaps consider to add a leverage check to the <code>check</code> function?<br />
Because one might think "qnout.check says everything is OK, so I have a valid portfolio" while actually having vastly overleveraged like in my 2nd example where <code>weights.sum('asset').values.max()</code> is <code>505.0</code>.<br />
Adding something like this to <code>check</code> would tell us about it:</p>
<pre><code>log_info("Check max portfolio leverage...")
max_leverage = abs(output).sum(ds.ASSET).values.max()
if max_leverage &gt; 1 + 1e-13: # (give some leeway for rounding errors and such)
    log_err("ERROR! The max portfolio leverage is too high.")
    log_err(f"Max leverage: {max_leverage} Limit: 1.0")
    log_err("Use qnt.output.clean() or normalize() to fix.")
else:
    log_info("Ok.")

</code></pre>
]]></description><link>http://quantiacs.com/community/post/1977</link><guid isPermaLink="true">http://quantiacs.com/community/post/1977</guid><dc:creator><![CDATA[antinomy]]></dc:creator><pubDate>Fri, 13 Jun 2025 14:14:42 GMT</pubDate></item><item><title><![CDATA[Reply to ERROR! The max exposure is too high on Mon, 09 Jun 2025 07:14:55 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="http://quantiacs.com/community/uid/20">@antinomy</a> Hello. If you look at how the function works, it limits exposure based on the invested capital, not the total capital — which is stricter than what's stated in the rules. However, in my opinion, this approach has advantages: strategies end up being more diversified, and you won’t be able to trade with just a few assets.</p>
]]></description><link>http://quantiacs.com/community/post/1975</link><guid isPermaLink="true">http://quantiacs.com/community/post/1975</guid><dc:creator><![CDATA[Vyacheslav_B]]></dc:creator><pubDate>Mon, 09 Jun 2025 07:14:55 GMT</pubDate></item><item><title><![CDATA[Reply to ERROR! The max exposure is too high on Fri, 06 Jun 2025 08:14:47 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="http://quantiacs.com/community/uid/878">@omohyoid</a> Hi.</p>
<p dir="auto">I don’t quite understand why you’re calculating the next trading date manually. According to the documentation and this <a href="https://github.com/quantiacs/strategy-q22-spx-platform-guide/blob/master/strategy.ipynb" rel="nofollow ugc">official example</a>, it works like this:</p>
<blockquote>
<p dir="auto"><strong>Strategy. Weights allocation</strong><br />
Every day, the algorithm determines how much of each asset should be in the portfolio for the next trading day.<br />
These are called the portfolio weights.<br />
A positive weight means you'll be buying that asset, while a negative weight means you'll be selling it.<br />
These decisions are made at the end of each day and put into effect at the beginning of the next trading day.</p>
</blockquote>
<p dir="auto">There’s a clear visual example in the notebook showing how this works. So there’s no need to manually add or compute the next date — the platform takes care of that automatically.</p>
<p dir="auto">As for the max weights — I didn’t quite understand what the issue is. If you look at the source code of a function like <code>cut_big_positions</code>, you’ll see something like this:</p>
<pre><code class="language-python">weights_1 = xr.where(abs(weights) &gt; 0.05, np.sign(weights) * 0.05, weights)
</code></pre>
<p dir="auto">This simply limits all weights that are greater than ±0.05 to exactly ±0.05. So if you’re seeing a value like 0.05882353, it’s likely either before this restriction is applied, or maybe you're looking at a version of the weights before post-processing.</p>
]]></description><link>http://quantiacs.com/community/post/1974</link><guid isPermaLink="true">http://quantiacs.com/community/post/1974</guid><dc:creator><![CDATA[Vyacheslav_B]]></dc:creator><pubDate>Fri, 06 Jun 2025 08:14:47 GMT</pubDate></item><item><title><![CDATA[Reply to ERROR! The max exposure is too high on Thu, 05 Jun 2025 16:38:37 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="http://quantiacs.com/community/uid/20">@antinomy</a> Hi,</p>
<p dir="auto">You are absolutely correct, we will fix check() function ASAP. It should only cut weights which exceed 0.1 allocation by asset, and normalize the sum of allocation to maximum 1, on every timestamp. If sum was &lt; 1, and weight of an asset &lt; 0.1, the output remains the same.<br />
Thanks a lot for pointing this out with examples.</p>
]]></description><link>http://quantiacs.com/community/post/1973</link><guid isPermaLink="true">http://quantiacs.com/community/post/1973</guid><dc:creator><![CDATA[support]]></dc:creator><pubDate>Thu, 05 Jun 2025 16:38:37 GMT</pubDate></item><item><title><![CDATA[Reply to ERROR! The max exposure is too high on Thu, 05 Jun 2025 16:29:06 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="http://quantiacs.com/community/uid/12">@support</a>,<br />
Either something about the exposure calculation is wrong or I really need clarification on the rules. About the position limit I only find rule 7. o. in the contest rules which states "The evaluation system limits the maximum position size for a single financial instrument to 10%"</p>
<p dir="auto">I always assumed this would mean the maximum weight for an asset would be 0.1 meaning 10 % of the portfolio. However the exposure calculation suggests the following:<br />
Either we trade no asset or at least 10 assets per trading day, regardless of the actual weights assigned to each asset.</p>
<p dir="auto">Consider this example:</p>
<pre><code>import qnt.data as qndata
import qnt.output as qnout
from qnt.filter import filter_sharpe_ratio


data = qndata.stocks.load_spx_data(min_date="2005-01-01")

weights = data.sel(field='is_liquid').fillna(0)
weights *= filter_sharpe_ratio(data, weights, 3) * .01 # assign 1 % to each asset using the top 3 assets by sharpe

qnout.check(weights, data, "stocks_s&amp;p500")
</code></pre>
<p dir="auto">which results in an exposure error:</p>
<pre><code>Check max exposure for index stocks (nasdaq100, s&amp;p500)…
ERROR! The max exposure is too high.
Max exposure: [0.         0.         0.         ... 0.33333333 0.33333333 0.33333333] Hard limit: 0.1
Use qnt.output.cut_big_positions() or normalize_by_max_exposure() to fix.
</code></pre>
<p dir="auto">even though the maximum weight per asset is only 0.01</p>
<pre><code>abs(weights).values.max()
0.01
</code></pre>
<p dir="auto">(By the way, the 4 functions mentioned by <a class="plugin-mentions-user plugin-mentions-a" href="http://quantiacs.com/community/uid/5">@Vyacheslav_B</a> also result in weights which dont't pass the exposure check when used with this example, except <code>drop_bad_days</code> which results in empty weights.)</p>
<p dir="auto">And if we assign 100 % to every liquid asset, the exposure check passes:</p>
<pre><code>weights = data.sel(field='is_liquid').fillna(0)
qnout.check(weights, data, "stocks_s&amp;p500")
</code></pre>
<pre><code>Check max exposure for index stocks (nasdaq100, s&amp;p500)…
Ok.
</code></pre>
<p dir="auto">So, does rule 7. o. mean we have to trade at least 10 assets or none at all each trading day to satisfy the exposure check?</p>
]]></description><link>http://quantiacs.com/community/post/1971</link><guid isPermaLink="true">http://quantiacs.com/community/post/1971</guid><dc:creator><![CDATA[antinomy]]></dc:creator><pubDate>Thu, 05 Jun 2025 16:29:06 GMT</pubDate></item><item><title><![CDATA[Reply to ERROR! The max exposure is too high on Wed, 04 Jun 2025 16:30:25 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="http://quantiacs.com/community/uid/5">@vyacheslav_b</a> Thanks for ur help!</p>
<ol>
<li>I checked my code, and I found that I loaded the data by using load_spx_data() instead of load_ndx_data()<br />
But I added the next trading date to the original data in order to write the latest weight. Does this operation cause the warning?</li>
<li>I checked the dataframe of the final weights, and I use the MAX() and the MIN() in excel to check the maximum and the minimum value of the weights, the maximum weight is 0.05, and the minimum weight is -0.05, which is different from the value 0.05882353 showing on the screen.<br />
<img src="/community/assets/uploads/files/1749054102017-%E8%9E%A2%E5%B9%95%E6%93%B7%E5%8F%96%E7%95%AB%E9%9D%A2-2025-06-05-001256.png" alt="螢幕擷取畫面 2025-06-05 001256.png" class="img-responsive img-markdown" /></li>
</ol>
]]></description><link>http://quantiacs.com/community/post/1968</link><guid isPermaLink="true">http://quantiacs.com/community/post/1968</guid><dc:creator><![CDATA[omohyoid]]></dc:creator><pubDate>Wed, 04 Jun 2025 16:30:25 GMT</pubDate></item><item><title><![CDATA[Reply to ERROR! The max exposure is too high on Tue, 03 Jun 2025 09:03:21 GMT]]></title><description><![CDATA[<p dir="auto">This script provides valuable insights into portfolio optimization, especially for managing exposure limits. Thank you for sharing!  To address the max exposure error, consider adjusting the optimization parameters, reducing position sizes, or exploring alternative asset allocation strategies. qnt.output.cut_big_positions() is a good suggestion, and perhaps also tweaking risk tolerance settings.</p>
]]></description><link>http://quantiacs.com/community/post/1965</link><guid isPermaLink="true">http://quantiacs.com/community/post/1965</guid><dc:creator><![CDATA[MaryVelez]]></dc:creator><pubDate>Tue, 03 Jun 2025 09:03:21 GMT</pubDate></item><item><title><![CDATA[Reply to ERROR! The max exposure is too high on Mon, 02 Jun 2025 08:43:27 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="http://quantiacs.com/community/uid/878">@omohyoid</a> Hello.</p>
<h4>1. <strong>Check which dataset you're loading</strong></h4>
<p dir="auto">You might have loaded <code>stocks_nasdaq100</code>, but are checking it as if it were <code>stocks_s&amp;p500</code>.</p>
<p dir="auto"><strong>Incorrect:</strong></p>
<pre><code class="language-python">import qnt.data as qndata
import qnt.ta as qnta
import qnt.stats as qnstats
import qnt.output as qnout
import xarray as xr

data = qndata.stocks.load_ndx_data(min_date="2005-06-01")
qnout.check(weights, data, kind="stocks_s&amp;p500")
</code></pre>
<p dir="auto"><strong>Correct:</strong></p>
<pre><code class="language-python">data = qndata.stocks.load_spx_data(min_date="2005-06-01")
qnout.check(weights, data, kind="stocks_s&amp;p500")
</code></pre>
<blockquote>
<p dir="auto"><img src="http://quantiacs.com/community/plugins/nodebb-plugin-emoji/emoji/android/26a0.png?v=933r2hptiik" class="not-responsive emoji emoji-android emoji--warning" title=":warning:" alt="⚠" />️ <code>kind</code> must match the actual dataset being used, otherwise some checks (e.g., liquidity or available dates) will not behave correctly.</p>
</blockquote>
<hr />
<h4>2. <strong>Handling Exposure</strong></h4>
<p dir="auto">If your exposure does exceed the limit on some days, you can fix it using one of the following methods (see the <a href="https://quantiacs.com/documentation/en/user_guide/dynamic_assets_selection.html" rel="nofollow ugc">documentation — Applying Exposure Filters</a>:</p>
<pre><code class="language-python">import qnt.output as qnout
import qnt.exposure as qnexp

weights_1 = qnexp.cut_big_positions(weights=weights, max_weight=0.049)
weights_2 = qnexp.drop_bad_days(weights=weights, max_weight=0.049)
weights_3 = qnexp.normalize_by_max_exposure(weights, max_exposure=0.049)
weights_4 = qnout.clean(weights, data, "stocks_s&amp;p500")
</code></pre>
<hr />
<h4>3. <strong>Use <code>clean()</code> instead of <code>check()</code> for auto-correction</strong></h4>
<p dir="auto">If you want the system to automatically fix issues like exposure or normalization, replace <code>check()</code> with <code>clean()</code>:</p>
<pre><code class="language-python">import qnt.output as qnout
weights = qnout.clean(weights, data, "stocks_s&amp;p500")
</code></pre>
<p dir="auto"><strong>Exposure of 0.0588 is below the hard limit of 0.1</strong>, so in this particular case, it does <em>not</em> violate any constraints. The error may have been triggered by other days or higher values elsewhere in the data — it's worth double-checking.</p>
]]></description><link>http://quantiacs.com/community/post/1964</link><guid isPermaLink="true">http://quantiacs.com/community/post/1964</guid><dc:creator><![CDATA[Vyacheslav_B]]></dc:creator><pubDate>Mon, 02 Jun 2025 08:43:27 GMT</pubDate></item></channel></rss>