|
9 | 9 | </p> |
10 | 10 |
|
11 | 11 | <div class="section-example-container"> |
12 | | -<pre class="python"> |
| 12 | + <pre class="python"> |
13 | 13 | def CoarseSelectionFunction(self, coarse): |
14 | | - if self.yearly_rebalance: |
15 | | - # drop stocks which have no fundamental data and have low price |
16 | | - CoarseWithFundamental = [x for x in coarse if x.HasFundamentalData and x.Price > 5] |
17 | | - sortedByDollarVolume = sorted(CoarseWithFundamental, key=lambda x: x.DollarVolume, reverse=False) |
18 | | - top = sortedByDollarVolume[:self._NumCoarseStocks] |
19 | | - return [i.Symbol for i in top] |
20 | | - else: |
21 | | - return [] |
| 14 | + if self.Time.year == self.year: return [] |
| 15 | + |
| 16 | + # drop stocks which have no fundamental data or have low price |
| 17 | + CoarseWithFundamental = [x for x in coarse if x.HasFundamentalData and x.Price > 5] |
| 18 | + sortedByDollarVolume = sorted(CoarseWithFundamental, key=lambda x: x.DollarVolume, reverse=False) |
| 19 | + top = sortedByDollarVolume[:self._NumCoarseStocks] |
| 20 | + return [i.Symbol for i in top] |
22 | 21 | </pre> |
23 | 22 | </div> |
24 | 23 |
|
|
27 | 26 | </p> |
28 | 27 |
|
29 | 28 | <div class="section-example-container"> |
30 | | -<pre class="python"> |
| 29 | + <pre class="python"> |
31 | 30 |
|
32 | 31 | def FineSelectionFunction(self, fine): |
33 | | - if self.yearly_rebalance: |
| 32 | + if self.Time.year == self.year: |
| 33 | + self.filtered_fine = [] |
| 34 | + else: |
34 | 35 | fine = [x for x in fine if (x.ValuationRatios.PERatio > 0)] |
35 | 36 | for i in fine: |
36 | 37 | i.PERatio = float(i.ValuationRatios.PERatio) |
37 | | - sortedPERatio = sorted(fine, key=lambda x: x.PERatio,reverse=True) |
| 38 | + sortedPERatio = sorted(fine, key=lambda x: x.PERatio) |
| 39 | + |
38 | 40 | self.filtered_fine = [i.Symbol for i in sortedPERatio[:self._NumStocksInPortfolio]] |
39 | | - self.yearly_rebalance = False |
40 | | - return self.filtered_fine |
41 | | - else: |
42 | | - return [] |
| 41 | + |
| 42 | + return self.filtered_fine |
43 | 43 | </pre> |
44 | 44 | </div> |
45 | 45 |
|
|
0 commit comments