Skip to content

Commit 8e6ce22

Browse files
committed
Fixes Small Capitalization Stocks Premium Anomaly Algorithm
Fixes the issue on the Universe Selection functions returning empty list of Symbol that unsubscribes them. Refactors the algorithm to use a pattern that does not depend on Schedule Events and rely on OnSecuritiesChanged to liquidate securities.
1 parent 32fd8ab commit 8e6ce22

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

04 Strategy Library/28 Small Capitalization Stocks Premium Anomaly/02 Method.html

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,26 @@
22
The first step is coarse universe selection. We create an investment universe with stocks that have fundmental data and with a price greater than $5.
33
</p>
44
<div class="section-example-container">
5-
<pre class="python">self.filtered_coarse = [x.Symbol for x in coarse if (x.HasFundamentalData) and (float(x.AdjustedPrice) > 5)]
5+
<pre class="python">return [x.Symbol for x in coarse if x.HasFundamentalData and x.AdjustedPrice > 5]
66
</pre>
77
</div>
88
<p>In fine universe selection, we sort the stocks in the universe by the market capitalization and choose 10 stocks with the lowest market cap.
99
</p>
1010
<div class="section-example-container">
1111
<pre class="python">def FineSelectionFunction(self, fine):
12-
if self.yearly_rebalance:
13-
fine = [x for x in fine if (x.ValuationRatios.PERatio > 0)
14-
and (x.EarningReports.BasicAverageShares.ThreeMonths > 0)
15-
and (x.EarningReports.BasicEPS.TwelveMonths > 0)]
16-
for i in fine:
17-
i.MarketCap = float(i.EarningReports.BasicAverageShares.ThreeMonths * (i.EarningReports.BasicEPS.TwelveMonths*i.ValuationRatios.PERatio))
18-
sorted_market_cap = sorted(fine, key=lambda x: x.MarketCap)
19-
self.filtered_fine = [i.Symbol for i in sorted_market_cap[:20]]
20-
self.yearly_rebalance = False
21-
return self.filtered_fine
22-
else:
23-
return []
12+
if self.year == self.Time.year:
13+
return self.symbols
14+
15+
# Calculate the market cap and add the "MarketCap" property to fine universe object
16+
for i in fine:
17+
i.MarketCap = (i.EarningReports.BasicAverageShares.ThreeMonths *
18+
i.EarningReports.BasicEPS.TwelveMonths *
19+
i.ValuationRatios.PERatio)
20+
21+
sorted_market_cap = sorted([x for x in fine if x.MarketCap > 0], key=lambda x: x.MarketCap)
22+
23+
self.symbols = [i.Symbol for i in sorted_market_cap[:10]]
24+
return self.symbols
2425
</pre>
2526
</div>
2627
<p>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
div class="qc-embed-frame" style="display: inline-block; position: relative; width: 100%; min-height: 100px; min-width: 300px;">
22
<div class="qc-embed-dummy" style="padding-top: 56.25%;"></div>
33
<div class="qc-embed-element" style="position: absolute; top: 0; bottom: 0; left: 0; right: 0;">
4-
<iframe class="qc-embed-backtest" height="100%" width="100%" style="border: 1px solid #ccc; padding: 0; margin: 0;" src="https://www.quantconnect.com/terminal/index.php?key=processCache&request=embedded_backtest_da3bf5ee608fb8b7dc952372dd925542.html"></iframe>
4+
<iframe class="qc-embed-backtest" height="100%" width="100%" style="border: 1px solid #ccc; padding: 0; margin: 0;" src="https://www.quantconnect.com/terminal/processCache?request=embedded_backtest_cc510b17cc0f58224282d37fa49643e8.html"></iframe>
55
</div>
66
</div>

0 commit comments

Comments
 (0)