{"id":25211,"date":"2024-07-10T17:30:00","date_gmt":"2024-07-10T09:30:00","guid":{"rendered":"https:\/\/www.tejwin.com\/?post_type=insight&#038;p=25211"},"modified":"2026-02-25T14:04:04","modified_gmt":"2026-02-25T06:04:04","slug":"running-tquant-lab-in-google-colab","status":"publish","type":"insight","link":"https:\/\/www.tejwin.com\/en\/insight\/running-tquant-lab-in-google-colab\/","title":{"rendered":"Tutorial on Running TQuant Lab in Google Colab and Common Errors"},"content":{"rendered":"\n<figure class=\"wp-block-image aligncenter size-full is-resized caption-align-center\"><img fetchpriority=\"high\" decoding=\"async\" width=\"5472\" height=\"3648\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/jametlene-reskp-3Dtu6_XfqIk-unsplash.jpg\" alt=\"Running TQuant Lab in Google Colab \" class=\"wp-image-24848\" style=\"width:840px;height:auto\" srcset=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/jametlene-reskp-3Dtu6_XfqIk-unsplash.jpg 5472w, https:\/\/www.tejwin.com\/wp-content\/uploads\/jametlene-reskp-3Dtu6_XfqIk-unsplash-300x200.jpg 300w, https:\/\/www.tejwin.com\/wp-content\/uploads\/jametlene-reskp-3Dtu6_XfqIk-unsplash-1024x683.jpg 1024w, https:\/\/www.tejwin.com\/wp-content\/uploads\/jametlene-reskp-3Dtu6_XfqIk-unsplash-150x100.jpg 150w, https:\/\/www.tejwin.com\/wp-content\/uploads\/jametlene-reskp-3Dtu6_XfqIk-unsplash-768x512.jpg 768w, https:\/\/www.tejwin.com\/wp-content\/uploads\/jametlene-reskp-3Dtu6_XfqIk-unsplash-1536x1024.jpg 1536w, https:\/\/www.tejwin.com\/wp-content\/uploads\/jametlene-reskp-3Dtu6_XfqIk-unsplash-2048x1365.jpg 2048w\" sizes=\"(max-width: 5472px) 100vw, 5472px\" \/><figcaption class=\"wp-element-caption\">Photo by <a href=\"https:\/\/unsplash.com\/@reskp?utm_content=creditCopyText&amp;utm_medium=referral&amp;utm_source=unsplash\" target=\"_blank\" rel=\"noopener\">Jametlene Reskp<\/a> on <a href=\"https:\/\/unsplash.com\/photos\/silver-pocketwatch-3Dtu6_XfqIk?utm_content=creditCopyText&amp;utm_medium=referral&amp;utm_source=unsplash\" class=\"ek-link\" 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-6a109b8304f71\" 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-6a109b8304f71\"  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\/running-tquant-lab-in-google-colab\/#Summary_of_Key_Points_in_This_Article\" >Summary of Key Points in This Article<\/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\/running-tquant-lab-in-google-colab\/#Introduction\" >Introduction<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.tejwin.com\/en\/insight\/running-tquant-lab-in-google-colab\/#Running_TQuant_Lab_in_Google_Colab_and_Installing_some_Commonly_used_Package\" >Running TQuant Lab in Google Colab and Installing some Commonly used Package<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.tejwin.com\/en\/insight\/running-tquant-lab-in-google-colab\/#You_only_need_one_simple_lines_of_code_to_complete_the_environment_setup\" >You only need one simple lines of code to complete the environment setup.<\/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\/running-tquant-lab-in-google-colab\/#If_you_encounter_a_pop-up_window_showing_an_error_simply_click_%E2%80%9CRestart_Runtime%E2%80%9D_to_resolve_it\" >If you encounter a pop-up window showing an error, simply click &#8220;Restart Runtime&#8221; to resolve it.<\/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\/running-tquant-lab-in-google-colab\/#In_the_end_you_may_see_the_following_error_message_but_you_can_ignore_it_The_system_is_actually_ready_for_use\" >In the end, you may see the following error message, but you can ignore it. The system is actually ready for use.<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.tejwin.com\/en\/insight\/running-tquant-lab-in-google-colab\/#TQuant_Lab_Tutorial_Selecting_the_Top_Five_Semiconductor_Companies_by_Revenue_for_Backtesting\" >TQuant Lab Tutorial: Selecting the Top Five Semiconductor Companies by Revenue for Backtesting<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.tejwin.com\/en\/insight\/running-tquant-lab-in-google-colab\/#Load_Commonly_Used_Packages\" >Load Commonly Used Packages<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.tejwin.com\/en\/insight\/running-tquant-lab-in-google-colab\/#First_identify_all_companies_in_the_semiconductor\" >First, identify all companies in the semiconductor<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.tejwin.com\/en\/insight\/running-tquant-lab-in-google-colab\/#Check_their_revenue_and_select_the_top_five_highest_then_save_their_stock_symbols\" >Check their revenue and select the top five highest, then save their stock symbols.<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/www.tejwin.com\/en\/insight\/running-tquant-lab-in-google-colab\/#Load_the_data_onto_your_local_computer\" >Load the data onto your local computer.<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/www.tejwin.com\/en\/insight\/running-tquant-lab-in-google-colab\/#Font_Issues_Encountered_with_Pyfolio_and_How_to_Resolve_Them\" >Font Issues Encountered with Pyfolio and How to Resolve Them<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/www.tejwin.com\/en\/insight\/running-tquant-lab-in-google-colab\/#Even_though_the_charts_have_been_successfully_plotted_you_may_still_encounter_warnings_about_missing_fonts_To_resolve_this_issue_you_can_manually_load_the_fonts\" >Even though the charts have been successfully plotted, you may still encounter warnings about missing fonts. To resolve this issue, you can manually load the fonts.<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/www.tejwin.com\/en\/insight\/running-tquant-lab-in-google-colab\/#After_trying_again_the_warning_messages_should_no_longer_appear\" >After trying again, the warning messages should no longer appear.<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/www.tejwin.com\/en\/insight\/running-tquant-lab-in-google-colab\/#Conclusion\" >Conclusion<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/www.tejwin.com\/en\/insight\/running-tquant-lab-in-google-colab\/#Source_Code\" >Source Code<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/www.tejwin.com\/en\/insight\/running-tquant-lab-in-google-colab\/#Extended_Reading\" >Extended Reading<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/www.tejwin.com\/en\/insight\/running-tquant-lab-in-google-colab\/#Relevant_Links\" >Relevant Links<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Summary_of_Key_Points_in_This_Article\"><\/span>Summary of Key Points in This Article<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Article Difficulty: \u2605\u2606\u2606\u2606\u2606<\/li>\n\n\n\n<li>Tutorial on Running TQuant Lab in Google Colab<\/li>\n\n\n\n<li>Simple Test: Select the top five companies by revenue (from any industry) and backtest their returns<\/li>\n\n\n\n<li>Install fonts to ensure the Pyfolio package can plot graphs smoothly<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Introduction\"><\/span>Introduction<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>For students who want to use TQuant Lab, in addition to the original GitHub installation tutorial, we now offer a faster and simpler way to use it directly on Google Colab. The tutorial on running TQuant Lab in Google Colab eliminates the need to set up a virtual environment, significantly lowering the barrier to entry.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Running_TQuant_Lab_in_Google_Colab_and_Installing_some_Commonly_used_Package\"><\/span>Running TQuant Lab in Google Colab and Installing some Commonly used Package<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"You_only_need_one_simple_lines_of_code_to_complete_the_environment_setup\"><\/span>You only need one simple lines of code to complete the environment setup.<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>              !pip install zipline-tej<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"If_you_encounter_a_pop-up_window_showing_an_error_simply_click_%E2%80%9CRestart_Runtime%E2%80%9D_to_resolve_it\"><\/span>If you encounter a pop-up window showing an error, simply click &#8220;Restart Runtime&#8221; to resolve it.<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img decoding=\"async\" width=\"1038\" height=\"506\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/image-453.png\" alt=\"Running TQuant Lab in Google Colab \" class=\"wp-image-24843\" srcset=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/image-453.png 1038w, https:\/\/www.tejwin.com\/wp-content\/uploads\/image-453-300x146.png 300w, https:\/\/www.tejwin.com\/wp-content\/uploads\/image-453-1024x499.png 1024w, https:\/\/www.tejwin.com\/wp-content\/uploads\/image-453-150x73.png 150w, https:\/\/www.tejwin.com\/wp-content\/uploads\/image-453-768x374.png 768w\" sizes=\"(max-width: 1038px) 100vw, 1038px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"In_the_end_you_may_see_the_following_error_message_but_you_can_ignore_it_The_system_is_actually_ready_for_use\"><\/span>In the end, you may see the following error message, but you can ignore it. The system is actually ready for use.<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-black-color\"><span style=\"background-color:#abb8c3\" class=\"has-inline-background\">ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\ncudf-cu12 24.4.1 requires pandas&lt;2.2.2dev0,&gt;=2.0, but you have pandas 1.5.3 which is incompatible.\ngoogle-colab 1.0.0 requires pandas==2.0.3, but you have pandas 1.5.3 which is incompatible.<\/span><\/mark><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"TQuant_Lab_Tutorial_Selecting_the_Top_Five_Semiconductor_Companies_by_Revenue_for_Backtesting\"><\/span>TQuant Lab Tutorial: Selecting the Top Five Semiconductor Companies by Revenue for Backtesting<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Load_Commonly_Used_Packages\"><\/span>Load Commonly Used Packages<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>import os \nos.environ&#91;'TEJAPI_BASE'] = 'https:\/\/api.tej.com.tw'\nos.environ&#91;'TEJAPI_KEY'] = 'Your_Key'\n\nimport datetime\n\nimport tejapi\nimport pandas as pd \nimport numpy as np<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"First_identify_all_companies_in_the_semiconductor\"><\/span>First, identify all companies in the semiconductor<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>from zipline.sources.TEJ_Api_Data import get_universe\n\npool = get_universe(start = '2022-07-02', \n                    end = '2023-07-02',\n                    mkt_bd_e = 'TSE',  \n                    stktp_e = 'Common Stock',  \n                    sub_ind_e=&#91;'M2324 Semiconductor', 'M2325 Computer and Peripheral Equipment'])<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Check_their_revenue_and_select_the_top_five_highest_then_save_their_stock_symbols\"><\/span>Check their revenue and select the top five highest, then save their stock symbols.<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>import TejToolAPI\n\nstart_time = pd.Timestamp('2022-07-02')\nend_time = pd.Timestamp('2023-07-02')\n\ndata = TejToolAPI.get_history_data(start = start_time,\n                                   end = end_time,\n                                   ticker = pool,\n                                   fin_type = 'A',\n                                   columns = &#91;'\u71df\u696d\u7e3d\u6536\u5165'],\n                                   transfer_to_chinese = True)\n\ndata  = data.drop_duplicates(subset=&#91;'\u80a1\u7968\u4ee3\u78bc'], keep='last').reset_index(drop=True)\n\ndata = data.nlargest(5, '\u71df\u696d\u7e3d\u6536\u5165_A')    #select the top five highest\n\ndata<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th><\/th><th class=\"has-text-align-center\" data-align=\"center\">stock<\/th><th class=\"has-text-align-center\" data-align=\"center\">date<\/th><th class=\"has-text-align-center\" data-align=\"center\">Total_Operating_Income_A<\/th><\/tr><\/thead><tbody><tr><th>6<\/th><td class=\"has-text-align-center\" data-align=\"center\">2330<\/td><td class=\"has-text-align-center\" data-align=\"center\">2023-06-30<\/td><td class=\"has-text-align-center\" data-align=\"center\">508632973.0<\/td><\/tr><tr><th>90<\/th><td class=\"has-text-align-center\" data-align=\"center\">4938<\/td><td class=\"has-text-align-center\" data-align=\"center\">2023-06-30<\/td><td class=\"has-text-align-center\" data-align=\"center\">318136546.0<\/td><\/tr><tr><th>27<\/th><td class=\"has-text-align-center\" data-align=\"center\">2382<\/td><td class=\"has-text-align-center\" data-align=\"center\">2023-06-30<\/td><td class=\"has-text-align-center\" data-align=\"center\">266180950.0<\/td><\/tr><tr><th>67<\/th><td class=\"has-text-align-center\" data-align=\"center\">3231<\/td><td class=\"has-text-align-center\" data-align=\"center\">2023-06-30<\/td><td class=\"has-text-align-center\" data-align=\"center\">212000207.0<\/td><\/tr><tr><th>4<\/th><td class=\"has-text-align-center\" data-align=\"center\">2324<\/td><td class=\"has-text-align-center\" data-align=\"center\">2023-06-30<\/td><td class=\"has-text-align-center\" data-align=\"center\">209458784.0<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>tickers = data&#91;'\u80a1\u7968\u4ee3\u78bc'].unique()<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Load_the_data_onto_your_local_computer\"><\/span>Load the data onto your local computer.<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>start = '2023-07-03'\nend = '2024-07-02'\n\nos.environ&#91;'mdate'] = start + ' ' + end\nos.environ&#91;'ticker'] = ' '.join(tickers) + ' ' + 'IR0001'\n\n!zipline ingest -b tquant\n\nfrom zipline.data import bundles\nbundle_data = bundles.load('tquant')\n\nfrom zipline.api import *\nfrom zipline.finance import commission, slippage\n\ndef initialize(context):\n    context.day = 0\n    context.tickers = tickers\n    set_slippage(slippage.VolumeShareSlippage(volume_limit = 0.025, price_impact = 0.1))\n    set_commission(commission.Custom_TW_Commission(min_trade_cost = 20, discount = 1.0, tax = 0.003))\n    set_benchmark(symbol('IR0001'))\n    set_liquidity_risk_management_rule(&#91;'\u5168\u984d\u4ea4\u5272\u80a1\u7968(Full-Cash Delivery Securities)', '\u6f32\u505c\u80a1\u7968(Limit Up)', '\u8dcc\u505c\u80a1\u7968(Limit Down)', '\u958b\u76e4\u5373\u9396\u6b7b(Limited Whole Day)'])\n\ndef handle_data(context, data):\n\n    if context.day == 0:\n        for ticker in context.tickers:\n            order_percent(symbol(ticker), 1 \/ len(tickers))\n\n    context.day += 1\n\nimport matplotlib.pyplot as plt\n\ncapital_base = 1e6 \n\ndef analyze(context, results):\n\n    fig = plt.figure()\n    ax1 = fig.add_subplot(111)\n    results&#91;'benchmark_cum'] = results.benchmark_return.add(1).cumprod() * capital_base\n    results&#91;&#91;'portfolio_value', 'benchmark_cum']].plot(ax = ax1, label = 'Portfolio Value($)')\n    ax1.set_ylabel('Portfolio value (TWD)')\n\n    plt.legend(loc = 'upper left')\n\n    plt.gcf().set_size_inches(18, 8)\n    plt.grid()\n    plt.show()\n\nfrom zipline import run_algorithm\n\nstart_date = pd.Timestamp('20230703', tz = 'utc')\nend_date = pd.Timestamp('20240702', tz = 'utc')\n\nresults = run_algorithm(\n    start = start_date,\n    end = end_date,\n    initialize = initialize,\n    handle_data = handle_data,\n    analyze = analyze,\n    bundle = 'tquant',\n    capital_base = capital_base,\n)\n\nresults<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img decoding=\"async\" width=\"1467\" height=\"630\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/portfolio_value-1.png\" alt=\"Running TQuant Lab in Google Colab \" class=\"wp-image-29384\" srcset=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/portfolio_value-1.png 1467w, https:\/\/www.tejwin.com\/wp-content\/uploads\/portfolio_value-1-300x129.png 300w, https:\/\/www.tejwin.com\/wp-content\/uploads\/portfolio_value-1-1024x440.png 1024w, https:\/\/www.tejwin.com\/wp-content\/uploads\/portfolio_value-1-150x64.png 150w, https:\/\/www.tejwin.com\/wp-content\/uploads\/portfolio_value-1-768x330.png 768w\" sizes=\"(max-width: 1467px) 100vw, 1467px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Font_Issues_Encountered_with_Pyfolio_and_How_to_Resolve_Them\"><\/span>Font Issues Encountered with Pyfolio and How to Resolve Them<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>from pyfolio.utils import extract_rets_pos_txn_from_zipline\nimport pyfolio as pf\n\nreturns, positions, transactions = extract_rets_pos_txn_from_zipline(results) \nbenchmark_rets = results.benchmark_return \n\nfrom pyfolio.plotting import plot_rolling_sharpe\n\nplot_rolling_sharpe(returns, factor_returns=benchmark_rets)<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><mark><span style=\"background-color:#abb8c3\" class=\"has-inline-background\">WARNING:matplotlib.font_manager:findfont: Generic family 'sans-serif' not found because none of the following families were found: Microsoft JhengHei\nWARNING:matplotlib.font_manager:findfont: Generic family 'sans-serif' not found because none of the following families were found: Microsoft JhengHei\nWARNING:matplotlib.font_manager:findfont: Generic family 'sans-serif' not found because none of the following families were found: Microsoft JhengHei\nWARNING:matplotlib.font_manager:findfont: Generic family 'sans-serif' not found because none of the following families were found: Microsoft JhengHei\nWARNING:matplotlib.font_manager:findfont: Generic family 'sans-serif' not found because none of the following families were found: Microsoft JhengHei<\/span><\/mark><\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"716\" height=\"512\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/sharpe-3.png\" alt=\"Running TQuant Lab in Google Colab \" class=\"wp-image-29386\" srcset=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/sharpe-3.png 716w, https:\/\/www.tejwin.com\/wp-content\/uploads\/sharpe-3-300x215.png 300w, https:\/\/www.tejwin.com\/wp-content\/uploads\/sharpe-3-150x107.png 150w\" sizes=\"(max-width: 716px) 100vw, 716px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Even_though_the_charts_have_been_successfully_plotted_you_may_still_encounter_warnings_about_missing_fonts_To_resolve_this_issue_you_can_manually_load_the_fonts\"><\/span>Even though the charts have been successfully plotted, you may still encounter warnings about missing fonts. To resolve this issue, you can manually load the fonts.<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>import matplotlib\nimport matplotlib.font_manager as fm\n!wget -O MicrosoftJhengHei.ttf https:\/\/github.com\/a7532ariel\/ms-web\/raw\/master\/Microsoft-JhengHei.ttf\n!wget -O ArialUnicodeMS.ttf https:\/\/github.com\/texttechnologylab\/DHd2019BoA\/raw\/master\/fonts\/Arial%20Unicode%20MS.TTF\n \nfm.fontManager.addfont('MicrosoftJhengHei.ttf')\nmatplotlib.rc('font', family='Microsoft Jheng Hei')\n \nfm.fontManager.addfont('ArialUnicodeMS.ttf')\nmatplotlib.rc('font', family='Arial Unicode MS')<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"After_trying_again_the_warning_messages_should_no_longer_appear\"><\/span>After trying again, the warning messages should no longer appear.<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>plot_rolling_sharpe(returns, factor_returns=benchmark_rets)<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"716\" height=\"512\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/sharpe-4.png\" alt=\"Running TQuant Lab in Google Colab \" class=\"wp-image-29388\" srcset=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/sharpe-4.png 716w, https:\/\/www.tejwin.com\/wp-content\/uploads\/sharpe-4-300x215.png 300w, https:\/\/www.tejwin.com\/wp-content\/uploads\/sharpe-4-150x107.png 150w\" sizes=\"(max-width: 716px) 100vw, 716px\" \/><\/figure>\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>This introduction&#8217;s testing section mostly references the code from the article \u201c<a href=\"https:\/\/www.tejwin.com\/en\/insight\/buffetts-business-investment-rules\/\" class=\"ek-link\">TQuant Lab Warren E. Buffett&#8217;s Business Investment Rules<\/a>.&#8221; You can refer to the original extended reading content if you have any questions.<\/p>\n\n\n\n<p>Additionally, this introduction allows everyone to use TQuant without needing extra virtual environment installations and extensive settings. It\u2019s much more convenient to get started right away and follow this recommended approach.<\/p>\n\n\n\n<div style=\"border: 1px black; border-style: solid none; text-align: center; border-color: #296580; padding: 24px; margin-top: 24px; margin-bottom: 24px;\">\n<p>\u3010TQuant Lab Backtesting System\u3011Solving Your Quantitative Finance Challenges<\/p>\n<p>Providing Comprehensive Tools for Trading Backtesting<\/p>\n<div style=\"margin-top: 32px;\"><a style=\"border: none; border-radius: 4px; background-color: #296580; color: white; font-size: 20px; width: fit-content; text-decoration: none; padding: 12px 30px 12px 30px;\" href=\"https:\/\/tquant.tejwin.com\/\" target=\"_blank\" rel=\"noopener\">Click Here to Register and Start Your Free Trial<\/a><\/div>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Source_Code\"><\/span>Source Code<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a class=\"ek-link\" href=\"https:\/\/github.com\/tejtw\/TEJAPI_Python_Medium_Application\/blob\/main\/Buffett&#039;s%20Business%20Investment%20Rules.ipynb\" target=\"_blank\" rel=\"noreferrer noopener\">C<\/a><a href=\"https:\/\/github.com\/tejtw\/TEJAPI_Python_Medium_Quant\/blob\/main\/Google%20Colab%20%E6%95%99%E5%AD%B8.ipynb\" target=\"_blank\" rel=\"noreferrer noopener\">lick Here to Github<\/a><\/li>\n<\/ul>\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<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/github.com\/tejtw\/TQuant-Lab\/blob\/main\/lecture\/Install%20TQuant%20Lab.ipynb\" class=\"ek-link\" target=\"_blank\" rel=\"noopener\">Install TQuant Lab<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/github.com\/tejtw\/TEJAPI_Python_Medium_Application\/blob\/main\/%E5%B7%B4%E8%8F%B2%E7%89%B9%E4%BC%81%E6%A5%AD%E6%8A%95%E8%B3%87%E6%B3%95%E5%89%87%E9%81%B8%E8%82%A1%E7%AD%96%E7%95%A5.ipynb\" class=\"ek-link\" target=\"_blank\" rel=\"noopener\">Buffett&#8217;s Business Investment Rules<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Relevant_Links\"><\/span>Relevant Links<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.tejwin.com\/en\/\" class=\"ek-link\">TEJ Official Website<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/github.com\/tejtw\/TQuant-Lab\" target=\"_blank\" rel=\"noreferrer noopener\" class=\"ek-link\">TQuant Lab Github<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/tquant.tejwin.com\/\" class=\"ek-link\" target=\"_blank\" rel=\"noopener\">TQuant Lab Homepage<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>For students who want to use TQuant Lab, in addition to the original GitHub installation tutorial, we now offer a faster and simpler way to use it directly on Google Colab. The tutorial on running TQuant Lab in Google Colab eliminates the need to set up a virtual environment, significantly lowering the barrier to entry.<\/p>\n","protected":false},"featured_media":25218,"template":"","tags":[3006,3166],"insight-category":[690,50,1356],"class_list":["post-25211","insight","type-insight","status-publish","has-post-thumbnail","hentry","tag-tejapi-beginners-guide","tag-tquant-lab-2","insight-category-data-analysis","insight-category-fintech","insight-category-tquant-lab-en"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/insight\/25211","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":14,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/insight\/25211\/revisions"}],"predecessor-version":[{"id":32669,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/insight\/25211\/revisions\/32669"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/media\/25218"}],"wp:attachment":[{"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/media?parent=25211"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/tags?post=25211"},{"taxonomy":"insight-category","embeddable":true,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/insight-category?post=25211"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}