-
Notifications
You must be signed in to change notification settings - Fork 1
/
fuquan.py
71 lines (66 loc) · 2.44 KB
/
fuquan.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
# coding=utf-8
import readDayRecord
import csv
"""
"""
STDTFQinfo = [[20110617, 0.3, 0, 0.6, 0, 0],
[20100617, 0.3, 0, 0.6, 0, 0],
[20090617, 0.3, 0, 0.6, 0, 0],
[20080617, 0.3, 0, 0.6, 0, 0],
[20070617, 0.3, 0, 0.6, 0, 0]]
def GetMatchedFuquanFromWholeFuquan(starttime, endtime, WholeFuquanData):
recordNumber = len(WholeFuquanData)
if len(WholeFuquanData) == 0:
return []
part1 = []
part2 = []
for i in WholeFuquanData:
if i[0] < endtime:
part1.append(i)
for i in part1:
if i[0] > starttime:
part2.append(i)
#part2 is Fuquan info between start and endtime
return part2
def SingleFuqian_Forward(FQinfo, filepointer):
"""FQinfo is : [time(trade time), free(how many), gift(How many), bonus(how much), cheaper_price(how much), cheaper_count(how many)]
"""
earlierprice = readDayRecord.GetYesterDayEndPrice(filepointer, FQinfo[0])
if earlierprice == []:
return 1
bonus = FQinfo[3]
free = FQinfo[1]
gift = FQinfo[2]
cheaper_price = FQinfo[4]
cheaper_count = FQinfo[5]
fq_1 = (earlierprice - bonus)
fq_2 = (fq_1)/(1 + free + gift)
fq_3 = ((fq_2) + cheaper_price*cheaper_count)/(1+cheaper_count)
return fq_3/earlierprice
def periodFuquan_factor_Forward(FQPeriodTable, filepointer):
result = 1.0
if FQPeriodTable == []:
return 1
if type(FQPeriodTable[0]) == type([]):
for i in FQPeriodTable:
result = result * SingleFuqian_Forward(i, filepointer)
else:
result = result * SingleFuqian_Forward(FQPeriodTable, filepointer)
return result
def GetFuquanedPrice(starttime, endtime, Kdayfilepointer, WholeFuquanInfo):
matchFuquanTable = GetMatchedFuquanFromWholeFuquan(starttime, endtime, WholeFuquanInfo)
index = periodFuquan_factor_Forward(matchFuquanTable, Kdayfilepointer)
record = readDayRecord.findMatchedTimeRecord(Kdayfilepointer, starttime)
if record <> []:
return readDayRecord.getEndPrice(record)* index
else:
return []
def getFuquanedPrice_fromFile(starttime, endtime, Kdayfilepointer, fuquanfilepointer):
FullFQInfo = GetFuquanInfoFromFile(fuquanfilepointer)
return GetFuquanedPrice(starttime, endtime, Kdayfilepointer, FullFQInfo)
def GetFuquanInfoFromFile(filenpointer):
FQReader = csv.reader(filenpointer)
result = []
for row in FQReader:
result.append(map(float, row))
return result