<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Shashank Tickjury</title>
    <description>The latest articles on DEV Community by Shashank Tickjury (@shashank_tickjury).</description>
    <link>https://dev.to/shashank_tickjury</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4268339%2Fdcc36373-c0f4-4772-8ed4-31c447ff189e.png</url>
      <title>DEV Community: Shashank Tickjury</title>
      <link>https://dev.to/shashank_tickjury</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shashank_tickjury"/>
    <language>en</language>
    <item>
      <title>How I Backtest a Trading Strategy Without Fooling Myself</title>
      <dc:creator>Shashank Tickjury</dc:creator>
      <pubDate>Sat, 28 Nov 2026 15:13:55 +0000</pubDate>
      <link>https://dev.to/shashank_tickjury/how-i-backtest-a-trading-strategy-without-fooling-myself-2n9f</link>
      <guid>https://dev.to/shashank_tickjury/how-i-backtest-a-trading-strategy-without-fooling-myself-2n9f</guid>
      <description>&lt;p&gt;I had run XGBoost to predict which stocks are likely to be the winners. The AUC of the model was 0.539. To compare, the AUC of a coin flip would have been 0.5. None of the 244 versions of XGBoost passed the luck-adjusted test.&lt;/p&gt;

&lt;p&gt;A bit of thinking on backtesting.&lt;/p&gt;

&lt;p&gt;It is easy to build a model, test on historical prices, and get a good result. The hard part is to understand whether the good result was due to the pattern really being there, or whether it was just due to a few stocks being lucky, or just that the rules had fit well with the history.&lt;/p&gt;

&lt;p&gt;When I backtest a trading strategy, I ask myself the following more useful question: after accounting for the factors that might be deceiving the backtest, is the strategy still interesting? To answer this question, I use three checks. None of these checks are hard, and even if you are backtesting in Python, you can use the same checks. In all the checks that I’m describing, I take an idea, make a fixed set of rules out of the idea, and replay those rules on the daily prices of the stocks in the NSE (India) since 2016.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to backtest a trading strategy with realistic costs
&lt;/h2&gt;

&lt;p&gt;First of all, when I backtest a strategy, I always ensure that transaction costs are accounted for. If the backtest result just looks at the difference between the entry price and the exit price, that may be a gross result. However, every transaction comes at a cost. If you account for these costs, you may see that the backtest result changes.&lt;/p&gt;

&lt;p&gt;For instance, in my backtests I account for STT, stamp duty, exchange fees, GST, demat charge and also include 0.1% slippage on either side for every trade.&lt;/p&gt;

&lt;p&gt;If I had not included the costs of STT, stamp duty and slippage, the backtest results will look better than what they would have been in real.&lt;/p&gt;

&lt;p&gt;Instead of adding a rough percentage of costs to the overall result of the backtest, it is better to include costs in each trade. That is, the costs need to be included in the simulation itself.&lt;/p&gt;

&lt;p&gt;In the style of Python, I can represent this like the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;trade&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;trades&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;entry&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;apply_slippage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;trade&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.1&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;exit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;apply_slippage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;trade&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;exit&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.1&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;costs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;calculate_STT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;trade&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;costs&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nf"&gt;calculate_stamp_duty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;trade&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;costs&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nf"&gt;calculate_exchange_fees&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;trade&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;costs&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nf"&gt;calculate_GST&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;trade&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;costs&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nf"&gt;calculate_demat_charge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;trade&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;net_result&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nf"&gt;trade_result&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;exit&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;costs&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Please note that this is just a generic pseudocode. The actual calculations of the costs should be a part of your execution model.&lt;/p&gt;

&lt;p&gt;The point of this is to not compare the strategies by their gross results, if you want to find out whether the strategies are actually making any money after costs.&lt;/p&gt;

&lt;p&gt;However, including realistic costs in the backtest is just one way of understanding whether the result of the strategy remains even after the costs of trading. But it does not help in understanding whether the strategy is actually finding something which is better than chance.&lt;/p&gt;

&lt;h2&gt;
  
  
  Compare your strategy against a random baseline
&lt;/h2&gt;

&lt;p&gt;Here is a useful check.&lt;/p&gt;

&lt;p&gt;When you have a strategy that picks certain stocks and after backtesting on the historical prices has shown a positive result, how do you know that it is the rules of picking the stocks that is giving you the result? Maybe you could have just picked the stocks randomly and got the same result?&lt;/p&gt;

&lt;p&gt;So I compare the strategy with the NIFTY 500 index, and also with 20 portfolios that randomly pick stocks from the same list of stocks as the strategy, but use the same timing, stake size and costs of the strategy. It is important that the random portfolio does not have an easier simulation than the strategy.&lt;/p&gt;

&lt;p&gt;A simplified representation of this is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;portfolio&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="mi"&gt;20_random_portfolios&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;picks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;random_from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;same_stock_list&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;timing&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;strategy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;timing&lt;/span&gt;
    &lt;span class="n"&gt;stake&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;strategy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;stake_size&lt;/span&gt;
    &lt;span class="n"&gt;costs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;strategy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;cost_rules&lt;/span&gt;
    &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;replay&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;picks&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timing&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;stake&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;costs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;compare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;strategy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;random_results&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If a random pick gave you the same result, maybe it’s just luck.&lt;/p&gt;

&lt;p&gt;Most of the ideas that I tested were not clearly better than randomly picking stocks from the same list of stocks. For example, the XGBoost model to predict the winning stocks was barely better than a coin flip (AUC of 0.539, where a coin flip would have an AUC of 0.5). None of the 244 versions of XGBoost passed the luck-adjusted test.&lt;/p&gt;

&lt;p&gt;Another example was when I found that the backtest result was high if I did not include the biggest 50 to 200 stocks. But, I found that if I picked stocks randomly from the same list, the result was just as good. So, the gains were a result of the list of stocks, not my picks.&lt;/p&gt;

&lt;p&gt;That's a very important distinction. It could be that the strategy is doing well because the stock universe itself is doing well.&lt;/p&gt;

&lt;p&gt;Once I have a random baseline, I look at whether the result of the strategy is dependent on a few stocks that do well.&lt;/p&gt;

&lt;h2&gt;
  
  
  Remove the 5 best winners, then check the result
&lt;/h2&gt;

&lt;p&gt;Sometimes the backtest result will look good because a few stocks do exceptionally well. This doesn't mean the strategy is useless. At the least, you should test the strategy more.&lt;/p&gt;

&lt;p&gt;I do this by running the result of the strategy once again, but without including the 5 best winners in the backtest. The point of this test is to see how dependent the backtest result is on the best winners.&lt;/p&gt;

&lt;p&gt;This is straightforward enough.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;ranked&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;rank_stocks_by_contribution&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stock_results&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;top_winners&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;select_top&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ranked&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;remaining&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;remove_stocks&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stock_results&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;top_winners&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;full_result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;calculate_result&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stock_results&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;reduced_result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;calculate_result&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;remaining&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;compare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;full_result&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;reduced_result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a pretty simple test, but it can help check whether the backtest result is broad-based, or dependent on a few winners.&lt;/p&gt;

&lt;p&gt;In one backtest I was doing, I tested the idea of just holding the most volatile stocks. The headline result looked better, but it was dependent on a few lottery ticket winners. The strategy did not pass the luck test, and the best deflated Sharpe was 0.51 across 179 different versions of the strategy.&lt;/p&gt;

&lt;p&gt;I am trying to understand how the backtest result is generated, not just looking at the headline result.&lt;/p&gt;

&lt;p&gt;Another important thing in backtesting is publishing ideas that don't work.&lt;/p&gt;

&lt;h2&gt;
  
  
  Publish the failures, and be upfront about data gaps
&lt;/h2&gt;

&lt;p&gt;I think a backtest is more useful if the reader is able to see failed ideas as well as successful ones. I do publish my failed ideas, marked as No change, Not adopted or Rejected.&lt;/p&gt;

&lt;p&gt;It's also easier to forget about ideas that don't fit your view, if they aren't visible. I tried an idea where I closed a third of a position early, at 1.5 to 8 times the amount risked. The results were lower in almost all versions I tested.&lt;/p&gt;

&lt;p&gt;The key thing is to publish that as well.&lt;/p&gt;

&lt;p&gt;One more thing: there is a known issue with the underlying data I use for backtests. There are missing prices of stocks that are delisted. So, the results of stocks in general look a bit better than they really were. A good backtesting process should recognize the limitations of the data, and historical lists of stocks can be misleading. I would rather publish an imperfect backtest with known limitations, than publish a backtest without discussing limitations.&lt;/p&gt;

&lt;p&gt;I built Tickjury, where these tests run on NSE stocks.&lt;/p&gt;

&lt;h2&gt;
  
  
  What check would you do on your backtest result?
&lt;/h2&gt;

&lt;p&gt;You could start with a couple of easy checks like use more realistic transaction costs, compare your result to a random portfolio with the same set of assumptions, and then remove the 5 best winners in the backtest and check the result. While these tests will not prove that a strategy will work in the future, they can help you understand whether the backtest result has some merit and should be studied further.&lt;/p&gt;

&lt;p&gt;What's the one check that you do on a backtest before trusting its results?&lt;/p&gt;

&lt;p&gt;Education only, not investment advice.&lt;/p&gt;

</description>
      <category>python</category>
      <category>trading</category>
      <category>backtesting</category>
      <category>datascience</category>
    </item>
    <item>
      <title>Backtesting Indian stocks against random portfolios: how I built Tickjury</title>
      <dc:creator>Shashank Tickjury</dc:creator>
      <pubDate>Fri, 27 Nov 2026 07:10:12 +0000</pubDate>
      <link>https://dev.to/shashank_tickjury/backtesting-indian-stocks-against-random-portfolios-how-i-built-tickjury-1o8</link>
      <guid>https://dev.to/shashank_tickjury/backtesting-indian-stocks-against-random-portfolios-how-i-built-tickjury-1o8</guid>
      <description>&lt;p&gt;Tickjury is a website where I backtest trading ideas on Indian stocks and put up the results. I also put up the failed results. In this post I’m going to talk about the architecture of the site and about one specific design decision I made, which is the use of a random portfolio as a baseline for comparisons.&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem with a backtest
&lt;/h2&gt;

&lt;p&gt;Whenever you do a backtest and see a good yearly return, the question to ask is, what would have happened had I randomly picked a portfolio in the same years? In Tickjury, for every trading model, I compare with the NIFTY 500 and also with 20 randomly selected portfolios from the same list of stocks. The portfolio is selected to match the model in terms of timing, stake size and costs, but the stock pick is random. If the random portfolio did as well, it could just be that the model’s performance was lucky.&lt;/p&gt;

&lt;h2&gt;
  
  
  Accounting for costs on each trade
&lt;/h2&gt;

&lt;p&gt;When you trade in the Indian stock market in the delivery mode, you pay a number of taxes and charges - STT, stamp duty, exchange charges, GST and a demat charge. I account for all of these on every trade, and I also use a slippage of 0.1% on either side of every trade. A backtest that doesn’t account for these will look better than it actually was.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tech stack
&lt;/h2&gt;

&lt;p&gt;The market data is taken from Zerodha Kite, and I get daily prices from 2016, which are updated periodically on a small Digital Ocean droplet. The research engine is written in plain Python, the API is a Starlette app, and the marketing site is written in Next.js 16. The performance sheets for each model are precomputed for every quarter start since 2016 Q1, and updated every night. This means that the model performance pages do not do any backtests on request, they just read files. The site is exposed via a Cloudflare Tunnel.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I got wrong
&lt;/h2&gt;

&lt;p&gt;My price data does not contain prices of stocks that have been delisted. This means that stock results look slightly better than they actually were. This is mentioned on the method page.&lt;/p&gt;

&lt;h2&gt;
  
  
  The failed ideas remain
&lt;/h2&gt;

&lt;p&gt;I publish the failed ideas as well, by marking them as “No change” or “Rejected”. If I only showed the winners, you wouldn’t know how many ideas I actually tested.&lt;/p&gt;

&lt;h2&gt;
  
  
  Free stuff
&lt;/h2&gt;

&lt;p&gt;I give away the returns and worst fall for each model, the market cycle view, the NIFTY weekly options backtests, and one page for each NSE stock, without requiring an account. The trades and holdings are behind a credits system, with packs starting Rs 100.&lt;/p&gt;

&lt;p&gt;I’m keen to get some feedback on the use of a random portfolio as a baseline - do you think it’s a fair comparison or would you do something different in your own backtesting?&lt;/p&gt;

&lt;p&gt;Demo (1:32): &lt;a href="https://www.youtube.com/watch?v=nmAvyH9II04" rel="noopener noreferrer"&gt;https://www.youtube.com/watch?v=nmAvyH9II04&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Site: &lt;a href="https://tickjury.com/?utm_source=devto&amp;amp;utm_medium=community&amp;amp;utm_campaign=launch" rel="noopener noreferrer"&gt;https://tickjury.com/?utm_source=devto&amp;amp;utm_medium=community&amp;amp;utm_campaign=launch&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;How I made this post: I run the tests and decide what is published. AI tools helped draft and edit this post. Every figure comes from the site.&lt;/p&gt;

&lt;p&gt;I built Tickjury. Education only, not investment advice. Past results, after costs, with stated limits.&lt;/p&gt;

</description>
      <category>showdev</category>
      <category>python</category>
      <category>nextjs</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
