当前位置:网站首页>Microblogging hot search stock selection strategy
Microblogging hot search stock selection strategy
2022-07-06 04:49:00 【bluishfish】
Preface
This strategy stems from a small talk in the Group ,A Stocks are a magical market , Gu ailing wins the championship ,“ invengo ” Born in the sky ! While lamenting that investors' imagination is too rich , According to the hot search of Weibo , Grasp the next stock limit ? Don't ask for accuracy , Let's sort out the related technology implementation first .
Background information
source : China Securities News
Gu Ailing is really hot !
2 month 8 Japan , Gu ailing won the gold medal of Freestyle women's ski platform in the Winter Olympics . At that time , Swipe the screen in the circle of friends , Gu Ailing is even more popular in Weibo search . And here's the interesting thing , And Gu ailing A stocks “ Sub Valley ” Appearance —— Yuanwang Valley rare daily limit . Investors rushed to the investor interaction platform , It is suggested that the listed company sign a contract with Gu ailing .
2 month 8 The morning of , The women's Freestyle Ski platform final of the Beijing Winter Olympics was held at Shougang ski platform . People place high hopes on “ Genius girl ” Gu Ailing has lived up to expectations , In the third jump challenge, I never made a super difficult action to succeed , Put on a super reversal , In total 188.25 The score of points won the championship miraculously .
During Gu Ailing's competition , One was named “ invengo ” The stock suddenly changed . The Winter Olympics freestyle skiing women's platform final will take place on 10 when ,14 Minutes later, the stock price of Yuanwang valley began to rise suddenly ; stay 10 when 36 Minute limit , The stock price hit 8 Month high , As of the close , Yuanwang Valley newspaper 6.22 element , The total market value 46 One hundred million yuan .
Regarding this , Some shareholders of the stock bar joked : In Yuanwang Valley, I watched Gu ailing win the championship from a distance , I didn't expect the limit to rise ! It's like “ Gu ailing concept stock ”. There are also investors sighing : It's really difficult to speculate in stocks now , You have to learn to make sentences !
Get Weibo hot search words
The first is, of course, to get the hot search words of Weibo , For the convenience of back testing , It's better to have a historical record .
Find one API
, Let's climb a little
import pandas as pd
import requests
import json
date = "2022-02-09"
url = 'https://google-api.zhaoyizhe.com/google-api/index/mon/sec?date='+date
r = requests.get(url)
message = json.loads(r.content)
data = message['data']
weibo = pd.DataFrame(data)
weibo['pm'] = weibo['pm'].astype('int')
weibo = weibo.sort_values(by="pm").reset_index()
Emotional categories
because A There is no short selling mechanism for stocks , We need to eliminate negative information , So first make an emotional classification
from snownlp import SnowNLP
from snownlp import sentiment
def get_sentiments(text):
return SnowNLP(text).sentiments
weibo['sentiments'] = weibo['topic'].apply(get_sentiments)
weibo[(weibo['sentiments']>0.5) & (weibo['pm']<=3)]
among sentiments
The closer the 1, The more positive ; The closer the 0, The more negative .pm
Rank for hot search , Only the top three themes are selected here .
Get all stock names
The hot search topics here are relatively brief , No word bag model ,Tfidf
or Word2Vec
To calculate the text similarity , Use built-in difflib
It will be faster . If you want to match information such as the profile of listed companies , Data cleaning can be further done , Introduce stop words , Optimize the algorithm with a larger model .
import difflib
# Get all stock information
df = get_all_securities(types=['stock'], date=None)
def string_similar(s1, s2):
return difflib.SequenceMatcher(None, s1, s2).quick_ratio()
# Calculate similarity
df['similar'] = 0
for word in weibo[(weibo['sentiments']>0.5) & (weibo['pm']<=3)]['topic']:
df['similar'] += df['display_name'].apply(string_similar, args=(word,))
# Get the best match 10 Shares
df[df['similar']>0].sort_values(by="similar", ascending=False)[:10]
Calculate the similarity between the stock name and the hot search words every time , Accumulate all matching values , Then output in reverse order , Sure enough, I can see the legend in the first four " Trading stocks " 了 .
Data back testing
Strategy is very mindless , Get hot search words before opening every day , Then select the best match 10 Shares , Divide the funds into 10 Share purchase ; Sell all stocks that are not in the hot search the next day , Re match new shares .
Although this stock selection is too wonderful and unreasonable , But we still “ rigorous ” some , Do a back test with the data since this year .
Encapsulating utility functions
Encapsulate the obtained hot search data into a letter
List of stocks to be purchased
The main task before opening is to get ready , List of stocks to be purchased
## Run the function before opening
def before_market_open(context):
# Output run time
log.info(' Function run time (before_market_open):'+str(context.current_dt.time()))
# The maximum number of stocks bought per day
g.daily_buy_count = 10
g.sentiments = 0.5 # Emotional threshold
g.pm = 3 # Ranking threshold
date = context.current_dt
weibo = get_weibo(date.strftime('%Y-%m-%d'))
if weibo is not None:
df = get_all_securities(types=['stock'], date=None)
df['similar'] = 0
for word in weibo[(weibo['sentiments']>g.sentiments) & (weibo['pm']<=g.pm)]['topic']:
df['similar'] += df['display_name'].apply(string_similar, args=(word,))
# Get the purchase list
stocks = df[df['similar']>0].sort_values(by="similar", ascending=False)
stocks = stocks[:g.daily_buy_count].index
g.buy_list = list(stocks)
else:
g.buy_list = []
print(g.buy_list)
Buy sell
Sell stocks that are not in the stock pool , Then divide the cash equally , Full position purchase .
## Run the function at the opening
def market_open(context):
log.info(' Function run time (market_open):'+str(context.current_dt.time()))
# Sell stocks that are not in the stock pool
sell_list = set(context.portfolio.positions.keys()) - set(g.buy_list)
for stock in sell_list:
order_target_value(stock, 0)
# Get current cash , divide equally
if len(g.buy_list) > 0:
cash = context.portfolio.available_cash / len(g.buy_list)
for security in g.buy_list:
order_value(security, cash)
# Record this purchase
log.info("Buying %s" % (security))
This strategy is very radical and wild , I didn't expect to beat the index ......
Don't do this in actual combat , If you can provide a more perspective , Let more hot stocks come into view when choosing stocks , It should be all the purposes of this algorithm .
Source download
Relevant documents in this issue , Available in the public number “ Deep awakening ”, The background to reply :“trade03”, Get download link .
边栏推荐
- [detailed steps of FreeRTOS shift value for the first time]
- 关于es8316的音频爆破音的解决
- Introduction of several RS485 isolated communication schemes
- Vulnerability discovery - vulnerability probe type utilization and repair of web applications
- Zynq learning notes (3) - partial reconfiguration
- [Yu Yue education] reference materials of complex variable function and integral transformation of Northwestern Polytechnic University
- Redis 排查大 key 的4种方法,优化必备
- How does vs change the project type?
- Postman关联
- 驱动开发——第一个HelloDDK
猜你喜欢
JS quick start (II)
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
Codeforces Round #804 (Div. 2)
[05-1, 05-02, 05-03] network protocol
MPLS experiment
11. Intranet penetration and automatic refresh
Selection of slow motion function
[lgr-109] Luogu may race II & windy round 6
Sqlserver query results are not displayed in tabular form. How to modify them
图论的扩展
随机推荐
Bill Gates posted his 18-year-old resume and expected an annual salary of $12000 48 years ago
几种RS485隔离通讯的方案介绍
win10电脑系统里的视频不显示缩略图
Codeforces Round #804 (Div. 2)
Visio draw fan
Coreldraw2022 new version new function introduction cdr2022
[noip2008 improvement group] stupid monkey
canal同步mysql数据变化到kafka(centos部署)
Postman test report
Selection sort
Quatre méthodes de redis pour dépanner les grandes clés sont nécessaires pour optimiser
驱动开发——HelloWDM驱动
SQL injection vulnerability (MSSQL injection)
How does vs change the project type?
JS quick start (II)
[try to hack] John hash cracking tool
Postman管理测试用例
[HBZ share] reasons for slow addition and deletion of ArrayList and fast query
Excellent PM must experience these three levels of transformation!
Delete subsequence < daily question >