请 [注册] 或 [登录]  | 返回主站

量化交易吧 /  量化平台 帖子:3364737 新帖:1

最近一年涨停个股流通市值分布

有事您说话发表于:5 月 13 日 16:37回复(1)

通过量化分析,涨停个股大部分布在 流通市值 < 50亿。

刚开始量化学习,感觉重要的是数据分析的逻辑。

在这里,感谢拉姆达投资的帖子,给了我数据处理学习很多启示。

import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
from jqdata import *
plt.style.use('fivethirtyeight')
pd.set_option('display.max_rows',10)
stock_all = get_all_securities(types=['stock'], date=None)
stock_list = stock_all.index.tolist()
len(stock_list)
3690
input_date = '2019-05-10'
# 工具函数

def filter_st(stocks,date):
   
    st_data = get_extras('is_st',stocks, count=1,end_date=date)
    stocks = [stock for stock in stocks if not st_data[stock][0]]
    
    return stocks

def find_close_limit_stock(stocks,date):

    h_limit_stocks = []

    df = get_price(stocks, end_date=date,frequency='daily', fq='pre',\
                   fields=['close','volume','high_limit','low_limit'],count = 1).iloc[:,0,:]
    
    df.query('volume != 0',inplace=True)

    df['is_high_limit']=(df['close']==df['high_limit'])

    h_limit_stocks = [df.index[i] for i in range(len(df)) if (df.is_high_limit[i])]
     
    return  h_limit_stocks

#MAD
def filter_extreme_MAD(series,n): 
    median = series.quantile(0.50)
    new_median = ((series - median).abs()).quantile(0.50)
    max_range = median + n*new_median
    min_range = median - n*new_median
    return np.clip(series,min_range,max_range)

# change list in list to list 
func_flat_list = lambda l: [item for sublist in l for item in sublist]
stock_non_st_list= filter_st(stock_list,input_date)
len(stock_non_st_list)
3527
trade_days = get_trade_days(end_date=input_date, count=250)
len(trade_days)
250
# 运行需要点时间
high_limit_list =[]

for date in trade_days:
    h = find_close_limit_stock(stock_non_st_list,date)
    high_limit_list.append(h)
/opt/conda/lib/python3.6/site-packages/jqresearch/api.py:87: FutureWarning: 
Panel is deprecated and will be removed in a future version.
The recommended way to represent these types of 3-dimensional data are with a MultiIndex on a DataFrame, via the Panel.to_frame() method
Alternatively, you can use the xarray package http://xarray.pydata.org/en/stable/.
Pandas provides a `.to_xarray()` method to help automate this conversion.

  pre_factor_ref_date=_get_today())
limit_stocks_year_list = set(func_flat_list(high_limit_list))
len(limit_stocks_year_list)
2745
stock_df = get_fundamentals(
    query(
        valuation.code, valuation.circulating_market_cap
    ).filter(
        valuation.code.in_(limit_stocks_year_list)
    ), date = input_date)
stock_df.dropna(how='any',inplace=True)
stock_df.shape
(2743, 2)
stock_df.circulating_market_cap.plot(figsize=(16,4),legend=True)
plt.axhline(stock_df.circulating_market_cap.mean(), color='red',linewidth=2,linestyle='--')
plt.show()
stock_df['circulating_market_cap'].describe()
count    2743.000000
mean       75.185018
std       200.894003
min         2.648600
25%        18.683100
50%        32.857400
75%        64.270850
max      5414.117700
Name: circulating_market_cap, dtype: float64
market_df = stock_df.copy()
market_df['fs_circulating_market_cap'] = filter_extreme_MAD(stock_df['circulating_market_cap'],5)
market_df.drop_duplicates(subset='fs_circulating_market_cap',inplace=True)
market_df = market_df[market_df['circulating_market_cap'] == market_df['fs_circulating_market_cap']]
market_df.drop(['circulating_market_cap'],axis=1,inplace=True)
market_df.shape
(2427, 2)
sns.distplot(market_df.fs_circulating_market_cap,bins=20)
<matplotlib.axes._subplots.AxesSubplot at 0x7f45123cacf8>
market_df.fs_circulating_market_cap.describe()
count    2427.000000
mean       36.760586
std        26.517044
min         2.648600
25%        17.092350
50%        28.852600
75%        49.666900
max       124.430000
Name: fs_circulating_market_cap, dtype: float64

全部回复

0/140

量化课程

    移动端课程