{"id":29131,"date":"2024-10-28T14:30:00","date_gmt":"2024-10-28T06:30:00","guid":{"rendered":"https:\/\/www.tejwin.com\/?post_type=insight&#038;p=29131"},"modified":"2026-03-02T11:00:59","modified_gmt":"2026-03-02T03:00:59","slug":"questions-about-tquant-lab","status":"publish","type":"insight","link":"https:\/\/www.tejwin.com\/en\/insight\/questions-about-tquant-lab\/","title":{"rendered":"Newbie Troubleshooting\uff1aAnswering All Your Questions About TQuant Lab."},"content":{"rendered":"\n<figure class=\"wp-block-image aligncenter size-full caption-align-center\"><img fetchpriority=\"high\" decoding=\"async\" width=\"4934\" height=\"3308\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/kelly-sikkema-UrafSwRu3hk-unsplash-1.jpg\" alt=\"questions\" class=\"wp-image-28969\" srcset=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/kelly-sikkema-UrafSwRu3hk-unsplash-1.jpg 4934w, https:\/\/www.tejwin.com\/wp-content\/uploads\/kelly-sikkema-UrafSwRu3hk-unsplash-1-300x201.jpg 300w, https:\/\/www.tejwin.com\/wp-content\/uploads\/kelly-sikkema-UrafSwRu3hk-unsplash-1-1024x687.jpg 1024w, https:\/\/www.tejwin.com\/wp-content\/uploads\/kelly-sikkema-UrafSwRu3hk-unsplash-1-150x101.jpg 150w, https:\/\/www.tejwin.com\/wp-content\/uploads\/kelly-sikkema-UrafSwRu3hk-unsplash-1-768x515.jpg 768w, https:\/\/www.tejwin.com\/wp-content\/uploads\/kelly-sikkema-UrafSwRu3hk-unsplash-1-1536x1030.jpg 1536w, https:\/\/www.tejwin.com\/wp-content\/uploads\/kelly-sikkema-UrafSwRu3hk-unsplash-1-2048x1373.jpg 2048w\" sizes=\"(max-width: 4934px) 100vw, 4934px\" \/><figcaption class=\"wp-element-caption\">Photo by <a class=\"ek-link\" href=\"https:\/\/unsplash.com\/@googledeepmindhttps:\/\/unsplash.com\/@googledeepmind\" target=\"_blank\" rel=\"noopener\">Kelly Sikkema<\/a> on <a class=\"ek-link\" href=\"https:\/\/unsplash.com\/\" target=\"_blank\" rel=\"noopener\">Unsplash<\/a><\/figcaption><\/figure>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_81 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-69f1890c12d57\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"ez-toc-cssicon\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-69f1890c12d57\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.tejwin.com\/en\/insight\/questions-about-tquant-lab\/#Preface\" >Preface<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.tejwin.com\/en\/insight\/questions-about-tquant-lab\/#Frequently_Asked_Questions_FAQ\" >Frequently Asked Questions (FAQ)<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.tejwin.com\/en\/insight\/questions-about-tquant-lab\/#What_should_I_do_if_I_installed_zipline-tej_in_a_virtual_environment_but_still_cant_use_TQuant_Lab\" >What should I do if I installed zipline-tej in a virtual environment but still can&#8217;t use TQuant Lab?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.tejwin.com\/en\/insight\/questions-about-tquant-lab\/#How_to_Import_External_Data_into_the_Pipeline_for_Backtesting\" >How to Import External Data into the Pipeline for Backtesting?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.tejwin.com\/en\/insight\/questions-about-tquant-lab\/#What_Are_the_Four_Main_Functions_in_TQuant_Lab_and_Are_They_Required_for_Every_Backtest\" >What Are the Four Main Functions in TQuant Lab, and Are They Required for Every Backtest?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.tejwin.com\/en\/insight\/questions-about-tquant-lab\/#What_Does_Each_Column_in_the_DataFrame_from_run_algorithm_Represent\" >What Does Each Column in the DataFrame from run_algorithm() Represent?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.tejwin.com\/en\/insight\/questions-about-tquant-lab\/#How_Can_Built-in_Technical_Indicators_such_as_SMA_be_used_in_TQuant_Lab_Can_External_Libraries_Like_NumPy_or_TA-Lib_Be_Used\" >How Can Built-in Technical Indicators, such as SMA, be used in TQuant Lab? Can External Libraries Like NumPy or TA-Lib Be Used?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.tejwin.com\/en\/insight\/questions-about-tquant-lab\/#Can_TQuant_Lab_Set_Entry_Points_Using_Opening_or_Closing_Prices\" >Can TQuant Lab Set Entry Points Using Opening or Closing Prices?<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.tejwin.com\/en\/insight\/questions-about-tquant-lab\/#Conclusion\" >Conclusion<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.tejwin.com\/en\/insight\/questions-about-tquant-lab\/#Extended_Reading\" >Extended Reading<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading has-text-align-left\"><span class=\"ez-toc-section\" id=\"Preface\"><\/span>Preface<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>When using TQuant Lab for backtesting and strategy analysis, beginners may encounter various technical challenges and questions. This article provides solutions and tips to help users develop and backtest strategies more smoothly, improving efficiency and accuracy. Hopefully, this information will help resolve common problems faced by newcomers.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Frequently_Asked_Questions_FAQ\"><\/span>Frequently Asked Questions (FAQ)<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_should_I_do_if_I_installed_zipline-tej_in_a_virtual_environment_but_still_cant_use_TQuant_Lab\"><\/span>What should I do if I installed <code><strong><em>zipline-tej<\/em><\/strong><\/code> in a virtual environment but still can&#8217;t use TQuant Lab?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>If you have followed <a href=\"https:\/\/tquant.tejwin.com\/%e6%8a%80%e8%a1%93%e6%89%8b%e5%86%8a\/\" target=\"_blank\" rel=\"noreferrer noopener\">the Technical manual\u2014TQuant Lab<\/a>\u2014but are still encountering issues, try using the <strong><a href=\"https:\/\/www.tejwin.com\/en\/insight\/running-tquant-lab-in-google-colab\/\" target=\"_blank\" rel=\"noreferrer noopener\">Tutorial on Running TQuant Lab in Google Colab and Common Errors<\/a> <\/strong>and following these additional steps to resolve common problems. <\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_to_Import_External_Data_into_the_Pipeline_for_Backtesting\"><\/span>How to Import External Data into the Pipeline for Backtesting?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Using <strong>CustomDataset<\/strong> allows you to seamlessly integrate external data into the TQuant Lab Pipeline, making it easier to leverage custom metrics and datasets in your strategies. This method ensures smooth backtesting by incorporating additional insights such as factors or indicators. A good example is implementing the <strong><a href=\"https:\/\/www.tejwin.com\/en\/insight\/f-score-strategy\/\" target=\"_blank\" rel=\"noreferrer noopener\">F-score Strategy: Identifying Undervalued Quality Stocks<\/a><\/strong>, which identifies undervalued quality stocks.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_Are_the_Four_Main_Functions_in_TQuant_Lab_and_Are_They_Required_for_Every_Backtest\"><\/span>What Are the Four Main Functions in TQuant Lab, and Are They Required for Every Backtest?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>The four core functions each serve different purposes. They can be used to configure the backtesting environment, such as setting slippage models or transaction fees, implementing trading strategies, placing orders, and recording trade information. Additionally, they enable the visualization of strategy performance and risk after completing the backtest. Not every strategy requires all four functions, as their usage depends on the strategy&#8217;s needs and the user&#8217;s preferences. For more detailed instructions, please refer to the <strong><a href=\"https:\/\/www.tejwin.com\/en\/insight\/tquant-lab-rookie-manual\/\" target=\"_blank\" rel=\"noreferrer noopener\">TQuant Lab Rookie Manual<\/a><\/strong>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_Does_Each_Column_in_the_DataFrame_from_run_algorithm_Represent\"><\/span>What Does Each Column in the DataFrame from <code>run_algorithm()<\/code> Represent?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Here, we list only a few of the more critical columns. For a complete description of all columns, please refer to <a href=\"https:\/\/github.com\/tejtw\/TQuant-Lab\/blob\/main\/lecture\/TSMC%20buy%20and%20hold%20strategy.ipynb\" target=\"_blank\" rel=\"noreferrer noopener\">TQuant-Lab\/lecture\/TSMC buy-and-hold strategy<\/a>.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>benchmark_return<\/strong>: The daily return of the benchmark. If set using set_benchmark(), it is calculated as:(Current Day\u2019s Benchmark Closing Price \/ Previous Day\u2019s Benchmark Closing Price) &#8211; 1<\/li>\n\n\n\n<li><strong>benchmark_period_return<\/strong>: The cumulative daily return of the benchmark, calculated as np.nancumprod(1 + benchmark_return Series) &#8211; 1<\/li>\n\n\n\n<li><strong>benchmark_volatility<\/strong>: The annualized volatility of the benchmark&#8217;s daily returns, calculated only if there are at least two periods of returns:(benchmark_return Series).expanding(2).std(ddof=1) * np.sqrt(252)<\/li>\n\n\n\n<li><strong>max_drawdown<\/strong>: The maximum percentage drop from the portfolio&#8217;s cumulative return peak.<\/li>\n\n\n\n<li><strong>Sharpe<\/strong>: The annualized Sharpe ratio measures the return achieved per unit of risk taken.<\/li>\n\n\n\n<li><strong>Sortino<\/strong>: The annualized Sortino ratio measures the return achieved per unit of downside risk taken.<\/li>\n\n\n\n<li><strong>Alpha<\/strong>: The annualized alpha indicates the portfolio&#8217;s ability to generate excess returns compared to the benchmark.<\/li>\n\n\n\n<li><strong>Beta<\/strong>: A measure of the portfolio&#8217;s volatility relative to the overall market.<\/li>\n<\/ul>\n\n\n\n<p>Additionally, you can use <code>get_transaction_detail<\/code> on the DataFrame output from <code>run_algorithm()<\/code> to obtain more detailed information on orders, trades, and positions. Here&#8217;s how to use it:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from zipline.utils.run_algo import get_transaction_detail\npositions, transactions, orders = get_transaction_detail(result) # If the DataFrame returned by run_algorithm() is named result<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>positions<\/strong>: Position status<\/li>\n\n\n\n<li><strong>transactions<\/strong>: Transaction records<\/li>\n\n\n\n<li><strong>orders<\/strong>: Order records<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_Can_Built-in_Technical_Indicators_such_as_SMA_be_used_in_TQuant_Lab_Can_External_Libraries_Like_NumPy_or_TA-Lib_Be_Used\"><\/span>How Can Built-in Technical Indicators, such as SMA, be used in TQuant Lab? Can External Libraries Like NumPy or TA-Lib Be Used?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>TQuant Lab offers many built-in technical and price factors, including SMA, Bollinger Bands, RSI, and more. These built-in indicators save users time from having to create technical indicators from scratch. For a detailed list of built-in factors, along with their descriptions and usage, please refer to <a href=\"https:\/\/github.com\/tejtw\/TQuant-Lab\/blob\/main\/lecture\/Pipeline%20built-in%20factors.ipynb\" target=\"_blank\" rel=\"noopener\">TQuant-Lab\/lecture\/Pipeline built-in factors\u3002<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Can_TQuant_Lab_Set_Entry_Points_Using_Opening_or_Closing_Prices\"><\/span>Can TQuant Lab Set Entry Points Using Opening or Closing Prices?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p><strong>Zipline<\/strong> executes trades based on the <strong>next day&#8217;s closing price<\/strong> to minimize look-ahead bias if the strategy generates a signal on the current day. For detailed order information, check the <strong>orders<\/strong> field in the results DataFrame.<\/p>\n\n\n\n<p>As for executing trades using <strong>opening prices<\/strong>, this feature is currently not available. However, it may be considered for future updates after evaluation.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>With the troubleshooting solutions and tips in this article, users can more smoothly overcome technical challenges encountered while using TQuant Lab. From installation to data processing, we hope this information will improve users&#8217; efficiency and accuracy, helping them successfully develop their first strategy.<\/p>\n\n\n\n<div class=\"wp-block-button has-custom-width wp-block-button__width-100 has-custom-font-size\" style=\"font-size:21px\"><a class=\"wp-block-button__link has-background has-text-align-center wp-element-button\" href=\"https:\/\/www.tejwin.com\/en\/contact\/\" style=\"border-radius:16px;background:linear-gradient(135deg,rgb(160,209,216) 0%,rgb(51,145,181) 50%,rgb(50,95,191) 100%)\"><strong>Want to Learn More About Our Databases and Solutions?<br>Contact Us and Get the Free Trial Today!<\/strong><\/a><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Extended_Reading\"><\/span>Extended Reading<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><a class=\"ek-link\" href=\"https:\/\/www.tejwin.com\/insight\/%e5%ae%b6%e9%9b%bb%e6%a5%ad\/\" target=\"_blank\" rel=\"noreferrer noopener\">TQuant Lab Rookie Manual <\/a><\/p>\n\n\n\n<p><a class=\"ek-link\" href=\"https:\/\/www.tejwin.com\/en\/insight\/touch-panel-industry-ways-to-end-decline-in-profit-venturing-into-new-business\/\" target=\"_blank\" rel=\"noreferrer noopener\">Tutorial on Running TQuant Lab in Google Colab and Common Errors <\/a><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>When using TQuant Lab for backtesting and strategy analysis, beginners may encounter various technical challenges and questions. This article provides solutions and tips to help users develop and backtest strategies more smoothly, improving efficiency and accuracy. Hopefully, this information will help resolve common problems faced by newcomers.<\/p>\n","protected":false},"featured_media":28969,"template":"","tags":[3063,3176,2990,3166],"insight-category":[50,1356],"class_list":["post-29131","insight","type-insight","status-publish","has-post-thumbnail","hentry","tag-backtesting-2","tag-python-2","tag-quantitive-trading","tag-tquant-lab-2","insight-category-fintech","insight-category-tquant-lab-en"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/insight\/29131","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/insight"}],"about":[{"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/types\/insight"}],"version-history":[{"count":10,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/insight\/29131\/revisions"}],"predecessor-version":[{"id":44017,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/insight\/29131\/revisions\/44017"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/media\/28969"}],"wp:attachment":[{"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/media?parent=29131"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/tags?post=29131"},{"taxonomy":"insight-category","embeddable":true,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/insight-category?post=29131"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}