forked from Rockyzsu/stock
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcaculation_tool.py
53 lines (42 loc) · 1.31 KB
/
caculation_tool.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
# -*-coding=utf-8-*-
import sys
__author__ = 'Rocky'
'''
http://30daydo.com
Contact: [email protected]
'''
#计算股价涨跌幅
import tushare as ts
class calculator_stock():
#date= YYYY-MM-DD
def profit(self,start,end,code):
start_price=ts.get_k_data(start=start,end=start,code=code)
if len(start_price)==0:
print("Not open for start day")
#采用日期操作,往前移动上一个开盘日.
s_price=start_price['close'].values[0]
print("Start price: ",s_price)
end_price=ts.get_k_data(start=end,end=end,code=code)
if len(end_price)==0:
print("Not open for end day")
e_price=end_price['close'].values[0]
print("End price: ",e_price)
earn_profit=(e_price-s_price)/s_price*100
print("Profit: ",)
print(round(earn_profit,2))
def percentage(open_price):
open_price=float(open_price)
for i in range(1,11):
print('{}\t+{}%->{}'.format(open_price,i,open_price*(1+0.01*i)))
for i in range(1,11):
print('{}\t-{}%->{}'.format(open_price,i,open_price*(1-0.01*i)))
if __name__=="__main__":
''''
obj=calculator_stock()
code='300333'
start='2015-12-21'
end='2017-04-14'
obj.profit(start,end,code)
'''
#percentage(sys.args[1])
percentage(24.54)