| Conditions | 34 | 
| Total Lines | 158 | 
| 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:
Complex classes like zipline.gens.AlgorithmSimulator._process_snapshot() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | #  | 
            ||
| 160 | splits = data_portal.get_splits(sids_we_care_about,  | 
            ||
| 161 | midnight_dt)  | 
            ||
| 162 | if len(splits) > 0:  | 
            ||
| 163 | algo.blotter.process_splits(splits)  | 
            ||
| 164 | perf_tracker.position_tracker.handle_splits(splits)  | 
            ||
| 165 | |||
| 166 | def handle_benchmark(date):  | 
            ||
| 167 | algo.perf_tracker.all_benchmark_returns[date] = \  | 
            ||
| 168 | self.benchmark_source.get_value(date)  | 
            ||
| 169 | |||
| 170 | with self.processor, ZiplineAPI(self.algo):  | 
            ||
| 171 | for dt, action in self.clock:  | 
            ||
| 172 | if action == BAR:  | 
            ||
| 173 | every_bar(dt)  | 
            ||
| 174 | elif action == DAY_START:  | 
            ||
| 175 | once_a_day(dt)  | 
            ||
| 176 | elif action == DAY_END:  | 
            ||
| 177 | # End of the day.  | 
            ||
| 178 | handle_benchmark(dt)  | 
            ||
| 179 | yield self._get_daily_message(dt, algo, algo.perf_tracker)  | 
            ||
| 180 | elif action == MINUTE_END:  | 
            ||
| 181 | handle_benchmark(dt)  | 
            ||
| 182 | minute_msg, daily_msg = \  | 
            ||
| 183 | self._get_minute_message(dt, algo, algo.perf_tracker)  | 
            ||
| 184 | |||
| 185 | yield minute_msg  | 
            ||
| 186 | |||
| 187 | if daily_msg:  | 
            ||
| 188 | yield daily_msg  | 
            ||
| 189 | |||
| 190 | risk_message = algo.perf_tracker.handle_simulation_end()  | 
            ||
| 191 | yield risk_message  | 
            ||
| 192 | |||
| 193 | @staticmethod  | 
            ||
| 194 | def _get_daily_message(dt, algo, perf_tracker):  | 
            ||
| 195 | """  | 
            ||
| 196 | Get a perf message for the given datetime.  | 
            ||
| 197 | """  | 
            ||
| 198 | perf_message = perf_tracker.handle_market_close_daily(dt)  | 
            ||
| 199 | perf_message['daily_perf']['recorded_vars'] = algo.recorded_vars  | 
            ||
| 200 | return perf_message  | 
            ||
| 201 | |||
| 202 | @staticmethod  | 
            ||
| 203 | def _get_minute_message(dt, algo, perf_tracker):  | 
            ||
| 204 | """  | 
            ||
| 205 | Get a perf message for the given datetime.  | 
            ||
| 206 | """  | 
            ||
| 207 | rvars = algo.recorded_vars  | 
            ||
| 208 | |||
| 209 | minute_message, daily_message = perf_tracker.handle_minute_close(dt)  | 
            ||
| 210 | minute_message['minute_perf']['recorded_vars'] = rvars  | 
            ||
| 211 | |||
| 212 | if daily_message:  | 
            ||
| 213 | daily_message["daily_perf"]["recorded_vars"] = rvars  | 
            ||
| 214 | |||
| 215 | return minute_message, daily_message  | 
            ||
| 216 |