forked from jsmidt/QuantPy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevent_profiler.py
More file actions
25 lines (21 loc) · 872 Bytes
/
event_profiler.py
File metadata and controls
25 lines (21 loc) · 872 Bytes
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
# This concept was inspired by QSTK:
# http://wiki.quantsoftware.org/index.php?title=QuantSoftware_ToolKit.
# However, no source code from that toolkit was used or consulted directly for
# this code. (The concept only)
from pylab import errorbar, xlabel, ylabel, show, legend
from numpy import array, arange
def event_profiler(asset, truth, periods=5):
cut = []
for i in range(periods, len(asset) - periods):
if truth[i] == 1 and asset[i] > 0:
cut.append(asset[i - periods:i + periods] / asset[i])
return array(cut)
def plot_event_profile(events, name=''):
mn = events.mean(axis=0) - 1.0
st = events.std(axis=0)
errorbar(arange(len(mn)), mn, st, label=name)
xlabel('Periods', fontsize=16)
ylabel('Price Change %', fontsize=16)
if len(name) > 1:
legend(loc='best', shadow=True, fancybox=True)
show()