Physical time | Intrinsic time |
---|---|
point-based | event-based |
homogeneous | inhomogeneous |
time scales equally spaced | time triggers only at periodic events |
Term | Description | Example in figure |
---|---|---|
Extreme point | the time at | points , , , , , , |
DCC point | the time at | points , , , , , , |
Term | Description | Example in figure |
---|---|---|
DC event | -starts with an extreme point -ends with a DCC point | intervals , , , |
DCC point | -starts at the DCC point -ends at the next extreme point | ntervals , , , |
downward run | upward run |
---|---|
A period between a downturn event and the next upturn event | A period between a upturn event and the next downturn event |
The last low price is continuosly updated to the minimum of the current market price and the last low price | The last high price is continuosly updated to the maximum of the current market price and the last high price |
An event is an event when the absolute price change between the current market price and the last low price is higher than a given threshold , i.e., If this holds, the point which the price last troughed ( is the starting point of a upturn event | An event is an event when the absolute price change between the current market price and the last high price is lower than a given threshold , i.e., If this holds, the point which the price last peaked ( is the starting point of a downturn event |
def myDC(data, d=0.2):
'''
- Aloud, M., Tsang, E., Olsen, R. & Dupuis, A. (2012). A Directional-Change Event Approach for Studying Financial Time Series. Economics, 6(1), 20120036.
- data : a list or array-like time series object
- d : theta value, which is a threshold to decide upturn/downturn event
'''
p = pd.DataFrame({
"Price": data
})
p["Event"] = ''
run = "upward" # initial run
ph = p['Price'][0] # highest price
pl = ph # lowest price
pl_i = ph_i = 0
for t in range(0, len(p)):
pt = p["Price"][t]
if run == "downward":
if pt < pl:
pl = pt
pl_i = t
if pt >= pl * (1 + d):
p.at[pl_i, 'Event'] = "start upturn event"
run = "upward"
ph = pt
ph_i = t
# print(">> {} - Upward! : {}%, value {}".format(pl_i, round((pt - pl)/pl, 2), round(pt - pl,2)))
elif run == "upward":
if pt > ph:
ph = pt
ph_i = t
if pt <= ph * (1 - d):
p.at[ph_i, 'Event'] = "start downturn event"
run = "downward"
pl = pt
pl_i = t
# print(">> {} - Downward! : {}%, value {}".format(ph_i, round((ph - pt)/ph, 2), round(ph - pt,2)))
return p