forked from Rockyzsu/stock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathipospeed.py
100 lines (85 loc) · 3.15 KB
/
ipospeed.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# -*-coding=utf-8-*-
__author__ = 'Rocky'
'''
http://30daydo.com
Contact: weigesysu@qq.com
'''
# 查看ipo速度 和指数的关系
import tushare as ts
from datetime import datetime
import pandas as pd
import numpy as np
from pandas import Series
import matplotlib.pyplot as plt
pd.set_option('display.max_rows', None)
class IPOSpeed():
def __init__(self):
self.ipo = ts.new_stocks()
# 日期转化
self.ipo['ipo_date'] = self.ipo['ipo_date'].astype('datetime64')
self.start = self.ipo['ipo_date'].iloc[-1]
self.end = self.ipo['ipo_date'].values[0]
# 转化类型
# ipo['ipo_date']=ipo['ipo_date'].astype('datetime64')
# self.start_d=datetime.datetime.strptime(self.start,'%Y-%m-%d')
# self.end_d=datetime.datetime.strptime(self.end,'%Y-%m-%d')
# print(type(self.start_d))
# period=self.start_d+datetime.timedelta(days=30)
# print(period.strftime('%Y-%m-%d'))
# print(ipo[ipo['ipo_date']<np.datetime64(period)])
def comparation(self):
# print(self.start)
# print(self.end)
delta = 30
count_list = []
profit_list = []
self.period = self.end + np.timedelta64(delta, 'D')
# print(self.period)
# print(self.ipo[self.ipo['ipo_date']<self.period])
# print(type(self.end.tolist()))
l = self.end.tolist()
ns = 1e-9
b = datetime.utcfromtimestamp(l * ns)
# print(datetime.fromtimestamp(self.end.tolist()))
c = b.strftime('%Y-%m-%d')
# print(type(c))
start_data = self.start
while start_data < self.end:
# print(start_data)
first_date = start_data
start_data = start_data + np.timedelta64(delta, 'D')
result = self.ipo[(self.ipo['ipo_date'] >= first_date) & (self.ipo['ipo_date'] < start_data)]
# print(result)
count = len(result)
temp_end_data = start_data + np.timedelta64(-1, 'D')
t = pd.to_datetime(str(temp_end_data))
d = t.strftime('%Y-%m-%d')
t1 = pd.to_datetime(str(first_date))
d1 = t1.strftime('%Y-%m-%d')
sz_index_data = ts.get_k_data('399001', index=True, start=d1, end=d)
# print(index_data)
# 大盘(深圳,考虑到国家队在上证的操作) 在30天内的收益
before = sz_index_data['close'].values[0]
after = sz_index_data['close'].values[-1]
# profit_index=(index_data['close'][-1]-index_data['close'][0])/index_data['close'][0]*100
p = round((after - before) / before * 100, 2)
count_list.append(count)
profit_list.append(p)
return count_list, profit_list
def draw(self):
count, profit = self.comparation()
s1 = Series(count, index=range(len(count)))
s2 = Series(profit, index=range(len(profit)))
'''
ax=s1.plot()
ax2=s2.plot()
fig=ax.get_figure()
fig.savefig('count.png')
fig2=ax2.get_figure()
fig2.savefig('profit.png')
'''
r = s1.corr(s2)
def main():
obj = IPOSpeed()
obj.draw()
main()