<?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[Strategy trades illiquid instruments]]></title><description><![CDATA[<p dir="auto">Hi, I am having problem Strategy trades illiquid instruments at latest date in log, while I have multiplied weight with liquid. I checked log only latest date has this error. Please help me. My stock universe is top 7 magnificent. <a class="plugin-mentions-user plugin-mentions-a" href="http://quantiacs.com/community/uid/12">@support</a> <a class="plugin-mentions-user plugin-mentions-a" href="http://quantiacs.com/community/uid/5">@Vyacheslav_B</a></p>
<p dir="auto">My alpha id is #18379797<br />
<img src="/community/assets/uploads/files/1746008208990-5f803660-59a2-48d7-b455-894bba89806a-image.png" alt="5f803660-59a2-48d7-b455-894bba89806a-image.png" class="img-responsive img-markdown" /><br />
<img src="/community/assets/uploads/files/1746008224789-493f87dd-887b-4c1d-8ecd-371e1fe8f382-image.png" alt="493f87dd-887b-4c1d-8ecd-371e1fe8f382-image.png" class="img-responsive img-markdown" /></p>
]]></description><link>http://quantiacs.com/community/topic/672/strategy-trades-illiquid-instruments</link><generator>RSS for Node</generator><lastBuildDate>Tue, 10 Mar 2026 09:32:22 GMT</lastBuildDate><atom:link href="http://quantiacs.com/community/topic/672.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 30 Apr 2025 10:18:22 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Strategy trades illiquid instruments on Thu, 05 Jun 2025 08:39:28 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="http://quantiacs.com/community/uid/2784">@illustrious-felice</a> Hello. The reason you're still seeing a large number of tickers (e.g., around 300) even after applying the filter is that the "best" instrument by Sharpe ratio changes over time. The <code>rank_assets_by</code> function returns a time-dependent mask, selecting the top N assets <strong>at each time step</strong>. So the total number of unique assets that were selected at <strong>any point in time</strong> may be much larger than <code>top_assets</code>.</p>
<p dir="auto">This is expected behavior.</p>
<p dir="auto">To illustrate this more clearly, let's consider a minimal working example that selects only <strong>1</strong> top asset at each point in time and shows all the intermediate steps:</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 qnt.filter as qnfilter
import xarray as xr
import pandas as pd

top_assets = 1

data = qndata.stocks.load_spx_data(min_date="2005-06-01")
weights = data.sel(field="is_liquid")

stats_per_asset = qnstats.calc_stat(data, weights, per_asset=True)
sharpe_ratio = stats_per_asset.sel(field="sharpe_ratio")
asset_filter = qnfilter.rank_assets_by(data, sharpe_ratio, top_assets, ascending=False)

weights = weights * asset_filter
stats = qnstats.calc_stat(data, weights.sel(time=slice("2005-06-01", None)))

display(asset_filter.to_pandas().tail())
display(stats.to_pandas().tail())
display(sharpe_ratio.to_pandas().tail())
display(weights.to_pandas().tail())
</code></pre>
<p dir="auto">If you want to see <strong>which asset was the best</strong> on specific dates, you can do something like this:</p>
<pre><code class="language-python">dates = ["2015-01-15", "2020-01-15", "2025-01-15"]
records = []

for date_str in dates:
    best_mask = asset_filter.sel(time=date_str)
    assets = best_mask.where(best_mask &gt; 0, drop=True).asset.values
    srs = sharpe_ratio.sel(time=date_str, asset=assets).values
    for a, s in zip(assets, srs):
        records.append({"time": date_str, "asset": a.item(), "sharpe_ratio": float(s)})

df = pd.DataFrame(records).set_index("time")
display(df)
</code></pre>
<pre><code>asset	sharpe_ratio
time		
2025-05-22	NYS:HRL	1.084683
2025-05-22	NAS:KDP	1.093528
2025-05-22	NAS:AAPL 0.968039
</code></pre>
<p dir="auto">Or simply for a single date:</p>
<pre><code class="language-python">date = "2020-05-22"
best_mask = asset_filter.sel(time=date)
best_assets = best_mask.where(best_mask &gt; 0, drop=True).asset
best_sr = sharpe_ratio.sel(time=date, asset=best_assets)
print(best_sr.to_pandas())
</code></pre>
<p dir="auto">This shows clearly that only one asset is selected at each time step, but over the full time range, many different assets can appear in the top list depending on how their Sharpe ratios change.</p>
]]></description><link>http://quantiacs.com/community/post/1969</link><guid isPermaLink="true">http://quantiacs.com/community/post/1969</guid><dc:creator><![CDATA[Vyacheslav_B]]></dc:creator><pubDate>Thu, 05 Jun 2025 08:39:28 GMT</pubDate></item><item><title><![CDATA[Reply to Strategy trades illiquid instruments on Wed, 28 May 2025 08:39:45 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="http://quantiacs.com/community/uid/12">@support</a> Thanks for the feedback. I would like to ask the following, for example if I want to filter out the 10 tickers with the best sharpe of the strategy, how should I do it, to avoid being filtered by hand?</p>
<p dir="auto">Please provide an example code</p>
<p dir="auto">def filter_sharpe_ratio(data, weights, top_assets):<br />
stats_per_asset = qnstats.calc_stat(data, weights, per_asset=True)<br />
sharpe_ratio = stats_per_asset.sel(field="sharpe_ratio")<br />
return qnfilter.rank_assets_by(data, sharpe_ratio, top_assets, ascending=False)</p>
<p dir="auto">asset_filter = filter_sharpe_ratio(data, weights, 150)<br />
weights = weights * asset_filter</p>
<p dir="auto">I used this code, but the result is still nearly 300 tickers.</p>
]]></description><link>http://quantiacs.com/community/post/1959</link><guid isPermaLink="true">http://quantiacs.com/community/post/1959</guid><dc:creator><![CDATA[illustrious.felice]]></dc:creator><pubDate>Wed, 28 May 2025 08:39:45 GMT</pubDate></item><item><title><![CDATA[Reply to Strategy trades illiquid instruments on Fri, 09 May 2025 09:24:23 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="http://quantiacs.com/community/uid/2784">@illustrious-felice</a> Hi,</p>
<p dir="auto">sorry for late answer, please check the correctness of dataset used for defining weights in strategy. Be sure that 'stocks_s&amp;p500' dataset is used and not 'stocks_nasdaq100' for current competition. To ensure strategy trades only liquid assets in certain time period, multiply the output from your strategy function with 'is_liquid' field from correct dataset, or simply use clean() function from qnt.output:</p>
<pre><code>import qnt.data as qndata
import qnt.output as qnout

def strategy(data):
    .....
    # liquid = data.sel(field='is_liquid')
    # weights = weights * liquid
    return weights


data = qndata.stocks_load_spx_data(min_date='2005-01-01')
weights = strategy(data)
weights = qnout.clean(weights, data, kind='stocks_s&amp;p500')

qnout.write(weights)
</code></pre>
<p dir="auto">Also, keep in mind that submission will not be eligible for contest if stocks universe (in this case  "top 7 magnificent") is hand picked (manually defined).</p>
<p dir="auto">Best regards,</p>
]]></description><link>http://quantiacs.com/community/post/1949</link><guid isPermaLink="true">http://quantiacs.com/community/post/1949</guid><dc:creator><![CDATA[support]]></dc:creator><pubDate>Fri, 09 May 2025 09:24:23 GMT</pubDate></item></channel></rss>