Time series objects

This module implements a TimeSeries object that is used to represent generic cashflows and interest rate.

class cashflows.gtimeseries.TimeSeries(start=None, end=None, nper=None, pyr=1)[source]

Bases: object

Time series object for representing generic cashflows and interest rates.

Examples.

>>> TimeSeries(start=(2000, 0), end=(2002, 3), nper=12, pyr=4) 
     Qtr0 Qtr1 Qtr2 Qtr3
2000 0.00 0.00 0.00 0.00
2001 0.00 0.00 0.00 0.00
2002 0.00 0.00 0.00 0.00
>>> TimeSeries(start=(2000, 0), end=(2002, 3), pyr=4) 
     Qtr0 Qtr1 Qtr2 Qtr3
2000 0.00 0.00 0.00 0.00
2001 0.00 0.00 0.00 0.00
2002 0.00 0.00 0.00 0.00
copy()[source]

returns a copy of the time series

cumsum()[source]

returns the cumulative sum of the time series

tolist()[source]

Returns the values as a list

cashflows.gtimeseries.cashflow(const_value=0, start=None, end=None, nper=None, pyr=1, spec=None)[source]

Returns a time series as a generic cashflow.

>>> spec = ((2000, 3), 10)
>>> cashflow(const_value=1, start=(2000, 0), nper=8, pyr=4, spec=spec) 
      Qtr0  Qtr1  Qtr2  Qtr3
2000  1.00  1.00  1.00 10.00
2001  1.00  1.00  1.00  1.00
>>> spec = [((2000, 3), 10), ((2001, 3), 10)]
>>> cashflow(const_value=1, start=(2000, 0), nper=8, pyr=4, spec=spec) 
      Qtr0  Qtr1  Qtr2  Qtr3
2000  1.00  1.00  1.00 10.00
2001  1.00  1.00  1.00 10.00
>>> spec = (3, 10)
>>> cashflow(const_value=1, start=(2000, 0), nper=8, pyr=4, spec=spec) 
      Qtr0  Qtr1  Qtr2  Qtr3
2000  1.00  1.00  1.00 10.00
2001  1.00  1.00  1.00  1.00
>>> spec = [(3, 10), (7, 10)]
>>> cashflow(const_value=1, start=(2000, 0), nper=8, pyr=4, spec=spec) 
      Qtr0  Qtr1  Qtr2  Qtr3
2000  1.00  1.00  1.00 10.00
2001  1.00  1.00  1.00 10.00
>>> cashflow(const_value=[10]*10, pyr=4) 
   Qtr0  Qtr1  Qtr2  Qtr3
0 10.00 10.00 10.00 10.00
1 10.00 10.00 10.00 10.00
2 10.00 10.00
>>> cashflow(const_value=[-10]*4) 
Time Series:
Start = (0,)
End = (3,)
pyr = 1
Data = (0,)-(3,) [4] -10.00
>>> x = cashflow(const_value=[0, 1, 2, 3], pyr=4)
>>> x[3] = 10
>>> x  
   Qtr0  Qtr1  Qtr2  Qtr3
0  0.00  1.00  2.00 10.00
>>> x[3]  
10
>>> x[(0, 3)] = 0
>>> x 
   Qtr0  Qtr1  Qtr2  Qtr3
0  0.00  1.00  2.00  0.00
>>> x[(0,2)]  
2
>>> cashflow(const_value=[0, 1, 2, 2, 4, 5, 6, 7, 8])  
Time Series:
Start = (0,)
End = (8,)
pyr = 1
Data = (0,)          0.00
       (1,)          1.00
       (2,)-(3,) [2] 2.00
       (4,)          4.00
       (5,)          5.00
       (6,)          6.00
       (7,)          7.00
       (8,)          8.00
>>> cashflow(const_value=0, nper=15, pyr=1, spec=[(t,100) for t in range(5,10)]) 
Time Series:
Start = (0,)
End = (14,)
pyr = 1
Data = (0,)-(4,)   [5]   0.00
       (5,)-(9,)   [5] 100.00
       (10,)-(14,) [5]   0.00
>>> cashflow(const_value=[0, 1, 2, 3, 4, 5]).cumsum() 
Time Series:
Start = (0,)
End = (5,)
pyr = 1
Data = (0,)          0.00
       (1,)          1.00
       (2,)          3.00
       (3,)          6.00
       (4,)         10.00
       (5,)         15.00
cashflows.gtimeseries.cfloplot(cflo)[source]

Text plot of a cashflow.

>>> cflo = cashflow(const_value=[-10, 5, 0, 20] * 3, pyr=4)
>>> cfloplot(cflo)
time    value +------------------+------------------+
(0, 0) -10.00           **********
(0, 1)   5.00                    *****
(0, 2)   0.00                    *
(0, 3)  20.00                    ********************
(1, 0) -10.00           **********
(1, 1)   5.00                    *****
(1, 2)   0.00                    *
(1, 3)  20.00                    ********************
(2, 0) -10.00           **********
(2, 1)   5.00                    *****
(2, 2)   0.00                    *
(2, 3)  20.00                    ********************
cashflows.gtimeseries.interest_rate(const_value=0, start=None, end=None, nper=None, pyr=1, spec=None)[source]

Creates a time series object specified as a interest rate.

>>> spec = ((2000, 3), 10)
>>> interest_rate(const_value=1, start=(2000, 0), nper=8, pyr=4, spec=spec) 
      Qtr0  Qtr1  Qtr2  Qtr3
2000  1.00  1.00  1.00 10.00
2001 10.00 10.00 10.00 10.00
>>> spec = [((2000, 3), 10), ((2001, 1), 20)]
>>> interest_rate(const_value=1, start=(2000, 0), nper=8, pyr=4, spec=spec) 
      Qtr0  Qtr1  Qtr2  Qtr3
2000  1.00  1.00  1.00 10.00
2001 10.00 20.00 20.00 20.00
>>> spec = (3, 10)
>>> interest_rate(const_value=1, start=(2000, 0), nper=8, pyr=4, spec=spec) 
      Qtr0  Qtr1  Qtr2  Qtr3
2000  1.00  1.00  1.00 10.00
2001 10.00 10.00 10.00 10.00
>>> spec = [(3, 10), (6, 20)]
>>> interest_rate(const_value=1, start=(2000, 0), nper=8, pyr=4, spec=spec) 
      Qtr0  Qtr1  Qtr2  Qtr3
2000  1.00  1.00  1.00 10.00
2001 10.00 10.00 20.00 20.00
>>> interest_rate(const_value=[10]*10, pyr=4)  
   Qtr0  Qtr1  Qtr2  Qtr3
0 10.00 10.00 10.00 10.00
1 10.00 10.00 10.00 10.00
2 10.00 10.00
cashflows.gtimeseries.repr_table(cols, header=None)[source]
cashflows.gtimeseries.verify_eq_time_range(series1, series2)[source]