do date parsing while loading json, not later

This commit is contained in:
Janne Sinivirta 2017-10-29 10:16:53 +02:00
parent da9c3e7d7d
commit 54987fd9ca
2 changed files with 6 additions and 5 deletions

View File

@ -4,7 +4,7 @@ from datetime import timedelta
import arrow
import talib.abstract as ta
from pandas import DataFrame
from pandas import DataFrame, to_datetime
from qtpylib.indicators import awesome_oscillator, crossed_above
from freqtrade import exchange
@ -23,8 +23,9 @@ def parse_ticker_dataframe(ticker: list) -> DataFrame:
"""
df = DataFrame(ticker) \
.drop('BV', 1) \
.rename(columns={'C':'close', 'V':'volume', 'O':'open', 'H':'high', 'L':'low', 'T':'date'}) \
.sort_values('date')
.rename(columns={'C':'close', 'V':'volume', 'O':'open', 'H':'high', 'L':'low', 'T':'date'})
df['date'] = to_datetime(df['date'], utc=True, infer_datetime_format=True)
df.sort_values('date', inplace=True)
return df

View File

@ -56,12 +56,12 @@ def backtest(conf, pairs, mocker):
for index, row in ticker[ticker.buy == 1].iterrows():
trade = Trade(
open_rate=row['close'],
open_date=arrow.get(row['date']).datetime,
open_date=row['date'],
amount=1,
)
# calculate win/lose forwards from buy point
for index2, row2 in ticker[index:].iterrows():
if should_sell(trade, row2['close'], arrow.get(row2['date']).datetime):
if should_sell(trade, row2['close'], row2['date']):
current_profit = (row2['close'] - trade.open_rate) / trade.open_rate
trades.append((pair, current_profit, index2 - index))