mhallsmoore / qsforex

QuantStart Forex Backtesting and Live Trading
http://www.quantstart.com
770 stars 354 forks source link

decimal.InvalidOperation: Invalid literal for Decimal: 'Bid' #56

Closed JamesKBowler closed 7 years ago

JamesKBowler commented 7 years ago

When running the backtest for mac.py I get an error as per below. (qsforex) jbowler@GEN-U-DAE-01:~/Projects/qsforex$ python examples/mac.py

Traceback (most recent call last): File "examples/mac.py", line 29, in backtest.simulate_trading() File "/home/jbowler/venv/qsforex/lib/python2.7/site-packages/qsforex/backtest/backtest.py", line 81, in simulate_trading self._run_backtest() File "/home/jbowler/venv/qsforex/lib/python2.7/site-packages/qsforex/backtest/backtest.py", line 57, in _run_backtest self.ticker.stream_next_tick() File "/home/jbowler/venv/qsforex/lib/python2.7/site-packages/qsforex/data/price.py", line 182, in stream_next_tick bid = Decimal(str(row["Bid"])).quantize( File "/home/jbowler/ProgramData/anaconda2/lib/python2.7/decimal.py", line 547, in new "Invalid literal for Decimal: %r" % value) File "/home/jbowler/ProgramData/anaconda2/lib/python2.7/decimal.py", line 3873, in _raise_error raise error(explanation) decimal.InvalidOperation: Invalid literal for Decimal: 'Bid'

How is this fixed?

Thank-you

yabolgha commented 7 years ago

Just try to set "header=false" in read_csv method when you are reading those files in CSV_DATA_DIR

Sent from my iPhone

On Dec 4, 2016, at 11:18 AM, JamesKBowler notifications@github.com wrote:

When running the backtest for mac.py I get an error as per below. (qsforex) jbowler@GEN-U-DAE-01:~/Projects/qsforex$ python examples/mac.py

Traceback (most recent call last): File "examples/mac.py", line 29, in backtest.simulate_trading() File "/home/jbowler/venv/qsforex/lib/python2.7/site-packages/qsforex/backtest/backtest.py", line 81, in simulate_trading self._run_backtest() File "/home/jbowler/venv/qsforex/lib/python2.7/site-packages/qsforex/backtest/backtest.py", line 57, in _run_backtest self.ticker.stream_next_tick() File "/home/jbowler/venv/qsforex/lib/python2.7/site-packages/qsforex/data/price.py", line 182, in stream_next_tick bid = Decimal(str(row["Bid"])).quantize( File "/home/jbowler/ProgramData/anaconda2/lib/python2.7/decimal.py", line 547, in new "Invalid literal for Decimal: %r" % value) File "/home/jbowler/ProgramData/anaconda2/lib/python2.7/decimal.py", line 3873, in _raise_error raise error(explanation) decimal.InvalidOperation: Invalid literal for Decimal: 'Bid'

How is this fixed?

Thank-you

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

JamesKBowler commented 7 years ago

Hi @yabolgha, Thank you for responding so quickly and my apologies for not...Tis the season.

I tried your suggestion however this did not work and gave a traceback below. I received the same error when set True. The error above was given when set to None.

(qsforex) jbowler@GEN-U-QS-01:~/projects/qsforex$ python examples/mac.py Traceback (most recent call last): File "examples/mac.py", line 27, in equity=settings.EQUITY File "/home/jbowler/venv/qsforex/local/lib/python2.7/site-packages/qsforex/backtest/backtest.py", line 29, in init self.ticker = data_handler(self.pairs, self.events, self.csv_dir) File "/home/jbowler/venv/qsforex/local/lib/python2.7/site-packages/qsforex/data/price.py", line 107, in init self.file_dates[self.cur_date_idx] File "/home/jbowler/venv/qsforex/local/lib/python2.7/site-packages/qsforex/data/price.py", line 143, in _open_convert_csv_files_for_day names=("Time", "Ask", "Bid", "AskVolume", "BidVolume") File "/home/jbowler/venv/qsforex/local/lib/python2.7/site-packages/pandas/io/parsers.py", line 646, in parser_f return _read(filepath_or_buffer, kwds) File "/home/jbowler/venv/qsforex/local/lib/python2.7/site-packages/pandas/io/parsers.py", line 389, in _read parser = TextFileReader(filepath_or_buffer, **kwds) File "/home/jbowler/venv/qsforex/local/lib/python2.7/site-packages/pandas/io/parsers.py", line 726, in init self.options, self.engine = self._clean_options(options, engine) File "/home/jbowler/venv/qsforex/local/lib/python2.7/site-packages/pandas/io/parsers.py", line 858, in _clean_options _validate_header_arg(options['header']) File "/home/jbowler/venv/qsforex/local/lib/python2.7/site-packages/pandas/io/common.py", line 195, in _validate_header_arg raise TypeError("Passing a bool to header is invalid. " TypeError: Passing a bool to header is invalid. Use header=None for no header or header=int or list-like of ints to specify the row(s) making up the column names

JamesKBowler commented 7 years ago

Issue resolved in the below Pull Request https://github.com/mhallsmoore/qsforex/pull/23

Cheers!