Skip to content

Commit

Permalink
Code generated by Alternative-Datasets-Code-Generator.py
Browse files Browse the repository at this point in the history
  • Loading branch information
GitHub authored and AlexCatarino committed Jan 4, 2025
1 parent 2774d3c commit fefae88
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 58 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<p>The Bybit Crypto Price dataset provides <b>TradeBar</b>, <b>QuoteBar</b>, <b>Tick</b>, and <b>CryptoCoarseFundamental</b> objects.</p>
<p>The Bybit Crypto Price dataset provides <b>TradeBar</b>, <b>QuoteBar</b>, <b>Tick</b>, and <b>CryptoUniverse</b> objects.</p>

<h4>TradeBar Attributes</h4>
<p><b>TradeBar</b> objects have the following attributes:</p>
Expand All @@ -12,6 +12,6 @@ <h4>Tick Attributes</h4>
<p><b>Tick</b> objects have the following attributes:</p>
<div data-tree="QuantConnect.Data.Market.Tick"></div>

<h4>CryptoCoarseFundamental Attributes</h4>
<p><b>CryptoCoarseFundamental</b> objects have the following attributes:</p>
<div data-tree="QuantConnect.DataSource.CryptoCoarseFundamental"></div>
<h4>CryptoUniverse Attributes</h4>
<p><b>CryptoUniverse</b> objects have the following attributes:</p>
<div data-tree="QuantConnect.DataSource.CryptoUniverse"></div>
Original file line number Diff line number Diff line change
@@ -1,36 +1,59 @@
<p>To select a dynamic universe of Cryptos based on CoinGecko Crypto Market Cap data, call the <b class="csharp">AddUniverse</b><b class="python">add_universe</b> method with the <b>CoinGeckoUniverse</b> class and a selection function. Note that the filtered output is a list of names of the coins. If corresponding tradable crypto pairs are preferred, call <b class="csharp">CreateSymbol(market, quoteCurrency)</b><b class="python">create_symbol(market, quoteCurrency)</b> method for each output item.</p>

<div class="section-example-container">
<pre class="python">def initialize(self) -&gt; None:
self._universe = self.add_universe(CoinGeckoUniverse, self.universe_selection)
<pre class="python">class CryptoMarketCapUniverseAlgorithm(QCAlgorithm):

def universe_selection(self, data: List[CoinGeckoUniverse]) -&gt; List[Symbol]:
for datum in data:
self.debug(f'{datum.coin},{datum.market_cap},{datum.price}')
def initialize(self) -&gt; None:
self.set_account_currency("USD")
self._market = Market.COINBASE
self._market_pairs = [
x.key.symbol
for x in self.symbol_properties_database.get_symbol_properties_list(self._market)
if x.value.quote_currency == self.account_currency
]
self._universe = self.add_universe(CoinGeckoUniverse, self._select_assets)

# define our selection criteria
selected = sorted(data, key=lambda x: x.market_cap, reverse=True)[:3]

# Use the CreateSymbol method to generate the Symbol object for
# the desired market (Coinbase) and quote currency (e.g. USD)
return [x.create_symbol(Market.COINBASE, "USD") for x in selected]</pre>
<pre class="csharp">private Universe _universe;
public override void Initialize()
def _select_assets(self, data: List[CoinGeckoUniverse]) -&gt; List[Symbol]:
for datum in data:
self.debug(f'{datum.coin},{datum.market_cap},{datum.price}')

# Select the coins that our brokerage supports and have a quote currency that matches
# our account currency.
tradable_coins = [d for d in data if d.coin + self.account_currency in self._market_pairs]
# Select the largest coins and create their Symbol objects.
return [
c.create_symbol(self._market, self.account_currency)
for c in sorted(tradable_coins, key=lambda x: x.market_cap)[-10:]
]</pre>
<pre class="csharp">public class CryptoMarketCapUniverseAlgorithm : QCAlgorithm
{
_universe = AddUniverse&lt;CoinGecko&gt;(data =&gt;
private Universe _universe;
public override void Initialize()
{
foreach (var datum in data.OfType&lt;CoinGecko&gt;())
SetAccountCurrency("USD");
var market = Market.Coinbase;
var marketPairs = SymbolPropertiesDatabase.GetSymbolPropertiesList(market)
.Where(x =&gt; x.Value.QuoteCurrency == AccountCurrency)
.Select(x =&gt; x.Key.Symbol)
.ToList();
_universe = AddUniverse&lt;CoinGecko&gt;(data =&gt;
{
Debug($"{datum.Coin},{datum.MarketCap},{datum.Price}");
}

// define our selection criteria
// Use the CreateSymbol method to generate the Symbol object for
// the desired market (Coinbase) and quote currency (e.g. USD)
return (from d in data.OfType&lt;CoinGeckoUniverse&gt;()
orderby d.MarketCap descending
select d.CreateSymbol(Market.Coinbase, "USD")).Take(3);
});
foreach (var datum in data.OfType&lt;CoinGecko&gt;())
{
Debug($"{datum.Coin},{datum.MarketCap},{datum.Price}");
}
return data
.Select(c =&gt; c as CoinGecko)
// Select the coins that the brokerage supports and have a quote currency that
// matches our account currency.
.Where(c =&gt; marketPairs.Contains(c.Coin + AccountCurrency))
// Select the 10 largest coins.
.OrderByDescending(c =&gt; c.MarketCap)
.Take(10)
// Create the Symbol objects of the selected coins.
.Select(c =&gt; c.CreateSymbol(market, AccountCurrency)
});
}
}</pre>
</div>

Expand Down
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]) -&gt; 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]) &gt;= 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]) -&gt; 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&lt;QuiverInsiderTradingUniverse&gt;(altCoarse =&gt;
private Universe _universe;

public override void Initialize()
{
var insiderTradingDataBySymbol = new Dictionary&lt;Symbol, List&lt;QuiverInsiderTradingUniverse&gt;&gt;();
SetStartDate(2023, 1, 1);
_universe = AddUniverse&lt;QuiverInsiderTradingUniverse&gt;(SelectAssets);
}

foreach (var datum in altCoarse.OfType&lt;QuiverInsiderTradingUniverse&gt;())
private IEnumerable&lt;Symbol&gt; SelectAssets(IEnumerable&lt;BaseData&gt; altCoarse)
{
var dollarVolumeBySymbol = new Dictionary&lt;Symbol, decimal?&gt;();
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&lt;QuiverInsiderTradingUniverse&gt;());
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 =&gt; x.Direction == OrderDirection.Buy) &gt;= 3
select kvp.Key;
});
return dollarVolumeBySymbol
.OrderByDescending(kvp =&gt; kvp.Value)
.Take(10)
.Select(kvp =&gt; kvp.Key);
}
}</pre>
</div>

0 comments on commit fefae88

Please sign in to comment.