{"id":13488438,"url":"https://github.com/foolcage/fooltrader","last_synced_at":"2025-05-15T15:04:18.018Z","repository":{"id":28574288,"uuid":"104978050","full_name":"foolcage/fooltrader","owner":"foolcage","description":"quant framework for stock","archived":false,"fork":false,"pushed_at":"2023-05-22T21:34:18.000Z","size":6346,"stargazers_count":1158,"open_issues_count":6,"forks_count":328,"subscribers_count":122,"default_branch":"master","last_synced_at":"2025-05-06T18:04:20.621Z","etag":null,"topics":["cryptocurrency","fintech","fundamental-analysis","quant","stock","stock-market","technical-analysis","trading-platform"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/foolcage.png","metadata":{"files":{"readme":"README-en.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2017-09-27T05:58:38.000Z","updated_at":"2025-05-06T10:18:02.000Z","dependencies_parsed_at":"2022-09-02T11:01:05.958Z","dependency_job_id":null,"html_url":"https://github.com/foolcage/fooltrader","commit_stats":{"total_commits":329,"total_committers":9,"mean_commits":36.55555555555556,"dds":0.3708206686930091,"last_synced_commit":"83d66d0c52631d0f714531a425cf1de4b4956d02"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foolcage%2Ffooltrader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foolcage%2Ffooltrader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foolcage%2Ffooltrader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foolcage%2Ffooltrader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/foolcage","download_url":"https://codeload.github.com/foolcage/fooltrader/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254364270,"owners_count":22058878,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cryptocurrency","fintech","fundamental-analysis","quant","stock","stock-market","technical-analysis","trading-platform"],"created_at":"2024-07-31T18:01:15.669Z","updated_at":"2025-05-15T15:04:17.993Z","avatar_url":"https://github.com/foolcage.png","language":"Python","readme":"[![Build Status](https://travis-ci.org/foolcage/fooltrader.svg?branch=master)](https://travis-ci.org/foolcage/fooltrader)\n\n## This project is deprecated, please move on to the new project [https://github.com/zvtvz/zvt](https://github.com/zvtvz/zvt)\n\n**Read this in other languages: [中文](README.md).**  \n# fooltrader:trade as a fool\n\u003e\"To survive in the market, you must stay away from being smart because your intelligence is worthless in the market\"------zen in chaos\n\n# 1. Screenshots\n## 1.1 **China stock fundamentals analysis**  \n![](./screenshots/profit_price.gif)\n\u003eEnter the stocks you are interested in to see the relationship between their net profit and the stock price, maybe you will not think that the \"fundamental\" useless?  \nFor example: Vanke's profit has been growing rapidly, but cabbage price pressure for several years, so 'barbarians' came...  \nAnd you could calculate the entire market stocks using fooltrader, and automatically notify you, in fact, is not that difficult.  \n\n## 1.2 **USA stock fundamentals analysis**  \n![](./screenshots/usa-profit-price.gif)\n\u003eTake a look at the performance of US stocks how? The operation is uniform.   \n\n## 1.3 **Back test**  \nYou could write the Strategy using  event-driven or time walk way, and view and analyze the performance in uniform way.  \nSee the [*design doc*](./docs/trader.md)  \n```python\nclass EventTrader(Trader):\n    def on_init(self):\n        self.trader_id = 'aa'\n        self.only_event_mode = True\n        self.universe = ['stock_sz_000338']\n        self.df_map = {}\n\n    def on_day_bar(self, bar_item):\n        current_security = bar_item['securityId']\n        current_df = self.df_map.get(current_security, pd.DataFrame())\n        if current_df.empty:\n            self.df_map[current_security] = current_df\n\n        current_df = current_df.append(bar_item, ignore_index=True)\n        self.df_map[current_security] = current_df\n\n        if len(current_df.index) == 10:\n            ma5 = np.mean(current_df.loc[5:, 'close'])\n            ma10 = np.mean(current_df.loc[:, 'close'])\n            # buy when ma5 \u003e ma10\n            if ma5 \u003e ma10 and not self.account_service.get_position(current_security):\n                self.buy(security_id=current_security, current_price=bar_item['close'])\n            # buy when ma5 \u003c ma10\n            elif ma5 \u003c ma10 and self.account_service.get_position(current_security):\n                self.sell(security_id=current_security, current_price=bar_item['close'])\n            current_df = current_df.loc[1:, ]\n            self.df_map[current_security] = current_df\n```\n\nRunning strategy can view the results in real time, and make further assessment  \n![](./screenshots/trader.gif)\n\n## 1.4 **General trend dashboard**\n![](./screenshots/analyze1.png)  \n\n## 1.5 **gdp and market value comparison**\n![](./screenshots/gdp_cap.png)  \n\u003eAs long as the total market capitalization is close to GDP, it is basically the top.   \nAnd From another perspective look,the total market capitalization is impossible always far below GDP.  \n\n## 1.6 **GEM(similar to nasdaq) PE analysis**\n![](./screenshots/cyb_pe.png)\n\u003e17.94% of the time in 20-40, 50.7% of the time in the 40-70, 26.67% of the time in the 70-100, 4.69% of the time in 100 or more.  \nSo thinking about gemp PE about 40 or so \"Valuation\" high and bearish it, doomed to not enjoy the 2015-year GEM bull market  \n\n## 1.7 **Global market PE comparison**  \n![](./screenshots/china-usa-pe.png)\n\u003eGEM\u003esmall board\u003eshenzhen\u003eS \u0026 P\u003eSSE?Maybe need a little imagination, the style is also convertible?  \nWell, the average PE of S \u0026 P has also exceeded 120, which is still slightly lower than that of our big GEM.  \nNow,the PE of the SSE is actually lower than that of the S \u0026 P, so?  \n\n# 2. Introduction\nfooltrader is a Quantitative Trading System designed with **big data** technology to capture, clean, structure, calculate, display, backtesting and trading.   \nIts goal is to provide a unified framework for conducting research, backtesting, forecasting, and trading on * entire markets * (equities, futures, bonds, foreign exchange, digital currencies, macroeconomics, etc.)  \nSuitable for: ***Quantitative traders, financial professionals, people who are interested in economic data, programmers, people who like freedom and exploration***  \n\n# 3. Architecture diagram\nfooltrader is a well-structured modular system that you can use at different levels, as well as extend, transform, or replace the modules inside.  \n\n![](./screenshots/architecture-en.png)\n\n# 4. use step by step\nThe hierarchy of usage is one-to-one with the modules in the architecture diagram.  \nYou can stop at any step, expand or replace with your own familiar system.  \nOf course, I still hope that you will run all the way, because the technical selection of each module here has been carefully considered, and the system is in active developing.  \n\n### 4.1 Environment preparation  \nOS:Ubuntu 16.04.3 LTS  \nIn principle, the system-specific components are cross-platform, but I only test on ubuntu and mac  \nMemory:\u003e16G  \nDisk:The bigger the better  \nclone or fork the code    \n```bash\n$ git clone https://github.com/foolcage/fooltrader.git\n```\n### 4.2 init python env\n```bash\n$ cd fooltrader\n$ ./init_env.sh\n```\n\nif you could see:  \n```bash\nRequirements installed.  \nenv ok\n```\nCongratulation! Now you could play with fooltrader  \n### 4.3 crawl the data  \n```bash\n$ source ve/bin/activate\n$ ./ve/bin/ipython\nIn [1]: from fooltrader.datamanager import datamanager\n#crawl stock meta data\nIn [2]: datamanager.crawl_stock_meta()\n#crawl index data\nIn [3]: datamanager.crawl_index_quote()\n#crawl stock kdata and tick data\nIn [4]: datamanager.crawl_stock_quote(start_code='002797',end_code='002798',crawl_tick=False)\n#crawl finance data\nIn [5]: datamanager.crawl_finance_data(start_code='002797',end_code='002798')\n```\ncrawling data and the api is in different module:  \n\u003espiders focus on crawling things: speed of crawling, better data classification, data completion, handling ban, etc.\n\u003e api design only depends on [*data contract*](./docs/contract.md), which has better speed and flexibility\n\nYou can also download packaged historical data[*data.zip*](https://pan.baidu.com/s/1dmZaPo).\nAnd you need only crawl the incremental data:\n```bash\n$ ./sched_finance.sh\n```\n```bash\n$ ./sched_quote.sh\n```\nThe script periodically fetches \"missing\" data. After the historical data integrity check is passed, it just actually fetches the data of the day, so that we have a complete data source for automated self-maintenance.  \nScheduled tasks can be configured in the sched_quote.py file:  \nYou could set the\n```python\n@sched.scheduled_job('cron', hour=17, minute=00)\ndef scheduled_job1():\n    crawl_stock_quote('000001', '002999')\n    crawl_index_quote()\n\n\n@sched.scheduled_job('cron', hour=17, minute=20)\ndef scheduled_job2():\n    crawl_stock_quote('300000', '300999')\n\n\n@sched.scheduled_job('cron', hour=17, minute=40)\ndef scheduled_job3():\n    crawl_stock_quote('600000', '666666')\n```\n\nFinally, how to use the data crawled? Please refer to[*data contract*](./docs/contract.md)  \nAnd here, you could use your familiar system to anylyze the data,e.g,mysql,superset,redash,hadoop.  \nJust follow the data contract and write the connector, and I hope you could pr to me.  \n### 4.4 install elastic-search and kibana(6.1.1)  \n\u003eJust change the storage of the data, incredible change to the system happen.  \n\nfollow the official docs:https://www.elastic.co/guide/en/elastic-stack/current/installing-elastic-stack.html  \nor:  \n```bash\n$ wget https://artifacts.elastic.co/downloads/packs/x-pack/x-pack-6.1.1.zip\n$ wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.1.1.zip\n$ unzip elasticsearch-6.1.1.zip\n$ cd elasticsearch-6.1.1/\n$ bin/elasticsearch-plugin install file:///path/to/file/x-pack-6.1.1.zip\n$ cp ../fooltrader/config/elasticsearch.yml config/\n$ ES_JAVA_OPTS=\"-Xms8g -Xmx8g\"  ./bin/elasticsearch\n$\n$ wget https://artifacts.elastic.co/downloads/kibana/kibana-6.1.1-linux-x86_64.tar.gz\n$ tar -xzf kibana-6.1.1-linux-x86_64.tar.gz\n$ cd kibana-6.1.1-linux-x86_64/\n$ bin/kibana-plugin install file:///path/to/file/x-pack-6.1.1.zip\n$ cp ../fooltrader/config/kibana.yml config/\n$ ./bin/kibana\n```\n\n### 4.5 use es_connector to store the data to elastic-search  \nin the fooltrader ipython env  \n```bash\nIn [1]: from fooltrader.connector import es_connector\n#stock meta-\u003ees\nIn [2]: es_connector.stock_meta_to_es()\n#index data-\u003ees\nIn [3]: es_connector.index_kdata_to_es()\n#stock kdata-\u003ees\nIn [4]: es_connector.stock_kdata_to_es()\n#you could open several terminals to improve the index speed\nIn [4]: es_connector.stock_kdata_to_es(start='002000',end='002999')\n#finance data-\u003ees\nIn [5]: es_connector.balance_sheet_to_es()\nIn [5]: es_connector.income_statement_to_es()\nIn [5]: es_connector.cash_flow_statement_to_es()\n```\n\nThen, let's briefly enjoy its power  \nQuery the top 5 net profit of the interim report 2017  \n```bash\ncurl -XPOST 'localhost:9200/income_statement/doc/_search?pretty\u0026filter_path=hits.hits._source' -H 'Content-Type: application/json' -d'\n{\n  \"query\": {\n    \"range\": {\n      \"reportDate\": {\n        \"gte\": \"20170630\",\n        \"lte\": \"20170630\"\n      }\n    }\n  },\n  \"size\": 5,\n  \"sort\": [\n    {\n      \"netProfit\": {\n        \"order\": \"desc\"\n      }\n    }\n  ]\n}\n'\n{\n  \"hits\": {\n    \"hits\": [\n      {\n        \"_source\": {\n          \"exchangeGains\": 1.3242E10,\n          \"netProfit\": 1.827E9,\n          \"securityId\": \"stock_sh_601318\",\n          \"investmentIncome\": 2.0523E10,\n          \"operatingProfit\": 7.8107E10,\n          \"accumulatedOtherComprehensiveIncome\": 2.0E8,\n          \"attributableToMinorityShareholders\": 6.5548E10,\n          \"sellingExpenses\": 1.0777E10,\n          \"investmentIncomeFromRelatedEnterpriseAndJointlyOperating\": \"398259000000.00\",\n          \"id\": \"stock_sh_601318_20170630\",\n          \"minorityInterestIncome\": 6.238E10,\n          \"code\": \"601318\",\n          \"otherComprehensiveIncome\": 6.5506E10,\n          \"nonOperatingIncome\": 4.006E9,\n          \"financingExpenses\": 0.0,\n          \"reportEventDate\": \"2017-08-18\",\n          \"netProfitAttributedToParentCompanyOwner\": 5.778E10,\n          \"disposalLossOnNonCurrentLiability\": 9.01E8,\n          \"incomeFromChangesInFairValue\": -2.56E8,\n          \"incomeTaxExpense\": 2.2E7,\n          \"operatingTotalCosts\": 3.4139E11,\n          \"assetsDevaluation\": 8.75E8,\n          \"EPS\": 1.9449E10,\n          \"operatingCosts\": 9.4E7,\n          \"attributableToOwnersOfParentCompany\": 1.58E8,\n          \"ManagingCosts\": 6.402E10,\n          \"totalProfits\": 8.403E9,\n          \"dilutedEPS\": 2.4575E10,\n          \"reportDate\": \"20170630\",\n          \"businessTaxesAndSurcharges\": 9.442E9,\n          \"operatingRevenue\": 4.63765E11,\n          \"nonOperatingExpenditure\": 1.35892E11\n        }\n      ]\n    }\n  }\n}\n```\nIn fact we have the REST API naturally and could use your favourite language to anylyze.\nJust follow the [*data contract*](./docs/contract.md) and ES DSL.  \n\n### 4.6 Use kibana to anylyze\n(TBD)\n\n### 4.7 Backtesting\n(TBD)\n\n### 4.8 Trading\n(TBD)\n\n# TODO\n* Trading DSL design\n* WEB management interface, wizard-generated strategy\n* Real-time market and kafka real-time calculation\n* Integrated vnpy trading interface\n* Futures data capture\n* Hong Kong stock data capture\n\n# Contact information\nQQ group:300911873  \nif you like this project,please star it and tell me your github user name when joining the qq group  \ncheck http://www.imqq.com/html/FAQ_en/html/Discussions_3.html\n","funding_links":[],"categories":["Python","Research Tools","数据源","金融"],"sub_categories":["Arbitrage","Trading \u0026 Backtesting","交易与回测"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffoolcage%2Ffooltrader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffoolcage%2Ffooltrader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffoolcage%2Ffooltrader/lists"}