Skip to content

Commit

Permalink
src/sage/finance: Update doctests: Top-level lazy_import deprecation …
Browse files Browse the repository at this point in the history
…warnings are now local to tests
  • Loading branch information
Matthias Koeppe committed Mar 30, 2023
1 parent 6ea8ecc commit e58be77
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/sage/finance/fractal.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def stationary_gaussian_simulation(s, N, n=1):
sage: set_random_seed(0)
sage: sim = finance.stationary_gaussian_simulation(s, N)[0]
doctest:warning...
DeprecationWarning: the package sage.finance is deprecated...
DeprecationWarning: ...finance... is deprecated...
Note that indeed the autocovariance sequence approximates ``s`` well::
Expand Down Expand Up @@ -175,6 +175,8 @@ def fractional_gaussian_noise_simulation(double H, double sigma2, N, n=1):
sage: set_random_seed(0)
sage: finance.fractional_gaussian_noise_simulation(0.8,1,10,2)
doctest:warning...
DeprecationWarning: ...finance... is deprecated...
[[-0.1157, 0.7025, 0.4949, 0.3324, 0.7110, 0.7248, -0.4048, 0.3103, -0.3465, 0.2964],
[-0.5981, -0.6932, 0.5947, -0.9995, -0.7726, -0.9070, -1.3538, -1.2221, -0.0290, 1.0077]]
Expand Down Expand Up @@ -231,6 +233,8 @@ def fractional_brownian_motion_simulation(double H, double sigma2, N, n=1):
sage: set_random_seed(0)
sage: finance.fractional_brownian_motion_simulation(0.8,0.1,8,1)
doctest:warning...
DeprecationWarning: ...finance... is deprecated...
[[-0.0754, 0.1874, 0.2735, 0.5059, 0.6824, 0.6267, 0.6465, 0.6289]]
sage: set_random_seed(0)
sage: finance.fractional_brownian_motion_simulation(0.8,0.01,8,1)
Expand Down Expand Up @@ -275,6 +279,8 @@ def multifractal_cascade_random_walk_simulation(double T,
sage: set_random_seed(0)
sage: a = finance.multifractal_cascade_random_walk_simulation(3770,0.02,0.01,0.01,10,3)
doctest:warning...
DeprecationWarning: ...finance... is deprecated...
sage: a
[[-0.0096, 0.0025, 0.0066, 0.0016, 0.0078, 0.0051, 0.0047, -0.0013, 0.0003, -0.0043],
[0.0003, 0.0035, 0.0257, 0.0358, 0.0377, 0.0563, 0.0661, 0.0746, 0.0749, 0.0689],
Expand Down
27 changes: 26 additions & 1 deletion src/sage/finance/markov_multifractal.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ def __init__(self, kbar, m0, sigma, gamma_kbar, b):
EXAMPLES::
sage: msm = finance.MarkovSwitchingMultifractal(8,1.4,0.5,0.95,3); msm
doctest:warning...
DeprecationWarning: ...finance... is deprecated...
Markov switching multifractal model with m0 = 1.4, sigma = 0.5, b = 3.0, and gamma_8 = 0.95
sage: yen_usd = finance.MarkovSwitchingMultifractal(10,1.448,0.461,0.998,3.76)
sage: cad_usd = finance.MarkovSwitchingMultifractal(10,1.278,0.262,0.644,2.11)
Expand All @@ -64,6 +66,8 @@ def __eq__(self, other):
EXAMPLES::
sage: msm = finance.MarkovSwitchingMultifractal(8,1.4,1.0,0.95,3)
doctest:warning...
DeprecationWarning: ...finance... is deprecated...
sage: msm == msm
True
Expand All @@ -87,6 +91,8 @@ def __hash__(self):
EXAMPLES::
sage: msm = finance.MarkovSwitchingMultifractal(8,1.4,1.0,0.95,3)
doctest:warning...
DeprecationWarning: ...finance... is deprecated...
sage: H = hash(msm)
"""
return hash((self.__m0, self.__sigma, self.__b, self.__gamma_kbar,
Expand All @@ -99,7 +105,8 @@ def __ne__(self, other):
EXAMPLES::
sage: msm = finance.MarkovSwitchingMultifractal(8,1.4,1.0,0.95,3)
doctest:warning...
DeprecationWarning: ...finance... is deprecated...
sage: msm != msm
False
sage: cad_usd = finance.MarkovSwitchingMultifractal(10,1.278,0.262,0.644,2.11); cad_usd
Expand All @@ -116,6 +123,8 @@ def __repr__(self):
EXAMPLES::
sage: msm = finance.MarkovSwitchingMultifractal(8,1.4,1,0.95,3)
doctest:warning...
DeprecationWarning: ...finance... is deprecated...
sage: msm.__repr__()
'Markov switching multifractal model with m0 = 1.4, sigma = 1.0, b = 3.0, and gamma_8 = 0.95'
"""
Expand All @@ -128,6 +137,8 @@ def m0(self):
EXAMPLES::
sage: msm = finance.MarkovSwitchingMultifractal(8,1.4,1,0.95,3)
doctest:warning...
DeprecationWarning: ...finance... is deprecated...
sage: msm.m0()
1.4
"""
Expand All @@ -140,6 +151,8 @@ def sigma(self):
EXAMPLES::
sage: msm = finance.MarkovSwitchingMultifractal(8,1.4,1,0.95,3)
doctest:warning...
DeprecationWarning: ...finance... is deprecated...
sage: msm.sigma()
1.0
"""
Expand All @@ -152,6 +165,8 @@ def b(self):
EXAMPLES::
sage: msm = finance.MarkovSwitchingMultifractal(8,1.4,1,0.95,3)
doctest:warning...
DeprecationWarning: ...finance... is deprecated...
sage: msm.b()
3.0
"""
Expand All @@ -164,6 +179,8 @@ def gamma_kbar(self):
EXAMPLES::
sage: msm = finance.MarkovSwitchingMultifractal(8,1.4,0.01,0.95,3)
doctest:warning...
DeprecationWarning: ...finance... is deprecated...
sage: msm.gamma_kbar()
0.95
"""
Expand All @@ -176,6 +193,8 @@ def kbar(self):
EXAMPLES::
sage: msm = finance.MarkovSwitchingMultifractal(8,1.4,0.01,0.95,3)
doctest:warning...
DeprecationWarning: ...finance... is deprecated...
sage: msm.kbar()
8
"""
Expand All @@ -192,6 +211,8 @@ def gamma(self):
EXAMPLES::
sage: msm = finance.MarkovSwitchingMultifractal(8,1.4,1.0,0.95,3)
doctest:warning...
DeprecationWarning: ...finance... is deprecated...
sage: msm.gamma()
(0.001368852970712986, 0.004100940201672509, 0.012252436441829..., 0.03630878209190..., 0.10501923017634..., 0.28312883556311..., 0.6315968501359..., 0.95000000000000...)
"""
Expand Down Expand Up @@ -224,6 +245,8 @@ def simulation(self, n):
EXAMPLES::
sage: msm = finance.MarkovSwitchingMultifractal(8,1.4,1.0,0.95,3)
doctest:warning...
DeprecationWarning: ...finance... is deprecated...
sage: m = msm.simulation(5); m # random
[0.0059, -0.0097, -0.0101, -0.0110, -0.0067]
sage: len(m)
Expand Down Expand Up @@ -253,6 +276,8 @@ def simulations(self, n, k=1):
EXAMPLES::
sage: cad_usd = finance.MarkovSwitchingMultifractal(10,1.278,0.262,0.644,2.11); cad_usd
doctest:warning...
DeprecationWarning: ...finance... is deprecated...
Markov switching multifractal model with m0 = 1.278, sigma = 0.262, b = 2.11, and gamma_10 = 0.644
"""
from . import markov_multifractal_cython
Expand Down
18 changes: 18 additions & 0 deletions src/sage/finance/stock.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ def __repr__(self):
EXAMPLES::
sage: finance.Stock('ibm').__repr__() # optional -- internet # known bug
doctest:warning...
DeprecationWarning: Importing finance from here is deprecated...
'IBM (...)'
"""
return "%s (%s)" % (self.symbol, self.market_value())
Expand All @@ -197,6 +199,8 @@ def market_value(self):
EXAMPLES::
sage: finance.Stock('goog').market_value() # random; optional - internet # known bug
doctest:warning...
DeprecationWarning: Importing finance from here is deprecated...
575.83000000000004
"""
return float(self.current_price_data()['price'])
Expand All @@ -222,6 +226,8 @@ def current_price_data(self):
EXAMPLES::
sage: finance.Stock('GOOG').current_price_data() # random; optional - internet # known bug
doctest:warning...
DeprecationWarning: Importing finance from here is deprecated...
{'200day_moving_avg': '536.57',
'50day_moving_avg': '546.01',
'52_week_high': '599.65',
Expand Down Expand Up @@ -329,6 +335,8 @@ def history(self, startdate='Jan+1,+1900', enddate=None, histperiod='daily'):
We get the first five days of VMware's stock history::
sage: finance.Stock('vmw').history('Aug+13,+2007')[:5] # optional -- internet # known bug
doctest:warning...
DeprecationWarning: Importing finance from here is deprecated...
[
14-Aug-07 50.00 55.50 48.00 51.00 38262850,
15-Aug-07 52.11 59.87 51.50 57.71 10689100,
Expand Down Expand Up @@ -428,6 +436,8 @@ def open(self, *args, **kwds):
You can directly obtain Open data as so::
sage: finance.Stock('vmw').open(startdate='Jan+1,+2008', enddate='Feb+1,+2008') # optional -- internet # known bug
doctest:warning...
DeprecationWarning: Importing finance from here is deprecated...
[85.4900, 84.9000, 82.0000, 81.2500, ... 82.0000, 58.2700, 54.4900, 55.6000, 56.9800]
Or, you can initialize stock data first and then extract the Open
Expand Down Expand Up @@ -487,6 +497,8 @@ def close(self, *args, **kwds):
You can directly obtain close data as so::
sage: finance.Stock('vmw').close(startdate='Jan+1,+2008', enddate='Feb+1,+2008') # optional -- internet # known bug
doctest:warning...
DeprecationWarning: Importing finance from here is deprecated...
[84.6000, 83.9500, 80.4900, 72.9900, ... 83.0000, 54.8700, 56.4200, 56.6700, 57.8500]
Or, you can initialize stock data first and then extract the Close
Expand Down Expand Up @@ -551,6 +563,8 @@ def load_from_file(self, file):
sage: with open(filename, 'w') as fobj:
....: _ = fobj.write("Date,Open,High,Low,Close,Volume\n1212405780,187.80,187.80,187.80,187.80,100\n1212407640,187.75,188.00,187.75,188.00,2000\n1212407700,188.00,188.00,188.00,188.00,1000\n1212408000,188.00,188.11,188.00,188.00,2877\n1212408060,188.00,188.00,188.00,188.00,687")
sage: finance.Stock('aapl').load_from_file(filename)[:5]
doctest:warning...
DeprecationWarning: Importing finance from here is deprecated...
...
1212408060 188.00 188.00 188.00 188.00 687,
1212408000 188.00 188.11 188.00 188.00 2877,
Expand Down Expand Up @@ -590,6 +604,8 @@ def _load_from_csv(self, R):
sage: with open(filename,'w') as fobj:
....: _ = fobj.write("Date,Open,High,Low,Close,Volume\n1212405780,187.80,187.80,187.80,187.80,100\n1212407640,187.75,188.00,187.75,188.00,2000\n1212407700,188.00,188.00,188.00,188.00,1000\n1212408000,188.00,188.11,188.00,188.00,2877\n1212408060,188.00,188.00,188.00,188.00,687")
sage: finance.Stock('aapl').load_from_file(filename)
doctest:warning...
DeprecationWarning: Importing finance from here is deprecated...
[
1212408060 188.00 188.00 188.00 188.00 687,
1212408000 188.00 188.11 188.00 188.00 2877,
Expand Down Expand Up @@ -619,6 +635,8 @@ def _get_data(self, exchange, startdate, enddate, histperiod='daily'):
This indirectly tests the use of ``_get_data()``::
sage: finance.Stock('aapl').history(startdate='Jan+1,+1990',enddate='Jan+1,+1991')[:2] # optional -- internet # known bug
doctest:warning...
DeprecationWarning: Importing finance from here is deprecated...
[
2-Jan-90 0.00 1.34 1.25 1.33 45799600,
3-Jan-90 0.00 1.36 1.34 1.34 51998800
Expand Down

0 comments on commit e58be77

Please sign in to comment.