<?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[Question about the Q17 Machine Learning Example Algo]]></title><description><![CDATA[<p dir="auto">Hi guys,<br />
I was just checking out the Q17 Machine Learning Algo (With Retraining). I don't know if it's just me, but I find the following strange:</p>
<ul>
<li>
<p dir="auto">The initial algorithm (has look ahead bias and what not) uses 54 different instruments during the backtest. As far as I can see, there is no "is liquid" filter anywhere, since this is just for educational purposes.</p>
</li>
<li>
<p dir="auto">When the ML algorithm is passed through the backtester, <strong>it only trades 8 instruments in the same timeframe</strong>.  What gives? Is there some parameter that is tuned when using the backtester instead of the whole data? Is this an error? I'd love to keep testing and exploring ML algorithms, but I think that the total number of traded instruments over 8 years should be more than 8, right?</p>
</li>
</ul>
<p dir="auto">Please let me know what changes I can make to the code, change the data, competition type, etc. in the backtester parameters, or if this is by design.</p>
<p dir="auto">Full data "test":<br />
<img src="https://cesarpadilla.xyz/wp-content/uploads/2022/02/Screenshot-2022-02-23-084445.png" alt="54 instruments" class="img-responsive img-markdown" /></p>
<p dir="auto">Backtester:<br />
<img src="https://cesarpadilla.xyz/wp-content/uploads/2022/02/Screenshot-2022-02-23-084512.png" alt="8 instruments" class="img-responsive img-markdown" /></p>
]]></description><link>http://quantiacs.com/community/topic/179/question-about-the-q17-machine-learning-example-algo</link><generator>RSS for Node</generator><lastBuildDate>Wed, 09 Sep 2026 12:49:49 GMT</lastBuildDate><atom:link href="http://quantiacs.com/community/topic/179.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 23 Feb 2022 14:54:04 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Question about the Q17 Machine Learning Example Algo on Wed, 02 Mar 2022 11:19:26 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="http://quantiacs.com/community/uid/256">@cespadilla</a> Hello.</p>
<p dir="auto">The reason is in "<em>train_model</em>" function.</p>
<pre><code class="language-python">def train_model(data):
    asset_name_all = data.coords['asset'].values
    features_all = get_features(data)
    target_all = get_target_classes(data)


    models = dict()

    for asset_name in asset_name_all:

        # drop missing values:
        target_cur = target_all.sel(asset=asset_name).dropna('time', 'any')
        features_cur = features_all.sel(asset=asset_name).dropna('time', 'any')
        
        
        target_for_learn_df, feature_for_learn_df = xr.align(target_cur, features_cur, join='inner')
        if len(features_cur.time) &lt; 10:
                continue
        model = get_model()
        try:
            model.fit(feature_for_learn_df.values, target_for_learn_df)
            models[asset_name] = model

                
        except:
            logging.exception('model training failed')

    return models
</code></pre>
<p dir="auto">If there are less than 10 features for training the model, then the model is not created (<em>if len(features_cur.time) &lt; 10</em>).</p>
<p dir="auto">This condition makes sense. I would not remove it.</p>
<p dir="auto">The second thing that can affect is the retraining interval of the model ("<em>retrain_interval</em>").</p>
<pre><code class="language-python">
weights = qnbt.backtest_ml(
    train=train_model,
    predict=predict_weights,
    train_period=2 *365,  # the data length for training in calendar days
    retrain_interval=10 *365,  # how often we have to retrain models (calendar days)
    retrain_interval_after_submit=1,  # how often retrain models after submission during evaluation (calendar days)
    predict_each_day=False,  # Is it necessary to call prediction for every day during backtesting?
    # Set it to true if you suspect that get_features is looking forward.
    competition_type='crypto_daily_long_short',  # competition type
    lookback_period=365,  # how many calendar days are needed by the predict function to generate the output
    start_date='2014-01-01',  # backtest start date
    analyze = True,
    build_plots=True  # do you need the chart?
)
</code></pre>
]]></description><link>http://quantiacs.com/community/post/625</link><guid isPermaLink="true">http://quantiacs.com/community/post/625</guid><dc:creator><![CDATA[Vyacheslav_B]]></dc:creator><pubDate>Wed, 02 Mar 2022 11:19:26 GMT</pubDate></item><item><title><![CDATA[Reply to Question about the Q17 Machine Learning Example Algo on Mon, 28 Feb 2022 14:51:41 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="http://quantiacs.com/community/uid/256">@cespadilla</a> Hi, sorry for late answer, we are checking and will let you know soon.</p>
]]></description><link>http://quantiacs.com/community/post/624</link><guid isPermaLink="true">http://quantiacs.com/community/post/624</guid><dc:creator><![CDATA[support]]></dc:creator><pubDate>Mon, 28 Feb 2022 14:51:41 GMT</pubDate></item></channel></rss>