#18355 closed defect (fixed)

Some cleanup in finance/stock

Reported by: ncohen Owned by:
Priority: major Milestone: sage-6.7
Component: finance Keywords:
Cc: Merged in:
Authors: Nathann Cohen Reviewers: Volker Braun
Report Upstream: N/A Work issues:
Branch: e685dcd (Commits) Commit: e685dcd2dcf7bd8d74efda055ecca94d38df7ae9
Dependencies: Stopgaps:

Description

This branch cleans that file a bit. It renames two functions (google() and yahoo()) into something more meaningful, moves exceptions around, adds some doc.

Nathann

Change History (14)

comment:1 Changed 23 months ago by ncohen

  • Branch set to public/18355
  • Commit set to bce3bc4ae710a4eaea99587d9bffffe4f89f18f2
  • Status changed from new to needs_review

New commits:

bac4f12trac #18355: Rename Stock.google->history and Stock.yahoo->current_price_data
4481fbctrac #18355: Index of methods
ac96755trac #18355: Raise exceptions in Stock._get_data instead of doing it in higher-level functions
ec9bd1dtrac #18355: Fix one broken doctest
bce3bc4trac #18355: Add actual ticket number in the deprecations

comment:2 Changed 23 months ago by vbraun

  • Reviewers set to Volker Braun

Great! Can you also fix the # optional internet tests?

sage -t src/sage/finance/stock.py
**********************************************************************
File "src/sage/finance/stock.py", line 279, in sage.finance.stock.Stock.history
Failed example:
    finance.Stock('vmw').history('Aug+13,+2007')[:5] # optional -- internet
Expected:
    [
     14-Aug-07 51.99 55.50 48.00 51.00   38253700,
     15-Aug-07 52.11 59.87 51.50 57.71   10487000,
     16-Aug-07 60.99 61.49 52.71 56.99    6641500,
     17-Aug-07 59.00 59.00 54.45 55.55    2983800,
     20-Aug-07 56.05 57.50 55.61 57.33    2077200
    ]
Got:
    [
     14-Aug-07 50.00 55.50 48.00 51.00   38262850,
     15-Aug-07 52.11 59.87 51.50 57.71   10689100,
     16-Aug-07 60.99 61.49 52.71 56.99    6919500,
     17-Aug-07 59.00 59.00 54.45 55.55    3087000,
     20-Aug-07 56.05 57.50 55.61 57.33    2141900
    ]
**********************************************************************
File "src/sage/finance/stock.py", line 288, in sage.finance.stock.Stock.history
Failed example:
    finance.Stock('F').history('Jan+3,+1978', 'Jul+7,+2008')[:5] # optional -- internet
Expected:
    [
      3-Jan-78 0.00 1.93 1.89 1.89    1618200,
      4-Jan-78 0.00 1.89 1.87 1.88    2482700,
      5-Jan-78 0.00 1.89 1.84 1.84    2994900,
      6-Jan-78 0.00 1.84 1.82 1.83    3042500,
      9-Jan-78 0.00 1.81 1.79 1.81    3916400
    ]
Got:
    [
     20-Aug-92 0.00 7.90 7.73 7.83    5492698,
     21-Aug-92 0.00 7.92 7.66 7.68    5345999,
     24-Aug-92 0.00 7.59 7.33 7.35   11056299,
     25-Aug-92 0.00 7.66 7.38 7.61    8875299,
     26-Aug-92 0.00 7.73 7.64 7.68    6447201
    ]
**********************************************************************
File "src/sage/finance/stock.py", line 302, in sage.finance.stock.Stock.history
Failed example:
    finance.Stock('AAPL').history('Sep+1,+1900', 'Jan+1,+2000')[0:5] # optional -- internet
Expected:
    [
      4-Jan-99 0.00 2.64 2.50 2.58  136126400,
      5-Jan-99 0.00 2.75 2.59 2.71  201441600,
      6-Jan-99 0.00 2.76 2.56 2.61  192643200,
      7-Jan-99 0.00 2.82 2.63 2.81  204145600,
      8-Jan-99 0.00 2.93 2.75 2.81   96960000
    ]
Got:
    [
      4-Jan-99 0.00 1.51 1.43 1.47  238221200,
      5-Jan-99 0.00 1.57 1.48 1.55  352522800,
      6-Jan-99 0.00 1.58 1.46 1.49  337125600,
      7-Jan-99 0.00 1.61 1.50 1.61  357254800,
      8-Jan-99 0.00 1.67 1.57 1.61  169680000
    ]
**********************************************************************
File "src/sage/finance/stock.py", line 330, in sage.finance.stock.Stock.history
Failed example:
    sage.finance.stock.Stock("AAPL", 22144).history(startdate='Jan+1,+1990')[:5] #optional -- internet
Expected:
    [
      2-Jan-90 0.00 9.38 8.75 9.31    6542800,
      3-Jan-90 0.00 9.50 9.38 9.38    7428400,
      4-Jan-90 0.00 9.69 9.31 9.41    7911200,
      5-Jan-90 0.00 9.56 9.25 9.44    4404000,
      8-Jan-90 0.00 9.50 9.25 9.50    3627600
    ]
Got:
    [
      8-Jun-99 0.00 1.74 1.70 1.70   78414000,
      9-Jun-99 0.00 1.73 1.69 1.73   88446400,
     10-Jun-99 0.00 1.72 1.69 1.72   79262400,
     11-Jun-99 0.00 1.73 1.65 1.66   46261600,
     14-Jun-99 0.00 1.67 1.61 1.62   39270000
    ]
**********************************************************************
File "src/sage/finance/stock.py", line 388, in sage.finance.stock.Stock.open
Failed example:
    c.history(startdate='Feb+1,+2008', enddate='Mar+1,+2008')[:5]    # optional -- internet
Expected:
    [
      1-Feb-08 56.98 58.14 55.06 57.85    2473000,
      4-Feb-08 58.00 60.47 56.91 58.05    1816500,
      5-Feb-08 57.60 59.30 57.17 59.30    1709000,
      6-Feb-08 60.32 62.00 59.50 61.52    2191100,
      7-Feb-08 60.50 62.75 59.56 60.80    1511900
    ]
Got:
    [
      1-Feb-08 56.98 58.14 55.06 57.85    2490481,
      4-Feb-08 58.00 60.47 56.91 58.05    1840709,
      5-Feb-08 57.60 59.30 57.17 59.30    1712179,
      6-Feb-08 60.32 62.00 59.50 61.52    2211775,
      7-Feb-08 60.50 62.75 59.56 60.80    1521651
    ]
**********************************************************************
File "src/sage/finance/stock.py", line 447, in sage.finance.stock.Stock.close
Failed example:
    c.history(startdate='Feb+1,+2008', enddate='Mar+1,+2008')[:5]    # optional -- internet
Expected:
    [
      1-Feb-08 56.98 58.14 55.06 57.85    2473000,
      4-Feb-08 58.00 60.47 56.91 58.05    1816500,
      5-Feb-08 57.60 59.30 57.17 59.30    1709000,
      6-Feb-08 60.32 62.00 59.50 61.52    2191100,
      7-Feb-08 60.50 62.75 59.56 60.80    1511900
    ]
Got:
    [
      1-Feb-08 56.98 58.14 55.06 57.85    2490481,
      4-Feb-08 58.00 60.47 56.91 58.05    1840709,
      5-Feb-08 57.60 59.30 57.17 59.30    1712179,
      6-Feb-08 60.32 62.00 59.50 61.52    2211775,
      7-Feb-08 60.50 62.75 59.56 60.80    1521651
    ]
**********************************************************************
File "src/sage/finance/stock.py", line 580, in sage.finance.stock.Stock._get_data
Failed example:
    finance.Stock('aapl').history(startdate='Jan+1,+1990',enddate='Jan+1,+1991')[:2]    # optional -- internet
Expected:
    [
      2-Jan-90 0.00 2.34 2.19 2.33   26171200,
      3-Jan-90 0.00 2.38 2.34 2.34   29713600
    ]
Got:
    [
      2-Jan-90 0.00 1.34 1.25 1.33   45799600,
      3-Jan-90 0.00 1.36 1.34 1.34   51998800
    ]
**********************************************************************
4 items had failures:
   1 of   3 in sage.finance.stock.Stock._get_data
   1 of   6 in sage.finance.stock.Stock.close
   4 of   6 in sage.finance.stock.Stock.history
   1 of   6 in sage.finance.stock.Stock.open
    [38 tests, 7 failures, 8.65 s]
sage -t src/sage/finance/time_series.pyx
    [343 tests, 3.50 s]
----------------------------------------------------------------------
sage -t src/sage/finance/stock.py  # 7 doctests failed
----------------------------------------------------------------------

comment:3 Changed 23 months ago by ncohen

I chose to not fix them, because I do not understand what happens with them. I first thought that they displayed "the latest data" which of course would change depending on when you run them, but they actually specified a date. And none of those values should have changed.

Also, I have no idea what the last column means.

Nathann

comment:4 Changed 23 months ago by vbraun

The last column is the volume (how many units were exchanged that day). Possibly changed because the old numbers missed a source for trades, as the new ones are always higher? In any case we should update it to the new numbers.

comment:5 follow-up: Changed 23 months ago by ncohen

That last column is not the only thing that changed. The actual prices can be the double of what they used to be O_o

Nathann

comment:6 in reply to: ↑ 5 Changed 23 months ago by vbraun

Replying to ncohen:

The actual prices can be the double of what they used to be O_o

Presumably that means that the stock split in the meantime, and the historical data is adjusted for that so that it can be compared in a meaningful way.

comment:7 Changed 23 months ago by ncohen

HMmmmmmmmmmmmmm O_o

Okay. You convinced me :-D

Nathann

comment:8 Changed 23 months ago by git

  • Commit changed from bce3bc4ae710a4eaea99587d9bffffe4f89f18f2 to b4a0e656abbf19a6cdd9f5a8e57d6851de730b0a

Branch pushed to git repo; I updated commit sha1. New commits:

b4a0e65trac #18355: Fix broken (internet) doctests

comment:9 Changed 23 months ago by vbraun

  • Status changed from needs_review to positive_review

comment:10 Changed 23 months ago by ncohen

Thanks !

comment:11 Changed 23 months ago by vbraun

  • Status changed from positive_review to needs_work

This should be # optional - internet

sage -t --long src/sage/finance/stock.py
**********************************************************************
File "src/sage/finance/stock.py", line 170, in sage.finance.stock.Stock.current_price_data
Failed example:
    finance.Stock('GOOG').current_price_data()  # random
Exception raised:
    Traceback (most recent call last):
      File "/Users/buildslave-sage/slave/sage_git/build/local/lib/python2.7/site-packages/sage/doctest/forker.py", line 496, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/Users/buildslave-sage/slave/sage_git/build/local/lib/python2.7/site-packages/sage/doctest/forker.py", line 858, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.finance.stock.Stock.current_price_data[0]>", line 1, in <module>
        finance.Stock('GOOG').current_price_data()  # random
      File "/Users/buildslave-sage/slave/sage_git/build/local/lib/python2.7/site-packages/sage/finance/stock.py", line 217, in current_price_data
        values = urllib.urlopen(url).read().strip().strip('"').split(',')
      File "/Users/buildslave-sage/slave/sage_git/build/local/lib/python/urllib.py", line 87, in urlopen
        return opener.open(url)
      File "/Users/buildslave-sage/slave/sage_git/build/local/lib/python/urllib.py", line 208, in open
        return getattr(self, name)(url)
      File "/Users/buildslave-sage/slave/sage_git/build/local/lib/python/urllib.py", line 345, in open_http
        h.endheaders(data)
      File "/Users/buildslave-sage/slave/sage_git/build/local/lib/python/httplib.py", line 991, in endheaders
        self._send_output(message_body)
      File "/Users/buildslave-sage/slave/sage_git/build/local/lib/python/httplib.py", line 844, in _send_output
        self.send(msg)
      File "/Users/buildslave-sage/slave/sage_git/build/local/lib/python/httplib.py", line 806, in send
        self.connect()
      File "/Users/buildslave-sage/slave/sage_git/build/local/lib/python/httplib.py", line 787, in connect
        self.timeout, self.source_address)
      File "/Users/buildslave-sage/slave/sage_git/build/local/lib/python/socket.py", line 573, in create_connection
        raise err
    IOError: [Errno socket error] [Errno 60] Operation timed out
**********************************************************************
1 item had failures:
   1 of   2 in sage.finance.stock.Stock.current_price_data
    [16 tests, 1 failure, 75.08 s]

comment:12 Changed 23 months ago by git

  • Commit changed from b4a0e656abbf19a6cdd9f5a8e57d6851de730b0a to e685dcd2dcf7bd8d74efda055ecca94d38df7ae9

Branch pushed to git repo; I updated commit sha1. New commits:

e685dcdtrac #18355: Broken doctest

comment:13 Changed 23 months ago by ncohen

  • Status changed from needs_work to positive_review

comment:14 Changed 23 months ago by vbraun

  • Branch changed from public/18355 to e685dcd2dcf7bd8d74efda055ecca94d38df7ae9
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.