From e58be77233d7be5941ceeb50ed07d6ccbac4a91f Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 30 Mar 2023 07:25:56 -0700 Subject: [PATCH] src/sage/finance: Update doctests: Top-level lazy_import deprecation warnings are now local to tests --- src/sage/finance/fractal.pyx | 8 +++++++- src/sage/finance/markov_multifractal.py | 27 ++++++++++++++++++++++++- src/sage/finance/stock.py | 18 +++++++++++++++++ 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/src/sage/finance/fractal.pyx b/src/sage/finance/fractal.pyx index ed67ade8181..d88467567a9 100644 --- a/src/sage/finance/fractal.pyx +++ b/src/sage/finance/fractal.pyx @@ -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:: @@ -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]] @@ -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) @@ -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], diff --git a/src/sage/finance/markov_multifractal.py b/src/sage/finance/markov_multifractal.py index 6206f56b304..82d14220a0f 100644 --- a/src/sage/finance/markov_multifractal.py +++ b/src/sage/finance/markov_multifractal.py @@ -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) @@ -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 @@ -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, @@ -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 @@ -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' """ @@ -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 """ @@ -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 """ @@ -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 """ @@ -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 """ @@ -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 """ @@ -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...) """ @@ -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) @@ -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 diff --git a/src/sage/finance/stock.py b/src/sage/finance/stock.py index 0ffa2854853..659a651ce67 100644 --- a/src/sage/finance/stock.py +++ b/src/sage/finance/stock.py @@ -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()) @@ -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']) @@ -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', @@ -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, @@ -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 @@ -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 @@ -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, @@ -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, @@ -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