1 Star 1 Fork 0

郭少强/deeplearning-note

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
stck.ipynb 57.43 KB
一键复制 编辑 原始数据 按行查看 历史
Mario Cho 提交于 6年前 . Create stck.ipynb
%matplotlib inline
import pandas as pd
import numpy as np
import tushare as ts
import matplotlib.pyplot as plt
from setting import get_engine
api = ts.get_apis()
df = ts.bar('300144',conn=api,start_date='2018-01-01')
df.head()
code open close high low vol amount
datetime
2018-03-29 300144 19.88 20.16 20.19 19.88 15050.0 30236284.0
2018-03-28 300144 20.26 19.86 20.63 19.85 142126.0 286976928.0
2018-03-27 300144 19.95 20.40 20.50 19.84 125721.0 254512320.0
2018-03-26 300144 19.22 19.69 19.79 19.05 95743.0 186872368.0
2018-03-23 300144 19.11 19.20 19.80 19.06 112123.0 216926128.0
closed = df['close']
closed
datetime
2018-03-29    20.16
2018-03-28    19.86
2018-03-27    20.40
2018-03-26    19.69
2018-03-23    19.20
2018-03-22    19.68
2018-03-21    19.81
2018-03-20    20.45
2018-03-19    20.09
2018-03-16    19.90
2018-03-15    20.29
2018-03-14    20.25
2018-03-13    20.64
2018-03-12    20.50
2018-03-09    20.59
2018-03-08    19.61
2018-03-07    19.75
2018-03-06    19.55
2018-03-05    19.39
2018-03-02    19.16
2018-03-01    19.63
2018-02-28    19.66
2018-02-27    19.46
2018-02-26    19.31
2018-02-23    19.12
2018-02-22    19.06
2018-02-14    18.50
2018-02-13    18.57
2018-02-12    18.72
2018-02-09    17.98
2018-02-08    18.69
2018-02-07    18.37
2018-02-06    17.67
2018-02-05    18.78
2018-02-02    18.87
2018-02-01    18.38
2018-01-31    18.45
2018-01-30    19.19
2018-01-29    19.24
2018-01-26    19.50
2018-01-25    19.41
2018-01-24    19.54
2018-01-23    18.44
2018-01-22    18.64
2018-01-19    18.05
2018-01-18    18.13
2018-01-17    18.30
2018-01-16    17.98
2018-01-15    17.82
2018-01-12    18.18
2018-01-11    18.27
2018-01-10    18.30
2018-01-09    18.50
2018-01-08    18.68
2018-01-05    18.82
2018-01-04    18.87
2018-01-03    18.78
2018-01-02    18.56
Name: close, dtype: float64
year_closed = closed.resample('w',how='ohlc')
c:\python27\lib\site-packages\ipykernel_launcher.py:1: FutureWarning: how in .resample() is deprecated
the new syntax is .resample(...).ohlc()
  """Entry point for launching an IPython kernel.
year_closed
open high low close
datetime
2018-01-07 18.56 18.87 18.56 18.82
2018-01-14 18.68 18.68 18.18 18.18
2018-01-21 17.82 18.30 17.82 18.05
2018-01-28 18.64 19.54 18.44 19.50
2018-02-04 19.24 19.24 18.38 18.87
2018-02-11 18.78 18.78 17.67 17.98
2018-02-18 18.72 18.72 18.50 18.50
2018-02-25 19.06 19.12 19.06 19.12
2018-03-04 19.31 19.66 19.16 19.16
2018-03-11 19.39 20.59 19.39 20.59
2018-03-18 20.50 20.64 19.90 19.90
2018-03-25 20.09 20.45 19.20 19.20
2018-04-01 19.69 20.40 19.69 20.16
apt = (year_closed.high-year_closed.low)/year_closed.low*100
apt
datetime
2018-01-07    1.670259
2018-01-14    2.750275
2018-01-21    2.693603
2018-01-28    5.965293
2018-02-04    4.678999
2018-02-11    6.281834
2018-02-18    1.189189
2018-02-25    0.314795
2018-03-04    2.609603
2018-03-11    6.188757
2018-03-18    3.718593
2018-03-25    6.510417
Freq: W-SUN, dtype: float64
df=df.dropna(axis=0)
df['close']
datetime
2018-03-29    20.16
2018-03-28    19.86
2018-03-27    20.40
2018-03-26    19.69
2018-03-23    19.20
2018-03-22    19.68
2018-03-21    19.81
2018-03-20    20.45
2018-03-19    20.09
2018-03-16    19.90
2018-03-15    20.29
2018-03-14    20.25
2018-03-13    20.64
2018-03-12    20.50
2018-03-09    20.59
2018-03-08    19.61
2018-03-07    19.75
2018-03-06    19.55
2018-03-05    19.39
2018-03-02    19.16
2018-03-01    19.63
2018-02-28    19.66
2018-02-27    19.46
2018-02-26    19.31
2018-02-23    19.12
2018-02-22    19.06
2018-02-14    18.50
2018-02-13    18.57
2018-02-12    18.72
2018-02-09    17.98
2018-02-08    18.69
2018-02-07    18.37
2018-02-06    17.67
2018-02-05    18.78
2018-02-02    18.87
2018-02-01    18.38
2018-01-31    18.45
2018-01-30    19.19
2018-01-29    19.24
2018-01-26    19.50
2018-01-25    19.41
2018-01-24    19.54
2018-01-23    18.44
2018-01-22    18.64
2018-01-19    18.05
2018-01-18    18.13
2018-01-17    18.30
2018-01-16    17.98
2018-01-15    17.82
2018-01-12    18.18
2018-01-11    18.27
2018-01-10    18.30
2018-01-09    18.50
2018-01-08    18.68
2018-01-05    18.82
2018-01-04    18.87
2018-01-03    18.78
2018-01-02    18.56
Name: close, dtype: float64
df['close'].plot()
<matplotlib.axes._subplots.AxesSubplot at 0x83cb850>
engine =get_engine('db_zdt')
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-62-37327cb8c862> in <module>()
----> 1 year_closed.plot()

/usr/local/lib/python2.7/dist-packages/pandas/plotting/_core.pyc in __call__(self, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
   2675                           fontsize=fontsize, colormap=colormap, table=table,
   2676                           yerr=yerr, xerr=xerr, secondary_y=secondary_y,
-> 2677                           sort_columns=sort_columns, **kwds)
   2678     __call__.__doc__ = plot_frame.__doc__
   2679 

/usr/local/lib/python2.7/dist-packages/pandas/plotting/_core.pyc in plot_frame(data, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
   1900                  yerr=yerr, xerr=xerr,
   1901                  secondary_y=secondary_y, sort_columns=sort_columns,
-> 1902                  **kwds)
   1903 
   1904 

/usr/local/lib/python2.7/dist-packages/pandas/plotting/_core.pyc in _plot(data, x, y, subplots, ax, kind, **kwds)
   1725                             pass
   1726                 data = series
-> 1727         plot_obj = klass(data, subplots=subplots, ax=ax, kind=kind, **kwds)
   1728 
   1729     plot_obj.generate()

/usr/local/lib/python2.7/dist-packages/pandas/plotting/_core.pyc in __init__(self, data, **kwargs)
    929 
    930     def __init__(self, data, **kwargs):
--> 931         MPLPlot.__init__(self, data, **kwargs)
    932         if self.stacked:
    933             self.data = self.data.fillna(value=0)

/usr/local/lib/python2.7/dist-packages/pandas/plotting/_core.pyc in __init__(self, data, kind, by, subplots, sharex, sharey, use_index, figsize, grid, legend, rot, ax, fig, title, xlim, ylim, xticks, yticks, sort_columns, fontsize, secondary_y, colormap, table, layout, **kwds)
     98                  table=False, layout=None, **kwds):
     99 
--> 100         _converter._WARN = False
    101         self.data = data
    102         self.by = by

NameError: global name '_converter' is not defined
from filter_stock import Filter_Stock
obj = Filter_Stock()
df = obj.get_new_stock('2015','2015')
df.head()
code name industry area pe outstanding totals totalAssets liquidAssets fixedAssets ... bvps pb undp perundp rev profit gpr npr holders 更新日期
timeToMarket
2018-05-25 300746 N汉嘉 建筑施工 浙江 36.00 0.53 2.10 84655.75 62115.23 15889.55 ... 3.87 2.09 29412.24 1.40 0.00 0.00 18.70 6.51 100201.0 2018-05-25
2017-05-05 300643 万通智控 汽车配件 浙江 1991.42 0.71 2.00 48480.46 35851.01 9471.17 ... 2.07 8.77 6885.06 0.34 -4.54 -94.65 26.56 0.74 17863.0 2018-05-25
2018-05-23 300745 欣锐科技 汽车配件 深圳 20.66 0.29 1.15 112515.45 98528.06 8233.80 ... 8.48 2.40 28390.36 2.48 0.00 0.00 29.77 18.97 56498.0 2018-05-25
2017-01-11 300580 贝斯特 汽车配件 江苏 33.83 0.66 2.00 153087.30 79671.81 51525.51 ... 6.43 3.32 35882.65 1.79 22.17 2.29 37.93 17.82 21940.0 2018-05-25
2017-11-06 300720 海川智能 电器仪表 广东 114.29 0.18 0.72 46308.18 32482.15 9548.55 ... 5.94 6.23 14848.82 2.06 0.00 0.00 55.91 22.28 12821.0 2018-05-25

5 rows × 23 columns

ret_df = df[(df['pe']< 50) & (df['pe']>0)].sort_values(by='pe',ascending=True)
f = open('new_stock.txt','w')
for i in df['code'].values:
    f.write(i)
    f.write('\n')
f.close()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/guo_shaoqiang/deeplearning-note.git
git@gitee.com:guo_shaoqiang/deeplearning-note.git
guo_shaoqiang
deeplearning-note
deeplearning-note
master

搜索帮助