Skip to content

Commit 1d75f09

Browse files
tweak comment;diff fwd/bkwd extrapolation
1 parent b54aa6e commit 1d75f09

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# extrapolate backward:
2+
loc_linear = _date_to_iloc_linear(dtseries,date)
3+
first = _date_to_mdate(dtseries.index[0])
4+
last = _date_to_mdate(dtseries.index[-1])
5+
avg_days_between_points = (last - first)/float(len(dtseries))
6+
if avg_days_between_points > 0.33: # daily (not intraday)
7+
delta = _date_to_mdate(dtseries.index[0]) - _date_to_mdate(date)
8+
loc_5_7ths = - (5./7.)*delta
9+
loc = (loc_linear + loc_5_7ths)/2.0
10+
else:
11+
loc = loc_linear
12+
return loc
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# extrapolate forward:
2+
loc_linear = _date_to_iloc_linear(dtseries,date)
3+
first = _date_to_mdate(dtseries.index[0])
4+
last = _date_to_mdate(dtseries.index[-1])
5+
avg_days_between_points = (last - first)/float(len(dtseries))
6+
if avg_days_between_points > 0.33: # daily (not intraday)
7+
delta = _date_to_mdate(date) - _date_to_mdate(dtseries.index[-1])
8+
loc_5_7ths = len(dtseries) - 1 + (5/7.)*delta
9+
loc = (loc_linear + loc_5_7ths)/2.0
10+
else:
11+
loc = loc_linear
12+
return loc

src/mplfinance/_utils.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,10 @@ def _date_to_iloc(dtseries,date):
224224

225225
def _date_to_iloc_linear(dtseries,date,trace=False):
226226
'''Find the location of a date using linear extrapolation.
227-
Use the endpoints of `dtseriews` to the slope and yintercept
228-
for the line: iloc = (slope)*(dtseries) + (yintercept)
229-
The use them to calculate the location of `date`
227+
Use the endpoints of `dtseries` to calculate the slope
228+
and yintercept for the line:
229+
iloc = (slope)*(dtseries) + (yintercept)
230+
Then use them to calculate the location of `date`
230231
'''
231232
d1 = _date_to_mdate(dtseries.index[0])
232233
d2 = _date_to_mdate(dtseries.index[-1])

0 commit comments

Comments
 (0)