Skip to content

Commit

Permalink
BLD: fix bundles last partial candle for minute mode - as reported in…
Browse files Browse the repository at this point in the history
… issue scrtlabs#266
  • Loading branch information
lenak25 committed Mar 29, 2018
1 parent 4eaec97 commit af7b211
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions catalyst/exchange/exchange_data_portal.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import abc
import datetime

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -300,20 +301,34 @@ def get_exchange_history_window(self,
)
adj_bar_count = candle_size * bar_count

if data_frequency == 'minute' and adj_data_frequency == 'daily':
end_dt = end_dt.floor('1D')
if data_frequency == "minute":
# for minute frequency always request data until the
# current minute (do not include the current minute)
last_dt_for_series = end_dt - datetime.timedelta(minutes=1)

# read the minute bundles for daily frequency to
# support last partial candle
# TODO: optimize this by applying this logic only for the last day
if adj_data_frequency == 'daily':
adj_data_frequency = 'minute'
adj_bar_count = adj_bar_count * 1440

else: # data_frequency == "daily":
last_dt_for_series = end_dt

series = bundle.get_history_window_series_and_load(
assets=assets,
end_dt=end_dt,
end_dt=last_dt_for_series,
bar_count=adj_bar_count,
field=field,
data_frequency=adj_data_frequency,
algo_end_dt=self._last_available_session,
)

start_dt = get_start_dt(end_dt, adj_bar_count, adj_data_frequency)
start_dt = get_start_dt(last_dt_for_series, adj_bar_count,
adj_data_frequency, False)
df = resample_history_df(pd.DataFrame(series), freq, field, start_dt)

return df

def get_exchange_spot_value(self,
Expand Down

0 comments on commit af7b211

Please sign in to comment.