Issue #1
The following function is run as a pre_func in a fetch_csv call. The data being called is monthly data.
def load_data(df):
df = df.reindex(df.index[::-1])
df['last'] = df['Value']
df['last Date'] = df['Date']
return df
In backtest mode, the below line was working fine. It would capture the late of the most recently available monthly data given the current day in the backtest.
last_date= datetime.strptime(data.current('data_series', 'last Date'),'%Y-%m-%d')
But in live trading mode, this last line of code fails because a "NaN" value is returned from data.current. I should note that the monthly data lags by at least a month. So in live trading, if we are in November, the last available data may be from October or even September.
I actually want the date returned to be the last date available from the fetched data so that I can adjust some calculations I do with the data. How can I do this and not keep getting NaN?
Issue #2
data.current is returning the last close price but not the current price. When in the backtest, I though this was simply an aberration of backtesting. But now that the code is in live trading, it's still only returning the last close price and not the intraday current price. Am I doing something wrong is this just how this code works?
Example:
now_price = data.current(stock,'price') #where stock is any valid sip code, returns last close instead of intraday price