-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Code generated by Alternative-Datasets-Code-Generator.py
- Loading branch information
1 parent
2774d3c
commit fefae88
Showing
3 changed files
with
92 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 48 additions & 25 deletions
73
...iting Algorithms/14 Datasets/11 CoinGecko/01 Crypto Market Cap/11 Universe Selection.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 40 additions & 29 deletions
69
...gorithms/14 Datasets/20 Quiver Quantitative/03 Insider Trading/10 Universe Selection.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,53 @@ | ||
<p>To select a dynamic universe of US Equities based on Insider Trading data, call the <b class="csharp">AddUniverse</b><b class="python">add_universe</b> method with the <b>QuiverInsiderTradingUniverse</b> class and a selection function.</p> | ||
|
||
<div class="section-example-container"> | ||
<pre class="python">def initialize(self): | ||
self._universe = self.add_universe(QuiverInsiderTradingUniverse, self.universe_selection) | ||
|
||
def universe_selection(self, alt_coarse: List[QuiverInsiderTradingUniverse]) -> List[Symbol]: | ||
insider_trading_data_by_symbol = {} | ||
|
||
for datum in alt_coarse: | ||
symbol = datum.symbol | ||
|
||
if symbol not in insider_trading_data_by_symbol: | ||
insider_trading_data_by_symbol[symbol] = [] | ||
insider_trading_data_by_symbol[symbol].append(datum) | ||
<pre class="python">class InsiderTradingUniverseAlgorithm(QCAlgorithm): | ||
|
||
return [symbol for symbol, d in insider_trading_data_by_symbol.items() | ||
if len([x for x in d if x.direction == OrderDirection.BUY]) >= 3]</pre> | ||
<pre class="csharp">private Universe _universe; | ||
public override void Initialize() | ||
def initialize(self): | ||
self.set_start_date(2023, 1, 1) | ||
self._universe = self.add_universe(QuiverInsiderTradingUniverse, self._select_assets) | ||
|
||
def _select_assets(self, alt_coarse: List[QuiverInsiderTradingUniverse]) -> List[Symbol]: | ||
dollar_volume_by_symbol = {} | ||
for data in alt_coarse: | ||
symbol = data.symbol | ||
if not data.price_per_share: | ||
continue | ||
if symbol not in dollar_volume_by_symbol: | ||
dollar_volume_by_symbol[symbol] = 0 | ||
dollar_volume_by_symbol[symbol] += data.shares * data.price_per_share | ||
return [ | ||
symbol for symbol, _ in sorted(dollar_volume_by_symbol.items(), key=lambda kvp: kvp[1])[-10:] | ||
]</pre> | ||
<pre class="csharp">public class InsiderTradingUniverseAlgorithm : QCAlgorithm | ||
{ | ||
_universe = AddUniverse<QuiverInsiderTradingUniverse>(altCoarse => | ||
private Universe _universe; | ||
|
||
public override void Initialize() | ||
{ | ||
var insiderTradingDataBySymbol = new Dictionary<Symbol, List<QuiverInsiderTradingUniverse>>(); | ||
SetStartDate(2023, 1, 1); | ||
_universe = AddUniverse<QuiverInsiderTradingUniverse>(SelectAssets); | ||
} | ||
|
||
foreach (var datum in altCoarse.OfType<QuiverInsiderTradingUniverse>()) | ||
private IEnumerable<Symbol> SelectAssets(IEnumerable<BaseData> altCoarse) | ||
{ | ||
var dollarVolumeBySymbol = new Dictionary<Symbol, decimal?>(); | ||
foreach (QuiverInsiderTradingUniverse data in altCoarse) | ||
{ | ||
var symbol = datum.Symbol; | ||
|
||
if (!insiderTradingDataBySymbol.ContainsKey(symbol)) | ||
if (data.PricePerShare == 0m) | ||
{ | ||
continue; | ||
} | ||
if (!dollarVolumeBySymbol.ContainsKey(data.Symbol)) | ||
{ | ||
insiderTradingDataBySymbol.Add(symbol, new List<QuiverInsiderTradingUniverse>()); | ||
dollarVolumeBySymbol[data.Symbol] = 0; | ||
} | ||
insiderTradingDataBySymbol[symbol].Add(datum); | ||
dollarVolumeBySymbol[data.Symbol] += data.Shares * data.PricePerShare; | ||
} | ||
|
||
return from kvp in insiderTradingDataBySymbol | ||
where kvp.Value.Where(x => x.Direction == OrderDirection.Buy) >= 3 | ||
select kvp.Key; | ||
}); | ||
return dollarVolumeBySymbol | ||
.OrderByDescending(kvp => kvp.Value) | ||
.Take(10) | ||
.Select(kvp => kvp.Key); | ||
} | ||
}</pre> | ||
</div> |