forked from jsmidt/QuantPy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevent_ex.py
More file actions
28 lines (20 loc) · 679 Bytes
/
event_ex.py
File metadata and controls
28 lines (20 loc) · 679 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
26
27
28
import quantpy as qp
from numpy import *
# Create your own truth function describing your even.
# In this case the event is: whenever the price chanegs $1.
def truth_function(asset):
truth = zeros(len(asset))
for i in range(1,len(asset)):
if asset[i] - asset[i-1] > 1.0:
truth[i] = 1
return truth
# Grab a profile
P = qp.Portfolio(['GOOG','IBM','INTC'])
# Define your asset you want to test.
asset = P.asset['IBM']['Adj Close']
# Generate your truth function.
truth = truth_function(asset)
# Get profiles for these events
profiles = qp.event_profiler(asset,truth)
# Plot them
qp.plot_event_profile(profiles,name='When price increases $1.')