-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
uncategorised.py
143 lines (130 loc) · 3.98 KB
/
uncategorised.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
""""""
# Import Built-Ins:
import cmath
# Import Third-Party:
# Import Homebrew:
import jhtalib as jhta
def BPPS(trade_start_price, trade_end_price, trade_start_timestamp, trade_end_timestamp):
"""
Basis Points per Second
Returns: float = jhta.BPPS(trade_start_price, trade_end_price, trade_start_timestamp, trade_end_timestamp)
Source: book: An Introduction to Algorithmic Trading
"""
return (((trade_end_price - trade_start_price) / trade_start_price) / (trade_end_timestamp - trade_start_timestamp)) * 10000
def PRET(df, price='Close'):
"""
%Return
Returns: list of floats = jhta.PRET(df, price='Close')
Source: book: An Introduction to Algorithmic Trading
"""
pret_list = []
ret_list = jhta.RET(df, price)
for i in range(len(df[price])):
if i < 1:
pret = float('NaN')
else:
pret = ret_list[i] / df[price][i - 1]
pret_list.append(pret)
return pret_list
def PRETLOG(df, price='Close'):
"""
%Return Log
Returns: list of floats = jhta.PRETLOG(df, price='Close')
Source: https://fintechprofessor.com/2017/12/02/log-vs-simple-returns-examples-and-comparisons/
"""
pretlog_list = []
for i in range(len(df[price])):
if i < 1:
pretlog = float('NaN')
else:
pretlog = cmath.log(df[price][i] / df[price][i - 1]).real
pretlog_list.append(pretlog)
return pretlog_list
def PRETS(df, price='Close'):
"""
%Returns
Returns: list of floats = jhta.PRETS(df, price='Close')
Source: book: An Introduction to Algorithmic Trading
"""
prets_list = []
pret_list = jhta.PRET(df, price)
for i in range(len(df[price])):
if i < 1:
prets = float('NaN')
prets_list.append(prets)
prets = .0
else:
prets = prets + pret_list[i]
prets_list.append(prets)
return prets_list
def PRETSLOG(df, price='Close'):
"""
%Returns Log
Returns: list of floats = jhta.PRETSLOG(df, price='Close')
"""
pretslog_list = []
pretlog_list = jhta.PRETLOG(df, price)
for i in range(len(df[price])):
if i < 1:
pretslog = float('NaN')
pretslog_list.append(pretslog)
pretslog = .0
else:
pretslog = pretslog + pretlog_list[i]
pretslog_list.append(pretslog)
return pretslog_list
def RET(df, price='Close'):
"""
Return
Returns: list of floats = jhta.RET(df, price='Close')
Source: book: An Introduction to Algorithmic Trading
"""
ret_list = []
for i in range(len(df[price])):
if i < 1:
ret = float('NaN')
else:
ret = df[price][i] - df[price][i - 1]
ret_list.append(ret)
return ret_list
def RETLOG(df, price='Close'):
"""
Return Log
Returns: list of floats = jhta.RETLOG(df, price='Close')
Source: https://fintechprofessor.com/2017/12/02/log-vs-simple-returns-examples-and-comparisons/
"""
ret_list = jhta.RET(df, price)
return jhta.LOG({'ret': ret_list}, 'ret')
def RETS(df, price='Close'):
"""
Returns
Returns: list of floats = jhta.RETS(df, price='Close')
Source: book: An Introduction to Algorithmic Trading
"""
rets_list = []
ret_list = jhta.RET(df, price)
for i in range(len(df[price])):
if i < 1:
rets = float('NaN')
rets_list.append(rets)
rets = .0
else:
rets = rets + ret_list[i]
rets_list.append(rets)
return rets_list
def RETSLOG(df, price='Close'):
"""
Returns Log
Returns: list of floats = jhta.RETSLOG(df, price='Close')
"""
retslog_list = []
retlog_list = jhta.RETLOG(df, price)
for i in range(len(df[price])):
if i < 1:
retslog = float('NaN')
retslog_list.append(retslog)
retslog = .0
else:
retslog = retslog + retlog_list[i]
retslog_list.append(retslog)
return retslog_list