<?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[Backtesting]]></title><description><![CDATA[<p dir="auto"><img src="/community/assets/uploads/files/1679838139759-bildschirmfoto-2023-03-26-um-15.39.29-resized.png" alt="Bildschirmfoto 2023-03-26 um 15.39.29.png" class="img-responsive img-markdown" /></p>
<p dir="auto">Hello,<br />
I have a question regarding my strategy. I defined a trading strategy and in [10] for each Asset listed in the Nasdaq, applied that strategy for the close values for a given time period.<br />
The signals of each asset are saved in a pandas dataframe with datetime index, which are the saved in a dictionary.<br />
Now it is not clear to me, from the examples given on the page, how to pass this into the qnt backtest.<br />
I will be thankful, if anyone can help me out on this. Thx</p>
]]></description><link>http://quantiacs.com/community/topic/372/backtesting</link><generator>RSS for Node</generator><lastBuildDate>Fri, 13 Mar 2026 12:09:39 GMT</lastBuildDate><atom:link href="http://quantiacs.com/community/topic/372.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 26 Mar 2023 13:57:11 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Backtesting on Sat, 01 Apr 2023 17:51:09 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="http://quantiacs.com/community/uid/229">@stefanm</a> Thank you!</p>
]]></description><link>http://quantiacs.com/community/post/1090</link><guid isPermaLink="true">http://quantiacs.com/community/post/1090</guid><dc:creator><![CDATA[support]]></dc:creator><pubDate>Sat, 01 Apr 2023 17:51:09 GMT</pubDate></item><item><title><![CDATA[Reply to Backtesting on Thu, 30 Mar 2023 00:22:19 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="http://quantiacs.com/community/uid/229">@stefanm</a> Finally worked. For whatever reason I had to write the trade library and the loop outside the strategy function, as the output was otherwise empty. (Tried all sorts of spacing to get it inside the stratety function but didnt work). Good luck with your strategy if you are taking part in the contest too! <img src="http://quantiacs.com/community/plugins/nodebb-plugin-emoji/emoji/android/1f642.png?v=933r2hptiik" class="not-responsive emoji emoji-android emoji--slightly_smiling_face" title=":)" alt="🙂" /> <img src="/community/assets/uploads/files/1680135400758-bildschirmfoto-2023-03-30-um-02.14.55-resized.png" alt="Bildschirmfoto 2023-03-30 um 02.14.55.png" class="img-responsive img-markdown" /></p>
]]></description><link>http://quantiacs.com/community/post/1072</link><guid isPermaLink="true">http://quantiacs.com/community/post/1072</guid><dc:creator><![CDATA[magenta.kabuto]]></dc:creator><pubDate>Thu, 30 Mar 2023 00:22:19 GMT</pubDate></item><item><title><![CDATA[Reply to Backtesting on Wed, 29 Mar 2023 19:19:46 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="http://quantiacs.com/community/uid/1799">@magenta-kabuto</a> No problem, you're welcome. Can you please change the start_date to '2006-01-01' when running backtester, and let us know if it worked?</p>
]]></description><link>http://quantiacs.com/community/post/1071</link><guid isPermaLink="true">http://quantiacs.com/community/post/1071</guid><dc:creator><![CDATA[stefanm]]></dc:creator><pubDate>Wed, 29 Mar 2023 19:19:46 GMT</pubDate></item><item><title><![CDATA[Reply to Backtesting on Wed, 29 Mar 2023 18:44:11 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="http://quantiacs.com/community/uid/229">@stefanm</a> I cant thank you enough. A very elegant way. The backtest atleast gets started but after approx. 20 seconds: the following occurs:<br />
Sry for being so annoying, the conversion is an extreme blindspot to me and if it takes too much time, pls focus on your strategy instead of mine<img src="/community/assets/uploads/files/1680115424489-bildschirmfoto-2023-03-29-um-20.42.45-resized.png" alt="Bildschirmfoto 2023-03-29 um 20.42.45.png" class="img-responsive img-markdown" /> <img src="/community/assets/uploads/files/1680115409973-bildschirmfoto-2023-03-29-um-20.42.50-resized.png" alt="Bildschirmfoto 2023-03-29 um 20.42.50.png" class="img-responsive img-markdown" /></p>
]]></description><link>http://quantiacs.com/community/post/1070</link><guid isPermaLink="true">http://quantiacs.com/community/post/1070</guid><dc:creator><![CDATA[magenta.kabuto]]></dc:creator><pubDate>Wed, 29 Mar 2023 18:44:11 GMT</pubDate></item><item><title><![CDATA[Reply to Backtesting on Wed, 29 Mar 2023 17:10:57 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="http://quantiacs.com/community/uid/1799">@magenta-kabuto</a> Hi, yes that's right, it seems that xarray DataArray is passed to function which expects pandas DataFrame (your entire algorithm is not visible, which is ok, so this is an assumption), but maybe you can try with this:</p>
<pre><code>### use your regime_trade(Stockdata, param_2=0.15) as helper function


def strategy(data):
# param data: the data returned from load_data function, xarray.DataArray structure. 
    Stockdata = ... # prepare data for regime_trade input, like you did for single pass
    trades = {}
    for j in logopenmod.keys():
        trades[j] = regime_trade(Stockdata[j].iloc[:,3], 0.15)
    pd_signals = pd.concat(trades.values(), axis=1)
    xr_signals = xr.DataArray(pd_signals, dims=('time', 'asset'))
    is_liquid = data.sel(field="is_liquid") # assume that "stocks" is exactly the same as data is
    return xr_signals * is_liquid
    
</code></pre>
<p dir="auto">Try it with Multi-pass, and change the name in competition_type. Set the start date as below:</p>
<pre><code>weights = qnbk.backtest(
  competition_type = "stocks_nasdaq100",
  load_data = load_data, # if omitted it loads data by competition_type
  lookback_period = 365,
  start_date = "2006-01-01", # set start_date 
  strategy = strategy,
  analyze = True,
)
</code></pre>
<p dir="auto">Regards</p>
]]></description><link>http://quantiacs.com/community/post/1069</link><guid isPermaLink="true">http://quantiacs.com/community/post/1069</guid><dc:creator><![CDATA[stefanm]]></dc:creator><pubDate>Wed, 29 Mar 2023 17:10:57 GMT</pubDate></item><item><title><![CDATA[Reply to Backtesting on Wed, 29 Mar 2023 15:51:24 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="http://quantiacs.com/community/uid/1799">@magenta-kabuto</a> And what is the exact competition name ? <img src="http://quantiacs.com/community/plugins/nodebb-plugin-emoji/emoji/android/1f605.png?v=933r2hptiik" class="not-responsive emoji emoji-android emoji--sweat_smile" title=":sweat_smile:" alt="😅" /></p>
]]></description><link>http://quantiacs.com/community/post/1068</link><guid isPermaLink="true">http://quantiacs.com/community/post/1068</guid><dc:creator><![CDATA[magenta.kabuto]]></dc:creator><pubDate>Wed, 29 Mar 2023 15:51:24 GMT</pubDate></item><item><title><![CDATA[Reply to Backtesting on Wed, 29 Mar 2023 15:47:59 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="http://quantiacs.com/community/uid/1799">@magenta-kabuto</a> <img src="/community/assets/uploads/files/1680104514265-bildschirmfoto-2023-03-29-um-17.33.56-resized.png" alt="Bildschirmfoto 2023-03-29 um 17.33.56.png" class="img-responsive img-markdown" /> <img src="/community/assets/uploads/files/1680104508631-bildschirmfoto-2023-03-29-um-17.32.54-resized.png" alt="Bildschirmfoto 2023-03-29 um 17.32.54.png" class="img-responsive img-markdown" /><br />
First of all thx again for the help. Single-Pass Backtesting works fine and I am pretty happy with the result. Multiple-Pass Backtesting however returns the error shown in the screenshot. I assume that this problem occurs because load data, an xArray DataArray is passed into the function that inputs pandas. IS this right ?And if yes, can I avoid it without having to rewrite the algo or can I skip Multiple-Pass backtest as my algo doesnt look into the future? Very grateful, if anyone can help. Regards</p>
]]></description><link>http://quantiacs.com/community/post/1067</link><guid isPermaLink="true">http://quantiacs.com/community/post/1067</guid><dc:creator><![CDATA[magenta.kabuto]]></dc:creator><pubDate>Wed, 29 Mar 2023 15:47:59 GMT</pubDate></item><item><title><![CDATA[Reply to Backtesting on Wed, 29 Mar 2023 14:26:38 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="http://quantiacs.com/community/uid/229">@stefanm</a> Thank you very much, that was extremely helpful. Without your help I would probably be still trying to figure out a way <img src="http://quantiacs.com/community/plugins/nodebb-plugin-emoji/emoji/android/1f44f.png?v=933r2hptiik" class="not-responsive emoji emoji-android emoji--clap" title=":clap:" alt="👏" /></p>
]]></description><link>http://quantiacs.com/community/post/1066</link><guid isPermaLink="true">http://quantiacs.com/community/post/1066</guid><dc:creator><![CDATA[magenta.kabuto]]></dc:creator><pubDate>Wed, 29 Mar 2023 14:26:38 GMT</pubDate></item><item><title><![CDATA[Reply to Backtesting on Tue, 28 Mar 2023 13:34:42 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="http://quantiacs.com/community/uid/1799">@magenta-kabuto</a> Hi, maybe this can help with your strategy also:<br />
In your function regime_trade() before returning signals_df, convert it to pandas.Series structure, and name it to corresponding asset (e.g. "NAS: AAPL").</p>
<pre><code>series = signals_df.squeeze().rename(asset_name)
return series
</code></pre>
<p dir="auto">After putting it to trades = dict(), you can concatenate trades.values(), which will create pandas.DataFrame of signals by assets:</p>
<pre><code>pd_signals = pd.concat(trades.values(), axis=1)
</code></pre>
<p dir="auto">Then, convert it to xarray.DataArray and pass it as weights to backtester.</p>
<pre><code>import xarray as xr

xr_signals = xr.DataArray(pd_signals, dims=('time', 'asset'))
</code></pre>
]]></description><link>http://quantiacs.com/community/post/1064</link><guid isPermaLink="true">http://quantiacs.com/community/post/1064</guid><dc:creator><![CDATA[stefanm]]></dc:creator><pubDate>Tue, 28 Mar 2023 13:34:42 GMT</pubDate></item><item><title><![CDATA[Reply to Backtesting on Mon, 27 Mar 2023 19:40:44 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> Thank you  <img src="http://quantiacs.com/community/plugins/nodebb-plugin-emoji/emoji/android/1f642.png?v=933r2hptiik" class="not-responsive emoji emoji-android emoji--slightly_smiling_face" title=":)" alt="🙂" /></p>
]]></description><link>http://quantiacs.com/community/post/1063</link><guid isPermaLink="true">http://quantiacs.com/community/post/1063</guid><dc:creator><![CDATA[magenta.kabuto]]></dc:creator><pubDate>Mon, 27 Mar 2023 19:40:44 GMT</pubDate></item><item><title><![CDATA[Reply to Backtesting on Mon, 27 Mar 2023 19:10:32 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="http://quantiacs.com/community/uid/1799">@magenta-kabuto</a></p>
<p dir="auto">Hello</p>
<p dir="auto">An example using pandas<br />
One can work with pandas DataFrames at intermediate steps and at the end convert them to xarray data structures:</p>
<pre><code class="language-python">def get_price_pct_change(prices):
    prices_pandas = prices.to_pandas()
    assets = data.coords["asset"].values
    for asset in assets:
        prices_pandas[asset] = prices_pandas[asset].pct_change()
    return prices_pandas

prices = data.sel(field="close") * 1.0
prices_pct_change = get_price_pct_change(prices).unstack().to_xarray()
</code></pre>
]]></description><link>http://quantiacs.com/community/post/1062</link><guid isPermaLink="true">http://quantiacs.com/community/post/1062</guid><dc:creator><![CDATA[Vyacheslav_B]]></dc:creator><pubDate>Mon, 27 Mar 2023 19:10:32 GMT</pubDate></item><item><title><![CDATA[Reply to Backtesting on Mon, 27 Mar 2023 17:27:47 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="http://quantiacs.com/community/uid/12">@support</a> Hello, thx for your reply!<img src="/community/assets/uploads/files/1679937629230-bildschirmfoto-2023-03-27-um-19.19.56-resized.png" alt="Bildschirmfoto 2023-03-27 um 19.19.56.png" class="img-responsive img-markdown" />  This is the dicitonary containing each asset. My strategy algorithm is created for inputing a pandas series instead of xArray (it outputs 1,0,-1 for the close price of each date of one asset). In the previous screenshot is an example of the output for a one year period, for each asset(Trades Dictionary). Is it possible to convert my strategy output to xArray or will I have to redefine the Algorithm.<br />
And since each asset and the positions taken for each asset (1,0,-1) are one dictionary entry per asset, it is also not clear to me, how to backtest all assets at once instead of backtesting each at a time.<br />
Thank you and sorry if my description is a bit unclear.</p>
]]></description><link>http://quantiacs.com/community/post/1061</link><guid isPermaLink="true">http://quantiacs.com/community/post/1061</guid><dc:creator><![CDATA[magenta.kabuto]]></dc:creator><pubDate>Mon, 27 Mar 2023 17:27:47 GMT</pubDate></item><item><title><![CDATA[Reply to Backtesting on Mon, 27 Mar 2023 16:18:20 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="http://quantiacs.com/community/uid/1799">@magenta-kabuto</a> Hello, are you using a dictionary where asset names are keys and values are dataframes? If you let us know the dictionary, we can help you in converting that to an xarray DataArray structure</p>
]]></description><link>http://quantiacs.com/community/post/1060</link><guid isPermaLink="true">http://quantiacs.com/community/post/1060</guid><dc:creator><![CDATA[support]]></dc:creator><pubDate>Mon, 27 Mar 2023 16:18:20 GMT</pubDate></item></channel></rss>