<?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[Multi-pass Backtesting]]></title><description><![CDATA[<p dir="auto">Hello !</p>
<p dir="auto">I'd like to rewrite this code for Multi-pass Backtesting to pass the competition filter.<br />
What should I do ?</p>
<pre><code>def pair_trading(data):
    pair = ['NAS:FWLT', 'NAS:PCAR']
    close = data.sel(field='close')
    price = close.sel(asset=pair).transpose('time', 'asset').fillna(0) #欠損値処理
    modelCoint = VECM(price.values, k_ar_diff=0, deterministic='na')
    res = modelCoint.fit()
    pairs_value = res.beta[0]*price.sel(asset=pair[0])+ res.beta[1]*price.sel(asset=pair[1]) #ポートフォリオ価値の作成
    diff = pairs_value.shift(time=-1) - pairs_value
    threshold = diff.std(dim='time')*2 #閾値の設定
    signal = np.sign(diff)
    
    weights = xr.zeros_like(close) #ポートフォリオウェイトの初期化

    for t in data.time:
        if (weights.sel(time=t)==[0,0]).any() and pairs_value.sel(time=t) &gt;= threshold:
            weights.loc[dict(time=t)] = [1,-1]
            
        if (weights.sel(time=t)==[0,0]).any() and pairs_value.sel(time=t) &lt;= -threshold:
            weights.loc[dict(time=t)] = [-1,1]
    
        if (weights.sel(time=t)==[1,-1]).any() and signal.sel(time=t) &lt; 0:
            weights.loc[dict(time=t)] = [0,0]
            
        if (weights.sel(time=t)==[-1,1]).any() and signal.sel(time=t) &gt;= 0:
            weights.loc[dict(time=t)] = [0,0]

    return weights
</code></pre>
<p dir="auto">Best regards</p>
]]></description><link>http://quantiacs.com/community/topic/415/multi-pass-backtesting</link><generator>RSS for Node</generator><lastBuildDate>Mon, 13 Jul 2026 18:42:36 GMT</lastBuildDate><atom:link href="http://quantiacs.com/community/topic/415.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 09 Aug 2023 05:55:27 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Multi-pass Backtesting on Thu, 10 Aug 2023 06:51:03 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="http://quantiacs.com/community/uid/602">@eddiee</a></p>
<p dir="auto">Hello.</p>
<p dir="auto">This code looks to the future.<br />
It is needed to train the model.<br />
Pay attention to the name of the variable.</p>
]]></description><link>http://quantiacs.com/community/post/1193</link><guid isPermaLink="true">http://quantiacs.com/community/post/1193</guid><dc:creator><![CDATA[Vyacheslav_B]]></dc:creator><pubDate>Thu, 10 Aug 2023 06:51:03 GMT</pubDate></item><item><title><![CDATA[Reply to Multi-pass Backtesting on Wed, 09 Aug 2023 15:18:29 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="http://quantiacs.com/community/uid/12">@support</a> is ".shift(time=-1)" really forward looking?<br />
In the Quantiacs Ridge Classifier example ".shift(time=-1)" is used, so I guess this operation is not forward looking. <img src="http://quantiacs.com/community/plugins/nodebb-plugin-emoji/emoji/android/1f642.png?v=o92lv7m3jt8" class="not-responsive emoji emoji-android emoji--slightly_smiling_face" title=":)" alt="🙂" /></p>
<pre><code>def get_target_classes(data):
    # define categorical targets
    price_current = data.sel(field="close").dropna("time") # rm NaN
    price_future = price_current.shift(time=-1).dropna("time")

    class_positive = 1
    class_negative = 0

    target_is_price_up = xr.where(price_future &gt; price_current, class_positive, class_negative)
    return target_is_price_up.to_pandas()</code></pre>
]]></description><link>http://quantiacs.com/community/post/1192</link><guid isPermaLink="true">http://quantiacs.com/community/post/1192</guid><dc:creator><![CDATA[EDDIEE]]></dc:creator><pubDate>Wed, 09 Aug 2023 15:18:29 GMT</pubDate></item><item><title><![CDATA[Reply to Multi-pass Backtesting on Wed, 09 Aug 2023 13:17:15 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="http://quantiacs.com/community/uid/2133">@cyan-gloom</a> Hi, before that, are you sure that your code is not looking forward? There is a shift with a negative value "-1" for the variable "diff", which in turns is used via "signal" for defining "weights". Naively, we would say that the code is looking into the future, correct?</p>
]]></description><link>http://quantiacs.com/community/post/1191</link><guid isPermaLink="true">http://quantiacs.com/community/post/1191</guid><dc:creator><![CDATA[support]]></dc:creator><pubDate>Wed, 09 Aug 2023 13:17:15 GMT</pubDate></item></channel></rss>