{"id":567,"date":"2024-07-03T19:02:00","date_gmt":"2024-07-03T11:02:00","guid":{"rendered":"http:\/\/123.60.176.65\/?p=567"},"modified":"2024-07-03T19:02:00","modified_gmt":"2024-07-03T11:02:00","slug":"ai%e9%a1%be%e6%8a%95%e9%ab%98%e7%ba%a7%e7%ad%96%e7%95%a5%e4%b9%8b%e4%b8%89%ef%bc%9a%e8%a9%b9%e5%a7%86%e6%96%af-%e5%a5%a5%e8%82%96%e5%86%85%e8%a5%bf%e7%9a%84%e4%bb%b7%e5%80%bc%e6%8a%95%e8%b5%84","status":"publish","type":"post","link":"https:\/\/laoyulaoyu.com\/index.php\/2024\/07\/03\/ai%e9%a1%be%e6%8a%95%e9%ab%98%e7%ba%a7%e7%ad%96%e7%95%a5%e4%b9%8b%e4%b8%89%ef%bc%9a%e8%a9%b9%e5%a7%86%e6%96%af-%e5%a5%a5%e8%82%96%e5%86%85%e8%a5%bf%e7%9a%84%e4%bb%b7%e5%80%bc%e6%8a%95%e8%b5%84\/","title":{"rendered":"AI\u987e\u6295\u9ad8\u7ea7\u7b56\u7565\u4e4b\u4e09\uff1a\u8a79\u59c6\u65af.\u5965\u8096\u5185\u897f\u7684\u4ef7\u503c\u6295\u8d44\u6cd5\uff08\u5efa\u8bae\u6536\u85cf\uff09"},"content":{"rendered":"<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img decoding=\"async\" src=\"http:\/\/123.60.176.65\/wp-content\/uploads\/2024\/06\/u875916278520691977fm253fmtautoapp138fJPEG.webp\" alt=\"\" class=\"wp-image-568\" style=\"width:645px;height:auto\"\/><\/figure>\n<\/div>\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<pre class=\"wp-block-verse\"><strong>&nbsp;\u5199\u5728\u524d\u9762\u7684\u8bdd\uff1a<\/strong>\u8a79\u59c6\u65af\u00b7\u5965\u8096\u5185\u897f\u662f\u4e00\u4f4d\u8457\u540d\u7684\u6295\u8d44\u8005\uff0c\u4ed6\u7684\u6295\u8d44\u65b9\u6cd5\u6df1\u53d7\u5b9a\u91cf\u5206\u6790\u7684\u5f71\u54cd\uff0c\u5c24\u5176\u662f\u5728\u4ef7\u503c\u6295\u8d44\u9886\u57df\u4e2d\u3002\u4ed6\u7684\u65b9\u6cd5\u901a\u8fc7\u4f7f\u7528\u5386\u53f2\u6570\u636e\u548c\u590d\u6742\u7684\u6570\u5b66\u6a21\u578b\u6765\u8bc6\u522b\u88ab\u4f4e\u4f30\u7684\u80a1\u7968\uff0c\u4ece\u800c\u5c1d\u8bd5\u7cfb\u7edf\u5730\u6218\u80dc\u5e02\u573a\u3002\u5965\u8096\u5185\u897f\u5728\u4ed6\u7684\u4e66\u7c4d\u548c\u7814\u7a76\u4e2d\u63d0\u51fa\u4e86\u51e0\u79cd\u7b56\u7565\uff0c\u5176\u4e2d\u6700\u8457\u540d\u7684\u662f\u201c\u600e\u6837\u51fb\u8d25\u5e02\u573a\u201d\uff08How to Beat the Market\uff09\u7cfb\u5217\u3002\u901a\u8fc7\u8fd9\u4e9b\u7b56\u7565\uff0c\u5965\u8096\u5185\u897f\u5e0c\u671b\u80fd\u627e\u5230\u5e02\u573a\u4e2d\u7684\u8bef\u4ef7\u80a1\u7968\uff0c\u5e76\u901a\u8fc7\u957f\u671f\u6301\u6709\u8fd9\u4e9b\u80a1\u7968\u83b7\u5f97\u8d85\u989d\u56de\u62a5\u3002<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">\u4ed6\u7684\u65b9\u6cd5\u4e3a\u4ef7\u503c\u6295\u8d44\u63d0\u4f9b\u4e86\u4e00\u79cd\u66f4\u79d1\u5b66\u3001\u7cfb\u7edf\u7684\u65b9\u5f0f\uff0c\u4f7f\u5176\u533a\u522b\u4e8e\u66f4\u4f20\u7edf\u7684\u3001\u4e3b\u89c2\u5224\u65ad\u8f83\u591a\u7684\u4ef7\u503c\u6295\u8d44\u7b56\u7565\u3002<\/mark><\/pre>\n<\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u5965\u8096\u5185\u897f\u7684\u72ec\u7279\u4e4b\u5904<\/strong>\uff1a<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u5b9a\u91cf\u65b9\u6cd5<\/strong>\uff1a\u4ed6\u5f3a\u8c03\u4f7f\u7528\u5ba2\u89c2\u3001\u53ef\u91cd\u590d\u7684\u65b9\u6cd5\u6765\u9009\u62e9\u80a1\u7968\uff0c\u51cf\u5c11\u4eba\u4e3a\u60c5\u611f\u548c\u504f\u89c1\u7684\u5f71\u54cd\u3002<\/li>\n\n\n\n<li><strong>\u591a\u56e0\u5b50\u6a21\u578b<\/strong>\uff1a\u4e0d\u53ea\u4f9d\u8d56\u5355\u4e00\u8d22\u52a1\u6307\u6807\uff0c\u800c\u662f\u7efc\u5408\u8003\u8651\u591a\u4e2a\u56e0\u7d20\u6765\u8bc4\u4f30\u80a1\u7968\u7684\u4ef7\u503c\u3002<\/li>\n\n\n\n<li><strong>\u5386\u53f2\u6570\u636e\u9a8c\u8bc1<\/strong>\uff1a\u4ed6\u7684\u6240\u6709\u7b56\u7565\u90fd\u57fa\u4e8e\u5386\u53f2\u6570\u636e\u7684\u5e7f\u6cdb\u6d4b\u8bd5\uff0c\u4ee5\u8bc1\u660e\u5176\u6709\u6548\u6027\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u901a\u8fc7\u8fd9\u4e9b\u7b56\u7565\uff0c\u5965\u8096\u5185\u897f\u5e0c\u671b\u80fd\u627e\u5230\u5e02\u573a\u4e2d\u7684\u8bef\u4ef7\u80a1\u7968\uff0c\u5e76\u901a\u8fc7\u957f\u671f\u6301\u6709\u8fd9\u4e9b\u80a1\u7968\u83b7\u5f97\u8d85\u989d\u56de\u62a5\u3002\u4ed6\u7684\u65b9\u6cd5\u4e3a\u4ef7\u503c\u6295\u8d44\u63d0\u4f9b\u4e86\u4e00\u79cd\u66f4\u79d1\u5b66\u3001\u7cfb\u7edf\u7684\u65b9\u5f0f\uff0c\u4f7f\u5176\u533a\u522b\u4e8e\u66f4\u4f20\u7edf\u7684\u3001\u4e3b\u89c2\u5224\u65ad\u8f83\u591a\u7684\u4ef7\u503c\u6295\u8d44\u7b56\u7565\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u7b97\u6cd5\u4ee3\u7801\u5982\u4e0b\uff1a<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>'''<br>\u7b56\u7565\u9009\u80a1<br>A. \u80a1\u7968\u7684\u5e02\u503c\u5927\u4e8e\u5e02\u573a\u7684\u4e2d\u4f4d\u6570<br>B. \u80a1\u7968\u7684\u80a1\u672c\u5927\u4e8e\u5e02\u573a\u7684\u4e2d\u4f4d\u6570<br>C. \u80a1\u7968\u7684\u5e02\u73b0\u7387\u5927\u4e8e0\uff0c\u4ece\u5c0f\u5230\u5927\u6392\u5217\uff0c\u53d6\u524d400\u53ea\u80a1\u7968<br>D. \u80a1\u7968\u7684\u5e02\u9500\u7387\u5927\u4e8e0\uff0c\u4ece\u5c0f\u5230\u5927\u6392\u5217\uff0c\u53d6\u524d400\u53ea\u80a1\u7968<br>E. \u80a1\u7968\u7684\u80a1\u606f\u7387\u4ece\u5927\u5230\u5c0f\u6392\u5217\uff0c\u53d6\u524d400\u53ea\u80a1\u7968<br>F. \u53d6\u4e0a\u8ff05\u4e2a\u6761\u4ef6\u6ee1\u8db3\u4e0b\u7684\u524d30\u53ea\u80a1\u7968<br>\u4ea4\u6613\u65b9\u5f0f\uff1a\u6309\u6708\u8c03\u4ed3<br>\u6b62\u635f\u65b9\u5f0f<br>A. \u5f53\u4e2a\u80a1\u4ef7\u683c\u4f4e\u4e8e\u6210\u672c\u4ef7\u76847%\u65f6\uff0c\u5356\u51fa\u8be5\u80a1\u7968<br>B. \u5f535\u65e5\u5185\u5927\u76d8\u4e0b\u8dcc13%\u65f6\uff0c\u5356\u51fa\u6240\u6709\u80a1\u7968<br><br>'''<br><br>from datetime import timedelta, date<br>import pandas as pd<br><br>############################## \u4ee5\u4e0b\u4e3a\u4e3b\u8981\u51fd\u6570 ################################<br># \u521d\u59cb\u5316\u51fd\u6570 ##################################################################<br><br>def init(context):<br> # \u8bbe\u7f6e\u624b\u7eed\u8d39\u4e3a\u4ea4\u6613\u989d\u76840.02%\uff0c\u6700\u5c115\u5143<br> set_commission(PerShare(type='stock', cost=0.0003, min_trade_cost=5.0))<br> # \u8bbe\u7f6e\u53ef\u53d8\u6ed1\u70b9\uff0c\u4e70\u5165\u6210\u4ea4\u4ef7 = \u59d4\u6258\u4ef7 * (1 + 0.1%)\uff0c\u5356\u51fa\u6210\u4ea4\u4ef7 = \u59d4\u6258\u4ef7 * (1 - 0.1%);<br> set_slippage(PriceSlippage(0.002))<br> context.selected = 400<br> context.n = 30 # \u6301\u80a1\u6570<br> context.trade_date = range(1,13,1)<br> ## \u6309\u6708\u8c03\u7528\u7a0b\u5e8f<br> run_monthly(trade,date_rule=-1)<br> <br># \u6708\u672b\u8c03\u4ed3\u51fd\u6570 #################################################################<br>def trade(context, bar_dict):<br> date = get_datetime()<br> months = get_datetime().month<br> if months in context.trade_date:<br> <br> <br> ##\u83b7\u5f97\u8d2d\u4e70\u80a1\u7968\u5217\u8868<br> market_cap_list = stocks_market_cap(context, bar_dict)<br> PCF_list = stocks_PCF(context, bar_dict)<br> PS_list = stocks_PS(context, bar_dict)<br> capitalization_list = stocks_capitalization(context, bar_dict)<br> DY_list = stocks_DY(context, bar_dict)<br> ## \u83b7\u5f97\u6ee1\u8db3\u6bcf\u79cd\u6761\u4ef6\u7684\u80a1\u7968\u6c60<br> stock_list = list(set(market_cap_list)&amp;set(PCF_list)&amp;set(PS_list)&amp;set(capitalization_list)&amp;set(DY_list))<br> log.info(len(stock_list))<br> <br> ## \u5356\u51fa<br> if len(context.portfolio.positions) &gt; 0:<br> for stock in list(context.portfolio.positions):<br> if stock not in stock_list:<br> order_target(stock, 0)<br> ## \u4e70\u5165<br> if len(stock_list) &gt; 0:<br> for stock in stock_list:<br> if stock not in list(context.portfolio.positions):<br> if len(context.portfolio.positions) &lt; context.n :<br> number = context.n - len(context.portfolio.positions)<br> order_value(stock,context.portfolio.available_cash\/number)<br> else: <br> order_value(stock,context.portfolio.available_cash)<br> <br> else:<br> pass<br><br># \u6bcf\u65e5\u68c0\u67e5\u6b62\u635f\u6761\u4ef6 ############################################################# <br>def handle_bar(context, bar_dict):<br> last_date = get_last_datetime().strftime('%Y%m%d')<br> <br> if len(context.portfolio.positions) &gt; 0:<br> # \u6b62\u635f\uff1a\u4e2a\u80a1\u8dcc\u5e45\u8d85\u8fc78%\uff0c\u5356\u51fa<br> securities = list(context.portfolio.positions)<br> for stock in securities:<br> price = history(stock, &#91;'close'], 1, '1d', False,'pre')<br> if context.portfolio.positions&#91;stock].cost_basis\/price&#91;'close']&#91;0]-1 &lt; -0.08:<br> order_target(stock, 0)<br> #log.info('%s \u6b62\u635f\uff1a%s' %(last_date,stock))<br> <br> #\u6b62\u635f\uff1a5\u5929\u5185\u5927\u76d8\u4e0b\u8dcc13%\uff0c\u5356\u51fa<br> price_bench = history('000300.SH', &#91;'close'], 5, '1d', False,'pre')<br> if price_bench&#91;'close']&#91;-5]\/price_bench&#91;'close']&#91;-1]-1 &gt; 0.13:<br> if len(list(context.portfolio.positions))&gt;0:<br> for stock in list(context.portfolio.positions):<br> order_target(stock, 0)<br><br>################## \u4ee5\u4e0b\u4e3a\u529f\u80fd\u51fd\u6570, \u5728\u4e3b\u8981\u51fd\u6570\u4e2d\u8c03\u7528 ##########################<br><br># 1 \u6839\u636e\u5e02\u503c\u6765\u7b5b\u9009\u80a1\u7968\u5217\u8868<br>def stocks_market_cap(context, bar_dict):<br> last_date = get_last_datetime().strftime('%Y%m%d')<br> market_cap = get_fundamentals(query(<br> valuation.symbol,<br> valuation.market_cap<br> ).order_by(<br> valuation.market_cap.desc()<br> ),date = last_date)<br> length = len(market_cap)<br> market_cap = market_cap&#91;:int(length\/2)]<br> return list(market_cap&#91;'valuation_symbol'])<br><br># 2. \u6839\u636e\u80a1\u672c\u6765\u7b5b\u9009\u80a1\u7968\u5217\u8868<br>def stocks_capitalization(context, bar_dict):<br> last_date = get_last_datetime().strftime('%Y%m%d')<br> capitalization = get_fundamentals(query(<br> valuation.symbol,<br> valuation.capitalization<br> ).order_by(<br> valuation.capitalization.desc()<br> ),date = last_date)<br> length = len(capitalization)<br> capitalization = capitalization&#91;:int(length\/2)]<br> return list(capitalization&#91;'valuation_symbol'])<br><br># 3. \u6839\u636e\u5e02\u73b0\u7387\u6765\u7b5b\u9009\u80a1\u7968\u5217\u8868<br>def stocks_PCF(context, bar_dict):<br> last_date = get_last_datetime().strftime('%Y%m%d')<br> PCF = get_fundamentals(query(<br> valuation.symbol,<br> valuation.pcf<br> ).filter(<br> valuation.pcf &gt; 0<br> ).order_by(<br> valuation.pcf.asc()<br> ).limit(<br> context.selected<br> ),date = last_date)<br> return list(PCF&#91;'valuation_symbol'])<br><br># 4. \u6839\u636e\u5e02\u9500\u7387\u6765\u7b5b\u9009\u80a1\u7968\u5217\u8868<br>def stocks_PS(context, bar_dict):<br> last_date = get_last_datetime().strftime('%Y%m%d')<br> PS = get_fundamentals(query(<br> valuation.symbol,<br> valuation.ps<br> ).filter(<br> valuation.ps&gt;0<br> ).order_by(<br> valuation.ps.asc() <br> ),date = last_date)<br> return list(PS&#91;'valuation_symbol'])<br><br># 5. \u6839\u636e\u80a1\u606f\u7387\uff08\u6bcf\u80a1\u6536\u76ca\/\u6bcf\u80a1\u5e02\u4ef7\u4ee3\u66ff\uff09\u6765\u7b5b\u9009\u80a1\u7968\u5217\u8868<br><br>def stocks_DY(context, bar_dict):<br> last_date = get_last_datetime().strftime('%Y%m%d')<br> EPS = get_fundamentals(query(<br> income.symbol,<br> income.basic_eps<br> ),date = last_date)<br> stock_List = list(EPS&#91;'income_symbol'])<br> close_price = history(stock_List,&#91;'close'],1,'1d',True,None)<br> DY_stock = dict(zip(EPS&#91;'income_symbol'],EPS&#91;'income_basic_eps']))<br> log.info(len(DY_stock)-len(EPS&#91;'income_symbol']))<br> for stock in stock_List:<br> try:<br> DY_stock&#91;stock] = DY_stock&#91;stock]\/close_price&#91;stock]&#91;'close']&#91;0]<br> except:<br> DY_stock&#91;stock] = 0<br> <br> DY_stock = sorted(DY_stock.items(),key=lambda t:t&#91;1],reverse=True) <br> return list(dict(DY_stock&#91;:context.selected]).keys())<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p class=\"has-text-align-center has-cyan-bluish-gray-color has-text-color has-link-color wp-elements-bd402b7c146898dcf3d05749282e5860\"><strong>\u672c\u6587\u5185\u5bb9\u4ec5\u4ec5\u662f\u6280\u672f\u63a2\u8ba8\u548c\u5b66\u4e60\uff0c\u5e76\u4e0d\u6784\u6210\u4efb\u4f55\u6295\u8d44\u5efa\u8bae\u3002<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp;\u5199\u5728\u524d\u9762\u7684\u8bdd\uff1a\u8a79\u59c6\u65af\u00b7\u5965\u8096\u5185\u897f\u662f\u4e00\u4f4d\u8457&#8230;<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"https:\/\/laoyulaoyu.com\/index.php\/2024\/07\/03\/ai%e9%a1%be%e6%8a%95%e9%ab%98%e7%ba%a7%e7%ad%96%e7%95%a5%e4%b9%8b%e4%b8%89%ef%bc%9a%e8%a9%b9%e5%a7%86%e6%96%af-%e5%a5%a5%e8%82%96%e5%86%85%e8%a5%bf%e7%9a%84%e4%bb%b7%e5%80%bc%e6%8a%95%e8%b5%84\/\">Continue reading<span class=\"screen-reader-text\">AI\u987e\u6295\u9ad8\u7ea7\u7b56\u7565\u4e4b\u4e09\uff1a\u8a79\u59c6\u65af.\u5965\u8096\u5185\u897f\u7684\u4ef7\u503c\u6295\u8d44\u6cd5\uff08\u5efa\u8bae\u6536\u85cf\uff09<\/span><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[4],"class_list":["post-567","post","type-post","status-publish","format-standard","hentry","category-aiinvest","tag-ai","entry"],"_links":{"self":[{"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/posts\/567","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/comments?post=567"}],"version-history":[{"count":0,"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/posts\/567\/revisions"}],"wp:attachment":[{"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/media?parent=567"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/categories?post=567"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/tags?post=567"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}