| Conditions | 1 | 
| Total Lines | 71 | 
| Lines | 0 | 
| Ratio | 0 % | 
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | # | ||
| 36 | @classmethod | ||
| 37 | def setUpClass(cls): | ||
| 38 | cls.env = TradingEnvironment() | ||
| 39 | cls.tempdir = TempDirectory() | ||
| 40 | |||
| 41 | cls.sim_params = factory.create_simulation_parameters() | ||
| 42 | |||
| 43 |         cls.env.write_data(equities_data={ | ||
| 44 |             1: { | ||
| 45 | "start_date": cls.sim_params.trading_days[0], | ||
| 46 | "end_date": cls.sim_params.trading_days[-1] + timedelta(days=1) | ||
| 47 | }, | ||
| 48 |             2: { | ||
| 49 | "start_date": cls.sim_params.trading_days[0], | ||
| 50 | "end_date": cls.sim_params.trading_days[-1] + timedelta(days=1) | ||
| 51 | }, | ||
| 52 |             3: { | ||
| 53 | "start_date": cls.sim_params.trading_days[100], | ||
| 54 | "end_date": cls.sim_params.trading_days[-100] | ||
| 55 | }, | ||
| 56 |             4: { | ||
| 57 | "start_date": cls.sim_params.trading_days[0], | ||
| 58 | "end_date": cls.sim_params.trading_days[-1] + timedelta(days=1) | ||
| 59 | } | ||
| 60 | |||
| 61 | }) | ||
| 62 | |||
| 63 | dbpath = os.path.join(cls.tempdir.path, "adjustments.db") | ||
| 64 | |||
| 65 | writer = SQLiteAdjustmentWriter(dbpath, cls.env.trading_days, | ||
| 66 | MockDailyBarSpotReader()) | ||
| 67 | splits = mergers = pd.DataFrame( | ||
| 68 |             { | ||
| 69 | # Hackery to make the dtypes correct on an empty frame. | ||
| 70 | 'effective_date': np.array([], dtype=int), | ||
| 71 | 'ratio': np.array([], dtype=float), | ||
| 72 | 'sid': np.array([], dtype=int), | ||
| 73 | }, | ||
| 74 | index=pd.DatetimeIndex([], tz='UTC'), | ||
| 75 | columns=['effective_date', 'ratio', 'sid'], | ||
| 76 | ) | ||
| 77 |         dividends = pd.DataFrame({ | ||
| 78 | 'sid': np.array([], dtype=np.uint32), | ||
| 79 | 'amount': np.array([], dtype=np.float64), | ||
| 80 | 'declared_date': np.array([], dtype='datetime64[ns]'), | ||
| 81 | 'ex_date': np.array([], dtype='datetime64[ns]'), | ||
| 82 | 'pay_date': np.array([], dtype='datetime64[ns]'), | ||
| 83 | 'record_date': np.array([], dtype='datetime64[ns]'), | ||
| 84 | }) | ||
| 85 | declared_date = cls.sim_params.trading_days[45] | ||
| 86 | ex_date = cls.sim_params.trading_days[50] | ||
| 87 | record_date = pay_date = cls.sim_params.trading_days[55] | ||
| 88 | |||
| 89 |         stock_dividends = pd.DataFrame({ | ||
| 90 | 'sid': np.array([4], dtype=np.uint32), | ||
| 91 | 'payment_sid': np.array([5], dtype=np.uint32), | ||
| 92 | 'ratio': np.array([2], dtype=np.float64), | ||
| 93 | 'declared_date': np.array([declared_date], dtype='datetime64[ns]'), | ||
| 94 | 'ex_date': np.array([ex_date], dtype='datetime64[ns]'), | ||
| 95 | 'record_date': np.array([record_date], dtype='datetime64[ns]'), | ||
| 96 | 'pay_date': np.array([pay_date], dtype='datetime64[ns]'), | ||
| 97 | }) | ||
| 98 | writer.write(splits, mergers, dividends, | ||
| 99 | stock_dividends=stock_dividends) | ||
| 100 | |||
| 101 | cls.data_portal = create_data_portal( | ||
| 102 | cls.env, | ||
| 103 | cls.tempdir, | ||
| 104 | cls.sim_params, | ||
| 105 | [1, 2, 3, 4], | ||
| 106 | adjustment_reader=SQLiteAdjustmentReader(dbpath) | ||
| 107 | ) | ||
| 215 |