do date parsing while loading json, not later
This commit is contained in:
parent
da9c3e7d7d
commit
54987fd9ca
@ -4,7 +4,7 @@ from datetime import timedelta
|
|||||||
|
|
||||||
import arrow
|
import arrow
|
||||||
import talib.abstract as ta
|
import talib.abstract as ta
|
||||||
from pandas import DataFrame
|
from pandas import DataFrame, to_datetime
|
||||||
from qtpylib.indicators import awesome_oscillator, crossed_above
|
from qtpylib.indicators import awesome_oscillator, crossed_above
|
||||||
|
|
||||||
from freqtrade import exchange
|
from freqtrade import exchange
|
||||||
@ -23,8 +23,9 @@ def parse_ticker_dataframe(ticker: list) -> DataFrame:
|
|||||||
"""
|
"""
|
||||||
df = DataFrame(ticker) \
|
df = DataFrame(ticker) \
|
||||||
.drop('BV', 1) \
|
.drop('BV', 1) \
|
||||||
.rename(columns={'C':'close', 'V':'volume', 'O':'open', 'H':'high', 'L':'low', 'T':'date'}) \
|
.rename(columns={'C':'close', 'V':'volume', 'O':'open', 'H':'high', 'L':'low', 'T':'date'})
|
||||||
.sort_values('date')
|
df['date'] = to_datetime(df['date'], utc=True, infer_datetime_format=True)
|
||||||
|
df.sort_values('date', inplace=True)
|
||||||
return df
|
return df
|
||||||
|
|
||||||
|
|
||||||
|
@ -56,12 +56,12 @@ def backtest(conf, pairs, mocker):
|
|||||||
for index, row in ticker[ticker.buy == 1].iterrows():
|
for index, row in ticker[ticker.buy == 1].iterrows():
|
||||||
trade = Trade(
|
trade = Trade(
|
||||||
open_rate=row['close'],
|
open_rate=row['close'],
|
||||||
open_date=arrow.get(row['date']).datetime,
|
open_date=row['date'],
|
||||||
amount=1,
|
amount=1,
|
||||||
)
|
)
|
||||||
# calculate win/lose forwards from buy point
|
# calculate win/lose forwards from buy point
|
||||||
for index2, row2 in ticker[index:].iterrows():
|
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
|
current_profit = (row2['close'] - trade.open_rate) / trade.open_rate
|
||||||
|
|
||||||
trades.append((pair, current_profit, index2 - index))
|
trades.append((pair, current_profit, index2 - index))
|
||||||
|
Loading…
Reference in New Issue
Block a user