Opened 13 years ago

Closed 13 years ago

#4491 closed defect (fixed)

finance.TimeSeries from numpy array doesn't work correctly

Reported by: ghtdak Owned by: jason
Priority: minor Milestone: sage-3.2.2
Component: finance Keywords:
Cc: Merged in:
Authors: Reviewers:
Report Upstream: Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description (last modified by mabshoff)

Looks like initializing a TimeSeries? from a column of a numpy array doesn't work properly

testp.shape
(373389, 4)
t1=finance.TimeSeries(testp[:,3]); t1             # wrong
[962.5000, 1225742099742.0000, 4.0000, 4.0000, 962.5000 ... 999.2500,
1225850900622.0000, 4.0000, 5.0000, 999.2500]
t1=finance.TimeSeries(testp[:,3].tolist()); t1     # correct
[962.5000, 962.5000, 962.5000, 962.5000, 962.5000 ... 954.5000,
954.5000, 954.5000, 954.5000, 954.5000]

Change History (8)

comment:1 Changed 13 years ago by mabshoff

  • Milestone set to sage-3.2.1

Welcome back :)

Cheers,

Michael

comment:2 Changed 13 years ago by jason

This might be affected by #4206.

comment:3 Changed 13 years ago by was

t1=finance.TimeSeries(testp[:,3]); t1

I probably never implemented such initialization when the numpy array doesn't have trivial stride. This is certainly a valid bug; fixing it should be a high priority.

comment:4 Changed 13 years ago by jason

  • Owner changed from ghtdak to jason
  • Status changed from new to assigned

I'm looking at this as part of the RDF/CDF vector rewrite.

comment:5 Changed 13 years ago by jason

Okay, this will taken care of as part of the vector RDF/CDF rewrite (since that already touched the relevant parts of the timeseries code). Timing results for the case that worked before (simple double numpy arrays) indicate a 3x slowdown. The new code should work for any numpy datatype (the current code does not) and any sort of numpy array.

before patch:

sage: import numpy as np
sage: a=np.array(range(1e2), dtype='double')
sage: %timeit b=finance.TimeSeries(a)
100000 loops, best of 3: 2.13 µs per loop
sage: a=np.array(range(1e3), dtype='double')
sage: %timeit b=finance.TimeSeries(a)
100000 loops, best of 3: 3.51 µs per loop
sage: a=np.array(range(1e4), dtype='double')
sage: %timeit b=finance.TimeSeries(a)
10000 loops, best of 3: 21.6 µs per loop
sage: a=np.array(range(1e5), dtype='double')
sage: %timeit b=finance.TimeSeries(a)
100 loops, best of 3: 1.85 ms per loop
sage: a=np.array(range(1e6), dtype='double')
sage: %timeit b=finance.TimeSeries(a)
10 loops, best of 3: 18.5 ms per loop
sage: a=np.array(range(1e7), dtype='double')
sage: %timeit b=finance.TimeSeries(a)double')
10 loops, best of 3: 189 ms per loop

after patch:

sage: sage: import numpy as np
sage: sage: a=np.array(range(1e2), dtype='double')
sage: sage: %timeit b=finance.TimeSeries(a)
100000 loops, best of 3: 5.77 µs per loop
sage: sage: a=np.array(range(1e3), dtype='double')
sage: sage: %timeit b=finance.TimeSeries(a)
100000 loops, best of 3: 8.74 µs per loop
sage: sage: a=np.array(range(1e4), dtype='double')
sage: sage: %timeit b=finance.TimeSeries(a)
10000 loops, best of 3: 52.3 µs per loop
sage: sage: a=np.array(range(1e5), dtype='double')
sage: sage: %timeit b=finance.TimeSeries(a)
100 loops, best of 3: 3.83 ms per loop
sage: sage: a=np.array(range(1e6), dtype='double')
sage: sage: %timeit b=finance.TimeSeries(a)
10 loops, best of 3: 36.3 ms per loop
sage: sage: a=np.array(range(1e7), dtype='double')
sage: sage: %timeit b=finance.TimeSeries(a)
10 loops, best of 3: 365 ms per loop

comment:6 Changed 13 years ago by jason

This is solved in #4206

comment:7 Changed 13 years ago by mabshoff

  • Description modified (diff)

comment:8 Changed 13 years ago by mabshoff

  • Resolution set to fixed
  • Status changed from assigned to closed

Since there is a doctest in #4206

[01:04am] mabshoff: I haven't checked, but I will close that ticket of #4206 has a doctest.
[01:04am] jason-: yes
[01:04am] jason-:             sage: finance.TimeSeries(v)
[01:04am] jason-:             [1.0000, 2.0000, 3.0000, 4.0000]
[01:04am] jason-:             sage: finance.TimeSeries(v[:,0])
[01:04am] jason-:             [1.0000, 3.0000]

this ticket is closed as fixed in Sage 3.2.2.alpha1

Note: See TracTickets for help on using tickets.