Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tearsheet Statistics Class #129

Merged
merged 9 commits into from
Aug 11, 2016
Merged

Tearsheet Statistics Class #129

merged 9 commits into from
Aug 11, 2016

Conversation

nwillemse
Copy link

First version of the Tearsheet statistics class with an example mac_backtest_tearsheet.py. Currently only bars supported until we can figure out a common interface to Bars and Ticks (i.e. add get_last_price() method to both)

Missing some trade statistics because we don't have position entry/exit dates, # bars in trade, etc.

Comments?

Closes #90

Nick Willemse added 6 commits August 2, 2016 22:32
- Add performance.py to calculate various metrics
- Add tearsheet.py produce a tearsheet with equity curve, drawdown curve,
  and various other trade statistics
Lastest branch from upstream
…t Statistics

for daily bars trading system.
@coveralls
Copy link

coveralls commented Aug 5, 2016

Coverage Status

Coverage decreased (-26.4%) to 63.197% when pulling 4107dfc on nwillemse:tearsheet-statistics into 55a9d93 on mhallsmoore:master.

@femtotrader
Copy link
Contributor

To improve code coverage you might add a test which run your example
https://github.com/mhallsmoore/qstrader/blob/master/examples/test_examples.py

@nwillemse
Copy link
Author

@femtotrader Ok I will add it

Add test_mac_backtest_tearsheet
@coveralls
Copy link

coveralls commented Aug 6, 2016

Coverage Status

Coverage decreased (-18.2%) to 71.371% when pulling cbedb95 on nwillemse:tearsheet-statistics into 55a9d93 on mhallsmoore:master.

@ryankennedyio
Copy link
Contributor

@nwillemse looks like a Python3 issue with PriceParser.display(). Do you have a PR waiting that should fix that @femtotrader ?

@femtotrader
Copy link
Contributor

femtotrader commented Aug 7, 2016

I don't understand why in Python 2 we are having legacy int, and in Python 3 we have Numpy int64

I see two differents ideas:

  1. have same type for both version
  2. overcome this issue by improving price_parser

I would try something like

#100

    int_t = (*six.integer_types, np.int64)

    @staticmethod
    @dispatch(int_t)
    def display(x):  # flake8: noqa
        return round(x / PriceParser.PRICE_MULTIPLIER, 2)

@coveralls
Copy link

coveralls commented Aug 8, 2016

Coverage Status

Coverage decreased (-18.2%) to 71.394% when pulling 82b6acc on nwillemse:tearsheet-statistics into 55a9d93 on mhallsmoore:master.

@ryankennedyio
Copy link
Contributor

@nwillemse -- is there any chance you could try to add Femto's suggestion to your own repo (make a branch from this branch, and add the suggested change to that branch)?

If that works, we know #100 needs to be merged in, in order for this PR to be merged in. I think #100 should probably get merged in for the sake of best practice anyway @mhallsmoore, as the suggested library was built for handling these 2-3.

@mhallsmoore
Copy link
Owner

#100 has now been merged, so @nwillemse should now be able to add this in and we can get this one merged too.

@nwillemse
Copy link
Author

nwillemse commented Aug 8, 2016

Hi now that #100 is merged, how do I rerun these checks? Do you just need to merge the latest master into my tearsheet branch...

@coveralls
Copy link

coveralls commented Aug 8, 2016

Coverage Status

Coverage decreased (-17.9%) to 73.096% when pulling 25a369e on nwillemse:tearsheet-statistics into 3f869f0 on mhallsmoore:master.

@ryankennedyio
Copy link
Contributor

ryankennedyio commented Aug 8, 2016

:(

Any ideas @femtotrader ??

@ryankennedyio
Copy link
Contributor

ryankennedyio commented Aug 11, 2016

Well. nosetests -v works locally for me. Confusing indeed. Same with nosetests-3.4.

@mhallsmoore
Copy link
Owner

I've just tried re-running the Python 3.4 and 3.5 builds. Python 2.7 seems to work ok.

Here is the error received from the Python 3.4 run:

======================================================================
ERROR: Test mac_backtest_tearsheet example
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/mhallsmoore/qstrader/examples/test_examples.py", line 89, in test_mac_backtest_tearsheet
    results = examples.mac_backtest_tearsheet.run(self.config, self.testing, tickers, filename)
  File "/home/travis/build/mhallsmoore/qstrader/examples/mac_backtest_tearsheet.py", line 72, in run
    results = backtest.simulate_trading(testing=testing)
  File "/home/travis/build/mhallsmoore/qstrader/qstrader/trading_session/backtest.py", line 69, in simulate_trading
    results = self.statistics.get_results()
  File "/home/travis/build/mhallsmoore/qstrader/qstrader/statistics/tearsheet.py", line 76, in get_results
    statistics["positions"] = self._get_positions()
  File "/home/travis/build/mhallsmoore/qstrader/qstrader/statistics/tearsheet.py", line 109, in _get_positions
    df['avg_bot'] = df['avg_bot'].apply(x)
  File "/home/travis/miniconda/envs/test-environment/lib/python3.4/site-packages/pandas/core/series.py", line 2169, in apply
    mapped = lib.map_infer(values, f, convert=convert_dtype)
  File "pandas/src/inference.pyx", line 1059, in pandas.lib.map_infer (pandas/lib.c:62578)
  File "/home/travis/build/mhallsmoore/qstrader/qstrader/statistics/tearsheet.py", line 100, in x
    return PriceParser.display(p)
  File "/home/travis/miniconda/envs/test-environment/lib/python3.4/site-packages/multipledispatch/dispatcher.py", line 161, in __call__
    (self.name, str_signature(types)))
nose.proxy.NotImplementedError: Could not find signature for display: <int64>

Is this related to our integer types issue? It's coming up in the multipledispatch code.

@ryankennedyio
Copy link
Contributor

Yep, something to do with that @mhallsmoore.

Not sure why it works locally for me with python3. Just pulled @nwillemse's branch to check things out. If I could make it fail locally that would be helpful.

@ryankennedyio
Copy link
Contributor

Got it. int64 is a numpy thing. Would explain why multipledispatch doesn't like it. Unsure why environment is making this an int64 though on travis and locally it's fine.

Making a separate PR now which should solve.

@mhallsmoore
Copy link
Owner

Ok, I've merged in @ryankennedyio's fix and am just running the builds again for this PR. Python 2.7 and 3.4 work, just waiting on 3.5...

@mhallsmoore
Copy link
Owner

All builds now pass. Although coverage has decreased somewhat, so in the future we'll need to get it back to 90% again with some additional tests.

Happy to merge now though. This is a great feature! Thanks to everyone for putting in the effort to get it into the codebase, and for @nwillemse for creating it in the first place.

@mhallsmoore mhallsmoore merged commit 8f8dab3 into mhallsmoore:master Aug 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants