loading data from a database #846
Unanswered
julienbalas
asked this question in
Q&A
Replies: 2 comments 1 reply
-
As the quick start tutorial points out, use df.index = pd.to_datetime(df['datetime'])
Ensure none of the Close values is 0! Also update backtesting.py to current master branch and see if the issue is maybe already fixed (a new release is pending shortly). Please provide a MWE that can be used to reproduce the issue. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi
i try to apply the first program of the tutorial "smaCross" to data i already have in a sqlite Database.
the data seems to be correctly loaded, the print(df) shows
datetime Open High Low Close
0 2000-01-03 127.100754 138.434097 127.024696 131.436325
1 2000-01-04 133.261841 135.391586 121.091805 123.525810
2 2000-01-05 119.038109 119.798737 113.257347 113.257347
3 2000-01-06 113.333412 118.353546 110.366966 113.333412
4 2000-01-07 115.615288 121.624245 114.094032 120.331177
.. ... ... ... ... ...
995 2003-10-27 41.264008 41.264008 39.970943 40.807632
996 2003-10-28 40.883698 42.937389 40.769604 42.785263
997 2003-10-29 43.355732 44.192425 43.203609 43.926205
998 2003-10-30 44.078327 44.382580 42.975422 43.545891
999 2003-10-31 43.013451 44.344547 42.252823 43.659985
[1000 rows x 5 columns]
but on the "bt .run()"
i get
5_load_from_db.py:24: UserWarning: Data index is not datetime. Assuming simple periods, but
pd.DateTimeIndex
is advised.exclusive_orders=True)
Q1) how can i convert my date to the correct datatype ?
then i get
/home/julien/.local/lib/python3.7/site-packages/backtesting/backtesting.py:149: RuntimeWarning: divide by zero encountered in true_divide
x = value / self._data.Close
/home/julien/.local/lib/python3.7/site-packages/backtesting/backtesting.py:864: RuntimeWarning: divide by zero encountered in double_scalars
// adjusted_price), size)
Traceback (most recent call last):
File "5_load_from_db.py", line 25, in
stats = bt.run()
File "/home/julien/.local/lib/python3.7/site-packages/backtesting/backtesting.py", line 1165, in run
broker.next()
File "/home/julien/.local/lib/python3.7/site-packages/backtesting/backtesting.py", line 765, in next
self._process_orders()
File "/home/julien/.local/lib/python3.7/site-packages/backtesting/backtesting.py", line 864, in _process_orders
// adjusted_price), size)
OverflowError: cannot convert float infinity to integer
i don't understand why there is a divide by zero as the Close values seems to be OK and i checked into the database, there is no null or 0 values
backtesting.py/backtesting/backtesting.py
Line 149 in 0107d4a
Q2) how can i get around this error ?
Q3) is there another things to do in order to load the data into the dataframe ?
is df = pd.read_sql_query("my_query") suffisant ?
Best regards
Beta Was this translation helpful? Give feedback.
All reactions