diff --git a/01 Cloud Platform/10 Live Trading/03 Data Feeds/01 US Equities/03 Universe Selection.php b/01 Cloud Platform/10 Live Trading/03 Data Feeds/01 US Equities/03 Universe Selection.php index 6f98429966..23b97fac04 100644 --- a/01 Cloud Platform/10 Live Trading/03 Data Feeds/01 US Equities/03 Universe Selection.php +++ b/01 Cloud Platform/10 Live Trading/03 Data Feeds/01 US Equities/03 Universe Selection.php @@ -1,14 +1,14 @@

The US Equities data feed enables you to create a dynamic universe of securities.

-

Coarse-Fine Universe

- +

Fundamental Universe

+
-
AddUniverse(SelectCoarse, SelectFine);
-
self.AddUniverse(self.SelectCoarse, self.SelectFine)
+
AddUniverse(SelectFundamental);
+
self.AddUniverse(self.SelectFundamental)

ETF Constituent Universe

-

The US Equities data feed enables you to create a universe of securities to match the constituents of an ETF. For more information about ETF universes, see ETF Constituents Selection .

+

The US Equities data feed enables you to create a universe of securities to match the constituents of an ETF. For more information about ETF universes, see ETF Constituents Selection.

var spy = AddEquity("SPY").Symbol;
diff --git a/01 Cloud Platform/10 Live Trading/03 Data Feeds/09 Brokerage Data Feeds/01 Interactive Brokers/03 Universe Selection.php b/01 Cloud Platform/10 Live Trading/03 Data Feeds/09 Brokerage Data Feeds/01 Interactive Brokers/03 Universe Selection.php
index dd0874de39..ddf39c099d 100644
--- a/01 Cloud Platform/10 Live Trading/03 Data Feeds/09 Brokerage Data Feeds/01 Interactive Brokers/03 Universe Selection.php	
+++ b/01 Cloud Platform/10 Live Trading/03 Data Feeds/09 Brokerage Data Feeds/01 Interactive Brokers/03 Universe Selection.php	
@@ -1,6 +1,7 @@
-
 
 

The universe selection data comes from our Dataset Market, not the TWS market scanners. Universe selection with the IB data feed occurs around 6-7 AM Eastern Time (ET) on Tuesday to Friday and at 2 AM ET on Sunday. Universe selection data isn't available when the IB servers are closed. To check the IB server status, see the Current System Status page on the IB website.

diff --git a/01 Cloud Platform/10 Live Trading/03 Data Feeds/09 Brokerage Data Feeds/03 Tradier/03 Universe Selection.php b/01 Cloud Platform/10 Live Trading/03 Data Feeds/09 Brokerage Data Feeds/03 Tradier/03 Universe Selection.php index d6e226b0c2..80a91f32b0 100644 --- a/01 Cloud Platform/10 Live Trading/03 Data Feeds/09 Brokerage Data Feeds/03 Tradier/03 Universe Selection.php +++ b/01 Cloud Platform/10 Live Trading/03 Data Feeds/09 Brokerage Data Feeds/03 Tradier/03 Universe Selection.php @@ -1,4 +1,5 @@ - \ No newline at end of file diff --git a/08 Drafts/03 Writing Algorithms/03 Securities/01 Key Concepts/08 Fundamental Data.html b/03 Writing Algorithms/03 Securities/01 Key Concepts/08 Fundamental Data.html similarity index 89% rename from 08 Drafts/03 Writing Algorithms/03 Securities/01 Key Concepts/08 Fundamental Data.html rename to 03 Writing Algorithms/03 Securities/01 Key Concepts/08 Fundamental Data.html index 8e2f5c2952..a7c04b7b55 100644 --- a/08 Drafts/03 Writing Algorithms/03 Securities/01 Key Concepts/08 Fundamental Data.html +++ b/03 Writing Algorithms/03 Securities/01 Key Concepts/08 Fundamental Data.html @@ -10,4 +10,4 @@
var hasFundamentalData = Securities[_symbol].Fundamentals.HasFundamentalData;
has_fundamental_data = self.Securities[self.symbol].Fundamentals.HasFundamentalData
-

For more information about fundamental data, see Corporate Fundamentals.

+

For more information about fundamental data, see Corporate Fundamentals.

diff --git a/03 Writing Algorithms/03 Securities/01 Key Concepts/08 Linked Custom Data.html b/03 Writing Algorithms/03 Securities/01 Key Concepts/09 Linked Custom Data.html similarity index 100% rename from 03 Writing Algorithms/03 Securities/01 Key Concepts/08 Linked Custom Data.html rename to 03 Writing Algorithms/03 Securities/01 Key Concepts/09 Linked Custom Data.html diff --git a/03 Writing Algorithms/03 Securities/99 Asset Classes/01 US Equity/06 Corporate Fundamentals/01 Introduction.html b/03 Writing Algorithms/03 Securities/99 Asset Classes/01 US Equity/06 Corporate Fundamentals/01 Introduction.html index d32460cbf8..c4f39a1abf 100644 --- a/03 Writing Algorithms/03 Securities/99 Asset Classes/01 US Equity/06 Corporate Fundamentals/01 Introduction.html +++ b/03 Writing Algorithms/03 Securities/99 Asset Classes/01 US Equity/06 Corporate Fundamentals/01 Introduction.html @@ -1 +1 @@ -

Corporate fundamental data contains all the information on the underlying company of an Equity asset and the information in their financial statements. Since corporate data contains information not found in price and alternative data, adding corporate data to your trading strategies provides you with more information so you can make more informed trading decisions. Corporate fundamental data is available through the US Fundamental Data from Morningstar. To get fundamental data into your algorithm, add a fundamental universe.

+

Corporate fundamental data contains all the information on the underlying company of an Equity asset and the information in their financial statements. Since corporate data contains information not found in price and alternative data, adding corporate data to your trading strategies provides you with more information so you can make more informed trading decisions. Corporate fundamental data is available through the US Fundamental Data from Morningstar.

diff --git a/08 Drafts/03 Writing Algorithms/03 Securities/99 Asset Classes/01 US Equity/06 Corporate Fundamentals/02 Direct Access.php b/03 Writing Algorithms/03 Securities/99 Asset Classes/01 US Equity/06 Corporate Fundamentals/02 Direct Access.php similarity index 100% rename from 08 Drafts/03 Writing Algorithms/03 Securities/99 Asset Classes/01 US Equity/06 Corporate Fundamentals/02 Direct Access.php rename to 03 Writing Algorithms/03 Securities/99 Asset Classes/01 US Equity/06 Corporate Fundamentals/02 Direct Access.php diff --git a/03 Writing Algorithms/03 Securities/99 Asset Classes/01 US Equity/06 Corporate Fundamentals/02 Properties.php b/03 Writing Algorithms/03 Securities/99 Asset Classes/01 US Equity/06 Corporate Fundamentals/02 Properties.php deleted file mode 100644 index 38cdf639f0..0000000000 --- a/03 Writing Algorithms/03 Securities/99 Asset Classes/01 US Equity/06 Corporate Fundamentals/02 Properties.php +++ /dev/null @@ -1,8 +0,0 @@ -

To get fundamental data, access the FineFundamental properties in your fine universe selection function or access the Fundamentals property of the Equity objects in your fundamental universe. - -

-
var fundamentals = Securities[_symbol].Fundamentals;
-
fundamentals = self.Securities[self.symbol].Fundamentals
-
- - diff --git a/03 Writing Algorithms/03 Securities/99 Asset Classes/01 US Equity/06 Corporate Fundamentals/03 Historical Data.html b/03 Writing Algorithms/03 Securities/99 Asset Classes/01 US Equity/06 Corporate Fundamentals/03 Historical Data.html deleted file mode 100644 index f531d6ce11..0000000000 --- a/03 Writing Algorithms/03 Securities/99 Asset Classes/01 US Equity/06 Corporate Fundamentals/03 Historical Data.html +++ /dev/null @@ -1 +0,0 @@ -

To get historical fundamental data, set a warm-up period and save the fundamental data during the warm-up period. It’s not currently possible to make a history request for fundamental data in an algorithm. Subscribe to GitHub Issue #4890 to track the feature progress.

\ No newline at end of file diff --git a/08 Drafts/03 Writing Algorithms/03 Securities/99 Asset Classes/01 US Equity/06 Corporate Fundamentals/03 Universe Selection.html b/03 Writing Algorithms/03 Securities/99 Asset Classes/01 US Equity/06 Corporate Fundamentals/03 Universe Selection.html similarity index 100% rename from 08 Drafts/03 Writing Algorithms/03 Securities/99 Asset Classes/01 US Equity/06 Corporate Fundamentals/03 Universe Selection.html rename to 03 Writing Algorithms/03 Securities/99 Asset Classes/01 US Equity/06 Corporate Fundamentals/03 Universe Selection.html diff --git a/03 Writing Algorithms/03 Securities/99 Asset Classes/01 US Equity/06 Corporate Fundamentals/04 Data Updates.html b/03 Writing Algorithms/03 Securities/99 Asset Classes/01 US Equity/06 Corporate Fundamentals/04 Data Updates.html deleted file mode 100644 index dd25a808f1..0000000000 --- a/03 Writing Algorithms/03 Securities/99 Asset Classes/01 US Equity/06 Corporate Fundamentals/04 Data Updates.html +++ /dev/null @@ -1 +0,0 @@ -

The US Fundmamental dataset only provides the originally-reported figures. If there was a mistake in reporting a figure, the data value isn't fixed later. In live trading, new fundamental data is available to your algorithms at approximately 6 AM Eastern Time (ET) each day. The majority of the corporate data update occurs once per month, but the financial ratios update daily. If there is no new data for a period of time, the previous data is filled forward.

\ No newline at end of file diff --git a/08 Drafts/03 Writing Algorithms/03 Securities/99 Asset Classes/01 US Equity/06 Corporate Fundamentals/04 Historical Data.php b/03 Writing Algorithms/03 Securities/99 Asset Classes/01 US Equity/06 Corporate Fundamentals/04 Historical Data.php similarity index 100% rename from 08 Drafts/03 Writing Algorithms/03 Securities/99 Asset Classes/01 US Equity/06 Corporate Fundamentals/04 Historical Data.php rename to 03 Writing Algorithms/03 Securities/99 Asset Classes/01 US Equity/06 Corporate Fundamentals/04 Historical Data.php diff --git a/08 Drafts/03 Writing Algorithms/03 Securities/99 Asset Classes/01 US Equity/06 Corporate Fundamentals/05 Data Updates.html b/03 Writing Algorithms/03 Securities/99 Asset Classes/01 US Equity/06 Corporate Fundamentals/05 Data Updates.html similarity index 100% rename from 08 Drafts/03 Writing Algorithms/03 Securities/99 Asset Classes/01 US Equity/06 Corporate Fundamentals/05 Data Updates.html rename to 03 Writing Algorithms/03 Securities/99 Asset Classes/01 US Equity/06 Corporate Fundamentals/05 Data Updates.html diff --git a/08 Drafts/03 Writing Algorithms/03 Securities/99 Asset Classes/01 US Equity/06 Corporate Fundamentals/06 Properties.php b/03 Writing Algorithms/03 Securities/99 Asset Classes/01 US Equity/06 Corporate Fundamentals/06 Properties.php similarity index 100% rename from 08 Drafts/03 Writing Algorithms/03 Securities/99 Asset Classes/01 US Equity/06 Corporate Fundamentals/06 Properties.php rename to 03 Writing Algorithms/03 Securities/99 Asset Classes/01 US Equity/06 Corporate Fundamentals/06 Properties.php diff --git a/03 Writing Algorithms/12 Universes/01 Key Concepts/05 Selection Functions.html b/03 Writing Algorithms/12 Universes/01 Key Concepts/05 Selection Functions.html index cb480bd1a7..b660608565 100644 --- a/03 Writing Algorithms/12 Universes/01 Key Concepts/05 Selection Functions.html +++ b/03 Writing Algorithms/12 Universes/01 Key Concepts/05 Selection Functions.html @@ -1,27 +1,27 @@

The following example filter function selects the 100 most liquid US Equities.

-
public class MyCoarseUniverseAlgorithm : QCAlgorithm
+
public class MyFundamentalUniverseAlgorithm : QCAlgorithm
 {
     public override void Initialize()
     {
-        AddUniverse(CoarseFilterFunction);
+        AddUniverse(FundamentalFilterFunction);
     }
 
-    private IEnumerable<Symbol> CoarseFilterFunction(IEnumerable<CoarseFundamental> coarse)
+    private IEnumerable<Symbol> FundamentalFilterFunction(IEnumerable<Fundamental> fundamental)
     {
-        return (from c in coarse
+        return (from c in fundamental
             orderby c.DollarVolume descending
             select c.Symbol).Take(100);
     }
 }
-
class MyCoarseUniverseAlgorithm(QCAlgorithm):
+
class MyFundamentalUniverseAlgorithm(QCAlgorithm):
     def Initialize(self) -> None:
-        self.AddUniverse(self.CoarseFilterFunction)
+        self.AddUniverse(self.FundamentalFilterFunction)
 
-    def CoarseFilterFunction(self, coarse: List[CoarseFundamental]) -> List[Symbol]:
-        sorted_by_dollar_volume = sorted(coarse, key=lambda x: x.DollarVolume, reverse=True) 
+    def FundamentalFilterFunction(self, fundamental: List[Fundamental]) -> List[Symbol]:
+        sorted_by_dollar_volume = sorted(fundamental, key=lambda x: x.DollarVolume, reverse=True) 
         return [c.Symbol for c in sorted_by_dollar_volume[:100]]
-

To learn how to define filter functions for other asset classes, custom data universes, or alternative data universes, see the following pages in this Universes chapter.

\ No newline at end of file +

To learn how to define filter functions for other asset classes, custom data universes, or alternative data universes, see the following pages in this Universes chapter.

\ No newline at end of file diff --git a/03 Writing Algorithms/12 Universes/01 Key Concepts/08 Select Current Constituents.html b/03 Writing Algorithms/12 Universes/01 Key Concepts/08 Select Current Constituents.html index 721de2ea0e..8b6c67ac48 100644 --- a/03 Writing Algorithms/12 Universes/01 Key Concepts/08 Select Current Constituents.html +++ b/03 Writing Algorithms/12 Universes/01 Key Concepts/08 Select Current Constituents.html @@ -6,20 +6,19 @@ { public override void Initialize() { - AddUniverse(MyCoarseFilterFunction); + AddUniverse(MyFundamentalFilterFunction); } - IEnumerable<Symbol> MyCoarseFilterFunction(IEnumerable<CoarseFundamental> coarse) + IEnumerable<Symbol> MyFundamentalFilterFunction(IEnumerable<Fundamental> fundamental) { - return Universe.Unchanged; + return Universe.Unchanged; } -} - +}
 class MyUniverseAlgorithm(QCAlgorithm):
-     def Initialize(self) -> None:
-         self.AddUniverse(self.MyCoarseFilterFunction)
+    def Initialize(self) -> None:
+        self.AddUniverse(self.MyFundamentalFilterFunction)
 
-    def MyCoarseFilterFunction(self, coarse: List[CoarseFundamental]) -> List[Symbol]:
-         return Universe.Unchanged
+ def MyFundamentalFilterFunction(self, fundamental: List[Fundamental]) -> List[Symbol]: + return Universe.Unchanged \ No newline at end of file diff --git a/03 Writing Algorithms/12 Universes/01 Key Concepts/09 Universe Manager.html b/03 Writing Algorithms/12 Universes/01 Key Concepts/09 Universe Manager.html index 7159dea0fa..297af9f107 100644 --- a/03 Writing Algorithms/12 Universes/01 Key Concepts/09 Universe Manager.html +++ b/03 Writing Algorithms/12 Universes/01 Key Concepts/09 Universe Manager.html @@ -4,7 +4,7 @@
private Universe _universe;
 
 // In Initialize
-_universe = AddUniverse(MyCoarseFilterFunction);
+_universe = AddUniverse(MyFundamentalFilterFunction);
 
 // In OnData
 var universeMembers = UniverseManager[_universe.Configuration.Symbol].Members;
@@ -14,12 +14,11 @@
     var security = kvp.Value;
 }
# In Initialize
-self.universe = self.AddUniverse(self.MyCoarseFilterFunction)
+self.universe = self.AddUniverse(self.MyFundamentalFilterFunction)
 
 # In OnData
 universe_members = self.UniverseManager[self.universe.Configuration.Symbol].Members
 for kvp in universe_members:
     symbol = kvp.Key
-    security = kvp.Value
-
+ security = kvp.Value \ No newline at end of file diff --git a/08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/01 Liquidity Universes/01 Introduction.html b/03 Writing Algorithms/12 Universes/03 Equity/01 Liquidity Universes/01 Introduction.html similarity index 100% rename from 08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/01 Liquidity Universes/01 Introduction.html rename to 03 Writing Algorithms/12 Universes/03 Equity/01 Liquidity Universes/01 Introduction.html diff --git a/08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/01 Liquidity Universes/02 Create Universes.html b/03 Writing Algorithms/12 Universes/03 Equity/01 Liquidity Universes/02 Create Universes.html similarity index 100% rename from 08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/01 Liquidity Universes/02 Create Universes.html rename to 03 Writing Algorithms/12 Universes/03 Equity/01 Liquidity Universes/02 Create Universes.html diff --git a/08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/01 Liquidity Universes/10 Selection Frequency.html b/03 Writing Algorithms/12 Universes/03 Equity/01 Liquidity Universes/10 Selection Frequency.html similarity index 100% rename from 08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/01 Liquidity Universes/10 Selection Frequency.html rename to 03 Writing Algorithms/12 Universes/03 Equity/01 Liquidity Universes/10 Selection Frequency.html diff --git a/08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/01 Liquidity Universes/99 Examples.html b/03 Writing Algorithms/12 Universes/03 Equity/01 Liquidity Universes/99 Examples.html similarity index 100% rename from 08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/01 Liquidity Universes/99 Examples.html rename to 03 Writing Algorithms/12 Universes/03 Equity/01 Liquidity Universes/99 Examples.html diff --git a/08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/02 Fundamental Universes/01 Introduction.php b/03 Writing Algorithms/12 Universes/03 Equity/02 Fundamental Universes/01 Introduction.php similarity index 100% rename from 08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/02 Fundamental Universes/01 Introduction.php rename to 03 Writing Algorithms/12 Universes/03 Equity/02 Fundamental Universes/01 Introduction.php diff --git a/08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/02 Fundamental Universes/02 Create Universes.php b/03 Writing Algorithms/12 Universes/03 Equity/02 Fundamental Universes/02 Create Universes.php similarity index 99% rename from 08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/02 Fundamental Universes/02 Create Universes.php rename to 03 Writing Algorithms/12 Universes/03 Equity/02 Fundamental Universes/02 Create Universes.php index e7daffea87..8ee3f3cd43 100644 --- a/08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/02 Fundamental Universes/02 Create Universes.php +++ b/03 Writing Algorithms/12 Universes/03 Equity/02 Fundamental Universes/02 Create Universes.php @@ -31,7 +31,7 @@

-
// Take the top 50 by dollar volume using coarse
+        
// Take the top 50 by dollar volume using fundamental
 // Then the top 10 by PERatio using fine
 AddUniverse(
     fundamental => (from f in fundamental
diff --git a/08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/02 Fundamental Universes/03 Direct Access.php b/03 Writing Algorithms/12 Universes/03 Equity/02 Fundamental Universes/03 Direct Access.php
similarity index 100%
rename from 08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/02 Fundamental Universes/03 Direct Access.php
rename to 03 Writing Algorithms/12 Universes/03 Equity/02 Fundamental Universes/03 Direct Access.php
diff --git a/08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/02 Fundamental Universes/04 Historical Data.php b/03 Writing Algorithms/12 Universes/03 Equity/02 Fundamental Universes/04 Historical Data.php
similarity index 100%
rename from 08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/02 Fundamental Universes/04 Historical Data.php
rename to 03 Writing Algorithms/12 Universes/03 Equity/02 Fundamental Universes/04 Historical Data.php
diff --git a/08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/02 Fundamental Universes/10 Selection Frequency.html b/03 Writing Algorithms/12 Universes/03 Equity/02 Fundamental Universes/10 Selection Frequency.html
similarity index 100%
rename from 08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/02 Fundamental Universes/10 Selection Frequency.html
rename to 03 Writing Algorithms/12 Universes/03 Equity/02 Fundamental Universes/10 Selection Frequency.html
diff --git a/03 Writing Algorithms/12 Universes/03 Equity/02 Fundamental Universes/11 Live Trading Considerations.php b/03 Writing Algorithms/12 Universes/03 Equity/02 Fundamental Universes/11 Live Trading Considerations.php
new file mode 100644
index 0000000000..d645576662
--- /dev/null
+++ b/03 Writing Algorithms/12 Universes/03 Equity/02 Fundamental Universes/11 Live Trading Considerations.php	
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/02 Fundamental Universes/99 Examples.html b/03 Writing Algorithms/12 Universes/03 Equity/02 Fundamental Universes/99 Examples.html
similarity index 99%
rename from 08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/02 Fundamental Universes/99 Examples.html
rename to 03 Writing Algorithms/12 Universes/03 Equity/02 Fundamental Universes/99 Examples.html
index 7ac7328fb1..54cc9d0bbc 100644
--- a/08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/02 Fundamental Universes/99 Examples.html	
+++ b/03 Writing Algorithms/12 Universes/03 Equity/02 Fundamental Universes/99 Examples.html	
@@ -1,5 +1,5 @@
 
-
+
 

The following examples are typical filter functions you may want.

Example 1: Take 500 stocks that are worth more than $10 and have more than $10M daily trading volume

diff --git a/03 Writing Algorithms/12 Universes/03 Equity/03 Dollar Volume Selection.html b/03 Writing Algorithms/12 Universes/03 Equity/03 Dollar Volume Selection.html deleted file mode 100644 index 31d6407e6a..0000000000 --- a/03 Writing Algorithms/12 Universes/03 Equity/03 Dollar Volume Selection.html +++ /dev/null @@ -1,10 +0,0 @@ -

A dollar volume universe enables you pick the most liquid stocks in the market with just one line of code. To add a dollar volume universe, call the Universe.DollarVolume.Top helper method and pass the result to the AddUniverse method.

- -
-
// Add the 50 stocks with the highest dollar volume
-AddUniverse(Universe.DollarVolume.Top(50));
-
-
// Add the 50 stocks with the highest dollar volume
-self.AddUniverse(self.Universe.DollarVolume.Top(50))
-
-
diff --git a/08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/03 ETF Constituents Universes/01 Introduction.html b/03 Writing Algorithms/12 Universes/03 Equity/03 ETF Constituents Universes/01 Introduction.html similarity index 100% rename from 08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/03 ETF Constituents Universes/01 Introduction.html rename to 03 Writing Algorithms/12 Universes/03 Equity/03 ETF Constituents Universes/01 Introduction.html diff --git a/08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/03 ETF Constituents Universes/02 Create Universes.html b/03 Writing Algorithms/12 Universes/03 Equity/03 ETF Constituents Universes/02 Create Universes.html similarity index 100% rename from 08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/03 ETF Constituents Universes/02 Create Universes.html rename to 03 Writing Algorithms/12 Universes/03 Equity/03 ETF Constituents Universes/02 Create Universes.html diff --git a/08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/03 ETF Constituents Universes/10 Selection Frequency.html b/03 Writing Algorithms/12 Universes/03 Equity/03 ETF Constituents Universes/10 Selection Frequency.html similarity index 100% rename from 08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/03 ETF Constituents Universes/10 Selection Frequency.html rename to 03 Writing Algorithms/12 Universes/03 Equity/03 ETF Constituents Universes/10 Selection Frequency.html diff --git a/08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/03 ETF Constituents Universes/99 Examples.html b/03 Writing Algorithms/12 Universes/03 Equity/03 ETF Constituents Universes/99 Examples.html similarity index 100% rename from 08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/03 ETF Constituents Universes/99 Examples.html rename to 03 Writing Algorithms/12 Universes/03 Equity/03 ETF Constituents Universes/99 Examples.html diff --git a/03 Writing Algorithms/12 Universes/03 Equity/03 ETF Constituents Universes/metadata.json b/03 Writing Algorithms/12 Universes/03 Equity/03 ETF Constituents Universes/metadata.json new file mode 100644 index 0000000000..bd33b20fcd --- /dev/null +++ b/03 Writing Algorithms/12 Universes/03 Equity/03 ETF Constituents Universes/metadata.json @@ -0,0 +1,12 @@ +{ + "type": "metadata", + "values": { + "description": "You can select a universe based on the constituents of an ETF, and then you can further filter your universe down with fundamentals.", + "keywords": "ETF constituents", + "og:description": "You can select a universe based on the constituents of an ETF, and then you can further filter your universe down with fundamentals.", + "og:title": "Equity - Documentation QuantConnect.com", + "og:type": "website", + "og:site_name": "Equity - QuantConnect.com", + "og:image": "https://cdn.quantconnect.com/docs/i/writing-algorithms/universes/equity.png" + } +} diff --git a/03 Writing Algorithms/12 Universes/11 Chained Universes/00 Introduction.html b/03 Writing Algorithms/12 Universes/03 Equity/04 Chained Universes/00 Introduction.html similarity index 100% rename from 03 Writing Algorithms/12 Universes/11 Chained Universes/00 Introduction.html rename to 03 Writing Algorithms/12 Universes/03 Equity/04 Chained Universes/00 Introduction.html diff --git a/08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/04 Chained Universes/02 Filter Pattern.html b/03 Writing Algorithms/12 Universes/03 Equity/04 Chained Universes/02 Filter Pattern.html similarity index 100% rename from 08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/04 Chained Universes/02 Filter Pattern.html rename to 03 Writing Algorithms/12 Universes/03 Equity/04 Chained Universes/02 Filter Pattern.html diff --git a/08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/04 Chained Universes/04 Universe Data Weights.html b/03 Writing Algorithms/12 Universes/03 Equity/04 Chained Universes/04 Universe Data Weights.html similarity index 100% rename from 08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/04 Chained Universes/04 Universe Data Weights.html rename to 03 Writing Algorithms/12 Universes/03 Equity/04 Chained Universes/04 Universe Data Weights.html diff --git a/08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/04 Chained Universes/06 Chain Fundamental and Alternative Data.html b/03 Writing Algorithms/12 Universes/03 Equity/04 Chained Universes/06 Chain Fundamental and Alternative Data.html similarity index 100% rename from 08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/04 Chained Universes/06 Chain Fundamental and Alternative Data.html rename to 03 Writing Algorithms/12 Universes/03 Equity/04 Chained Universes/06 Chain Fundamental and Alternative Data.html diff --git a/08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/04 Chained Universes/07 Chain ETF and Fundamental.html b/03 Writing Algorithms/12 Universes/03 Equity/04 Chained Universes/07 Chain ETF and Fundamental.html similarity index 93% rename from 08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/04 Chained Universes/07 Chain ETF and Fundamental.html rename to 03 Writing Algorithms/12 Universes/03 Equity/04 Chained Universes/07 Chain ETF and Fundamental.html index a42219c066..1fdaecad6c 100644 --- a/08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/04 Chained Universes/07 Chain ETF and Fundamental.html +++ b/03 Writing Algorithms/12 Universes/03 Equity/04 Chained Universes/07 Chain ETF and Fundamental.html @@ -2,7 +2,7 @@

- The following example chains a fundamental universe and an ETF constituents universe. + The following example chains a fundamental universe and an ETF constituents universe. It first selects all the constituents of the QQQ ETF and then filters then down to select the 20 assets with the lowest PE ratio. The output of the fundamental universe selection method is the output of the chained universe.

diff --git a/08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/04 Chained Universes/08 Chain ETF and Alternative Data.html b/03 Writing Algorithms/12 Universes/03 Equity/04 Chained Universes/08 Chain ETF and Alternative Data.html similarity index 94% rename from 08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/04 Chained Universes/08 Chain ETF and Alternative Data.html rename to 03 Writing Algorithms/12 Universes/03 Equity/04 Chained Universes/08 Chain ETF and Alternative Data.html index cf82999dd5..4deeb5e580 100644 --- a/08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/04 Chained Universes/08 Chain ETF and Alternative Data.html +++ b/03 Writing Algorithms/12 Universes/03 Equity/04 Chained Universes/08 Chain ETF and Alternative Data.html @@ -1,5 +1,5 @@

-The following example chains an ETF universe and a QuiverQuantTwitterFollowersUniverse alternative universe. +The following example chains an ETF universe and a QuiverQuantTwitterFollowersUniverse alternative universe. It first selects all constituents of SPY and then filters them down with based on their Twitter followers number and weekly change. The output of the alternative universe selection method is the output of the chained universe.

diff --git a/08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/04 Chained Universes/10 Chain ETF and US Equity Options.html b/03 Writing Algorithms/12 Universes/03 Equity/04 Chained Universes/10 Chain ETF and US Equity Options.html similarity index 96% rename from 08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/04 Chained Universes/10 Chain ETF and US Equity Options.html rename to 03 Writing Algorithms/12 Universes/03 Equity/04 Chained Universes/10 Chain ETF and US Equity Options.html index 76bfe4898e..a80d2488b3 100644 --- a/08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/04 Chained Universes/10 Chain ETF and US Equity Options.html +++ b/03 Writing Algorithms/12 Universes/03 Equity/04 Chained Universes/10 Chain ETF and US Equity Options.html @@ -1,5 +1,5 @@

- The following example chains an ETF constituents universe and an Equity Options universe. + The following example chains an ETF constituents universe and an Equity Options universe. It first selects the 30 largest-weighted constituents of QQQ and then selects their call Option contracts that expire within 60 days. The output of both universes is the output of the chained universe.

diff --git a/03 Writing Algorithms/12 Universes/03 Equity/04 ETF Constituents Selection.html b/03 Writing Algorithms/12 Universes/03 Equity/04 ETF Constituents Selection.html deleted file mode 100644 index d531448a65..0000000000 --- a/03 Writing Algorithms/12 Universes/03 Equity/04 ETF Constituents Selection.html +++ /dev/null @@ -1,82 +0,0 @@ -

An ETF constituents universe lets you select a universe of securities in an ETF. The US ETF Constituents dataset includes 2,650 US ETFs you can use to create your universe. To add an ETF Constituents universe, call the Universe.ETF method.

- -
-
public class ETFConstituentsAlgorithm : QCAlgorithm
-{
-    public override void Initialize() 
-    {
-        AddUniverse(Universe.ETF("SPY", Market.USA, UniverseSettings));
-    }
-}
-
class ETFConstituentsAlgorithm(QCAlgorithm):
-    def Initialize(self) -> None:        
-        self.AddUniverse(self.Universe.ETF("SPY", Market.USA, self.UniverseSettings))
-
- -

The following table describes the ETF method arguments:

- - - - - - - - - - - - - - - - -
-

Argument: etfTicker

-

The ETF ticker. To view the supported ETFs in the US ETF Constituents dataset, see Supported ETFs.

-

Data Type: stringstr | Default Value: None

-
-

Argument: market

-

The market of the ETF. If you don't provide an argument, it uses the default Equity market of the brokerage model.

-

Data Type: stringstr | Default Value: None

-
-

Argument: universeSettings

-

The universe settings. If you don't provide an argument, it uses the algorithm UniverseSettings.

-

Data Type: UniverseSettings | Default Value: None

-
-

Argument: universeFilterFunc

-

A function to select some of the ETF constituents for the universe. If you don't provide an argument, it selects all of the constituents.

-

Data Type: Func<IEnumerable<ETFConstituentData>, IEnumerable<Symbol>>Callable[[List[ETFConstituentData]], List[Symbol]] | Default Value: nullNone

-
- -

To select a subset of the ETF constituents, provide a universeFilterFunc argument. The filter function receives ETFConstituentData objects, which represent one of the ETF constituents. ETFConstituentsData objects have the following attributes:

- -
- - -
-
public class ETFConstituentsAlgorithm : QCAlgorithm 
-{
-    public override void Initialize() 
-    {
-        var universe = Universe.ETF("SPY", Market.USA, UniverseSettings, ETFConstituentsFilter);
-        AddUniverse(universe);
-    }
-
-    private IEnumerable<Symbol> ETFConstituentsFilter(IEnumerable<ETFConstituentData> constituents)
-    {
-        // Get the 10 securities with the largest weight in the index
-        return constituents.OrderByDescending(c => c.Weight).Take(10).Select(c => c.Symbol);
-    }
-}
-
-
class ETFConstituentsAlgorithm(QCAlgorithm):
-    def Initialize(self) -> None:
-        universe = self.Universe.ETF("SPY", Market.USA, self.UniverseSettings, self.ETFConstituentsFilter)
-        self.AddUniverse(universe)
-
-    def ETFConstituentsFilter(self, constituents: List[ETFConstituentData]) -> List[Symbol]:
-        # Get the 10 securities with the largest weight in the index
-        selected = sorted([c for c in constituents if c.Weight],
-            key=lambda c: c.Weight, reverse=True)[:10]
-        return [c.Symbol for c in selected]
-
diff --git a/03 Writing Algorithms/12 Universes/03 Equity/01 Introduction.html b/03 Writing Algorithms/12 Universes/03 Equity/05 Legacy Fundamental Universes/01 Introduction.html similarity index 100% rename from 03 Writing Algorithms/12 Universes/03 Equity/01 Introduction.html rename to 03 Writing Algorithms/12 Universes/03 Equity/05 Legacy Fundamental Universes/01 Introduction.html diff --git a/03 Writing Algorithms/12 Universes/03 Equity/02 Coarse Universe Selection.php b/03 Writing Algorithms/12 Universes/03 Equity/05 Legacy Fundamental Universes/02 Coarse Universe Selection.php similarity index 100% rename from 03 Writing Algorithms/12 Universes/03 Equity/02 Coarse Universe Selection.php rename to 03 Writing Algorithms/12 Universes/03 Equity/05 Legacy Fundamental Universes/02 Coarse Universe Selection.php diff --git a/03 Writing Algorithms/12 Universes/03 Equity/05 Fundamentals Selection.php b/03 Writing Algorithms/12 Universes/03 Equity/05 Legacy Fundamental Universes/05 Fundamentals Selection.php similarity index 89% rename from 03 Writing Algorithms/12 Universes/03 Equity/05 Fundamentals Selection.php rename to 03 Writing Algorithms/12 Universes/03 Equity/05 Legacy Fundamental Universes/05 Fundamentals Selection.php index a77ceb73ab..aa51050353 100644 --- a/03 Writing Algorithms/12 Universes/03 Equity/05 Fundamentals Selection.php +++ b/03 Writing Algorithms/12 Universes/03 Equity/05 Legacy Fundamental Universes/05 Fundamentals Selection.php @@ -47,7 +47,7 @@
QuantConnect Coarse and Fine Universe Selection
-

To add a fundamental universe, in the Initialize method, pass two filter functions to the AddUniverse method. The first filter function can be a coarse universe filter, dollar volume filter, or an ETF constituents filter. The second filter function receives a list of FineFundamental objects and must return a list of Symbol objects. The list of FineFundamental objects contains a subset of the Symbol objects that the first filter function returned. The Symbol objects you return from the second function are the constituents of the fundamental universe and LEAN automatically creates subscriptions for them. Don't call AddEquity in the filter function.

+

To add a fundamental universe, in the Initialize method, pass two filter functions to the AddUniverse method. The first filter function can be a coarse universe filter, dollar volume filter, or an ETF constituents filter. The second filter function receives a list of FineFundamental objects and must return a list of Symbol objects. The list of FineFundamental objects contains a subset of the Symbol objects that the first filter function returned. The Symbol objects you return from the second function are the constituents of the fundamental universe and LEAN automatically creates subscriptions for them. Don't call AddEquity in the filter function.

Tip: diff --git a/03 Writing Algorithms/12 Universes/03 Equity/05 Legacy Fundamental Universes/07 Live Trading Considerations.php b/03 Writing Algorithms/12 Universes/03 Equity/05 Legacy Fundamental Universes/07 Live Trading Considerations.php new file mode 100644 index 0000000000..d645576662 --- /dev/null +++ b/03 Writing Algorithms/12 Universes/03 Equity/05 Legacy Fundamental Universes/07 Live Trading Considerations.php @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/03 Writing Algorithms/12 Universes/03 Equity/08 Examples.html b/03 Writing Algorithms/12 Universes/03 Equity/05 Legacy Fundamental Universes/08 Examples.html similarity index 100% rename from 03 Writing Algorithms/12 Universes/03 Equity/08 Examples.html rename to 03 Writing Algorithms/12 Universes/03 Equity/05 Legacy Fundamental Universes/08 Examples.html diff --git a/08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/06 Alternative Data Universes/01 Introduction.html b/03 Writing Algorithms/12 Universes/03 Equity/06 Alternative Data Universes/01 Introduction.html similarity index 100% rename from 08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/06 Alternative Data Universes/01 Introduction.html rename to 03 Writing Algorithms/12 Universes/03 Equity/06 Alternative Data Universes/01 Introduction.html diff --git a/08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/06 Alternative Data Universes/02 Supported Datasets.html b/03 Writing Algorithms/12 Universes/03 Equity/06 Alternative Data Universes/02 Supported Datasets.html similarity index 100% rename from 08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/06 Alternative Data Universes/02 Supported Datasets.html rename to 03 Writing Algorithms/12 Universes/03 Equity/06 Alternative Data Universes/02 Supported Datasets.html diff --git a/03 Writing Algorithms/12 Universes/03 Equity/06 Selection Frequency.html b/03 Writing Algorithms/12 Universes/03 Equity/06 Selection Frequency.html deleted file mode 100644 index fbb9bc72ad..0000000000 --- a/03 Writing Algorithms/12 Universes/03 Equity/06 Selection Frequency.html +++ /dev/null @@ -1 +0,0 @@ -

Equity universes run on a daily basis.

diff --git a/03 Writing Algorithms/12 Universes/03 Equity/07 Live Trading Considerations.php b/03 Writing Algorithms/12 Universes/03 Equity/07 Live Trading Considerations.php deleted file mode 100644 index 72a971d5d3..0000000000 --- a/03 Writing Algorithms/12 Universes/03 Equity/07 Live Trading Considerations.php +++ /dev/null @@ -1 +0,0 @@ - diff --git a/03 Writing Algorithms/12 Universes/03 Equity/metadata.json b/03 Writing Algorithms/12 Universes/03 Equity/metadata.json deleted file mode 100644 index 3e962bd65c..0000000000 --- a/03 Writing Algorithms/12 Universes/03 Equity/metadata.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "type": "metadata", - "values": { - "description": "You can select a universe based on coarse data or the constituents of an ETF, and then you can further filter your universe down with fundamentals.", - "keywords": "Coarse Fundamental, fine fundamental, etf constituents, fundamental data", - "og:description": "You can select a universe based on coarse data or the constituents of an ETF, and then you can further filter your universe down with fundamentals.", - "og:title": "Equity - Documentation QuantConnect.com", - "og:type": "website", - "og:site_name": "Equity - QuantConnect.com", - "og:image": "https://cdn.quantconnect.com/docs/i/writing-algorithms/universes/equity.png" - } -} diff --git a/08 Drafts/03 Writing Algorithms/12 Universes/05 Crypto/03 Alternative Data Universes.html b/03 Writing Algorithms/12 Universes/05 Crypto/03 Alternative Data Universes.html similarity index 100% rename from 08 Drafts/03 Writing Algorithms/12 Universes/05 Crypto/03 Alternative Data Universes.html rename to 03 Writing Algorithms/12 Universes/05 Crypto/03 Alternative Data Universes.html diff --git a/03 Writing Algorithms/12 Universes/11 Chained Universes/02 Filter Pattern.html b/03 Writing Algorithms/12 Universes/11 Chained Universes/02 Filter Pattern.html deleted file mode 100644 index d1d01ce744..0000000000 --- a/03 Writing Algorithms/12 Universes/11 Chained Universes/02 Filter Pattern.html +++ /dev/null @@ -1,5 +0,0 @@ -

- Universes filter a large set of Symbol objects by a coarse filter to quickly reduce the data processing requirement. This is often a first step before applying a second filter or requesting alternative data. For example, a strategy might only be interested in easily tradable liquid assets so quickly eliminates all stocks with less than $1M USD / day in trading volume. -

-A chain of universe blocks that get smaller as they are filtered over time -

The order of your filters can improve the speed of your research. By applying filters that narrow the universe the most, or are the lightest weight first, you can significantly reduce the amount of data your algorithm processes. Unless necessary, you can also not return any selections from earlier filters to further improve research speed, keeping only the universe data for later filters.

\ No newline at end of file diff --git a/03 Writing Algorithms/12 Universes/11 Chained Universes/04 Universe Data Weights.html b/03 Writing Algorithms/12 Universes/11 Chained Universes/04 Universe Data Weights.html deleted file mode 100644 index 8171a5c8aa..0000000000 --- a/03 Writing Algorithms/12 Universes/11 Chained Universes/04 Universe Data Weights.html +++ /dev/null @@ -1,21 +0,0 @@ -

- To speed up your algorithm, request the lightest weight data first before chaining heavier filters or adding alternative data. The following table shows the size each dataset:

-

- - - - - - - - - - - - - - - - - -
Name Data Size / Weight
US Equities (Coarse)Light (1 GB)
US Equities (Fine/Fundamental)Heavy (5 TB)
US Equity Options Huge (200 TB)
US Index Options Medium (500 GB)
US Futures Medium (500 GB)
US Futures OptionsMedium (500 GB)
CryptoLight (1 GB)
Alternative / GeneralLight (100 MB - 2 GB)
Alternative / Tiingo News Medium (200 GB)
diff --git a/03 Writing Algorithms/12 Universes/11 Chained Universes/05 Universe Schedules.html b/03 Writing Algorithms/12 Universes/11 Chained Universes/05 Universe Schedules.html deleted file mode 100644 index 647352d951..0000000000 --- a/03 Writing Algorithms/12 Universes/11 Chained Universes/05 Universe Schedules.html +++ /dev/null @@ -1 +0,0 @@ -

Universes typically run overnight and are available before market open. Universes are not currently "ordered", so universe chaining works best with slower universes. For example, use a slow-changing ETF Constituents Universe to set the Symbol list for alternative data.

\ No newline at end of file diff --git a/03 Writing Algorithms/12 Universes/11 Chained Universes/06 Chaining Coarse and Alternative Data.html b/03 Writing Algorithms/12 Universes/11 Chained Universes/06 Chaining Coarse and Alternative Data.html deleted file mode 100644 index f70decf701..0000000000 --- a/03 Writing Algorithms/12 Universes/11 Chained Universes/06 Chaining Coarse and Alternative Data.html +++ /dev/null @@ -1,99 +0,0 @@ -

-The following example chains the QuiverQuantTwitterFollowersUniverse alternative universe to the coarse universe. It first selects the 100 most liquid US Equities and then filters them down based on their Twitter followers number and weekly change. The output of the alternative universe selection method is the output of the chained universe. -

-
-
using System.Collections.Generic;
-using System.Linq;
-using QuantConnect.Data;
-using QuantConnect.Data.UniverseSelection;
-using QuantConnect.DataSource;
-using QuantConnect.Securities;
-
-namespace QuantConnect.Algorithm.CSharp
-{
-    public class ChainedUniverseAlgorithm : QCAlgorithm
-    {
-        private List<Symbol> _coarse = new();
-        private Universe _universeCoarse;
-        private Universe _universeTwitter;
-
-        public override void Initialize()
-        {
-            SetStartDate(2023, 1, 2);
-            SetCash(100000);
-
-            _universeCoarse = AddUniverse(CoarseFilterFunction);
-            _universeTwitter = AddUniverse<QuiverQuantTwitterFollowersUniverse>(
-                "QuiverQuantTwitterFollowersUniverse", Resolution.Daily, FollowerSelection);
-        }
-
-        private IEnumerable<Symbol> CoarseFilterFunction(IEnumerable<CoarseFundamental> coarse)
-        {
-            _coarse = (from c in coarse
-                       orderby c.DollarVolume descending
-                       select c.Symbol).Take(100).ToList();
-            return Universe.Unchanged;
-        }
-
-        private IEnumerable<Symbol> FollowerSelection(IEnumerable<QuiverQuantTwitterFollowersUniverse> altCoarse)
-        {
-            var followers = from d in altCoarse
-                         where d.Followers > 200000m && d.WeekPercentChange > 0m
-                         select d.Symbol;
-            return _coarse.Intersect(followers);
-        }
-
-        public override void OnSecuritiesChanged(SecurityChanges changes)
-        {
-            foreach (var added in changes.AddedSecurities)
-            {
-                AddData<QuiverQuantTwitterFollowers>(added.Symbol);
-            }
-        }
-
-        public override void OnData(Slice data)
-        {
-            foreach (var kvp in data.Get<QuiverQuantTwitterFollowers>())
-            {
-                var datasetSymbol = kvp.Key;
-                var dataPoint = kvp.Value;
-                Debug($"{datasetSymbol} followers at {data.Time}: {dataPoint.Followers}");
-            }
-        }
-    }
-}
-
from AlgorithmImports import * 
-
-class ChainedUniverseAlgorithm(QCAlgorithm):
-
-    coarse = []
-    universe_coarse = None
-    universe_twitter = None
-
-    def Initialize(self):
-        self.SetCash(100000)
-        self.SetStartDate(2023, 1, 2)
-        self.universe_coarse = self.AddUniverse(self.CoarseFilterFunction)
-        self.universe_twitter = self.AddUniverse(QuiverQuantTwitterFollowersUniverse, "QuiverQuantTwitterFollowersUniverse", Resolution.Daily, self.FollowerSelection)
-
-    def CoarseFilterFunction(self, coarse: List[CoarseFundamental]) -> List[Symbol]:
-        sorted_by_dollar_volume = sorted(coarse, key=lambda x: x.DollarVolume, reverse=True) 
-        self.coarse = [c.Symbol for c in sorted_by_dollar_volume[:100]]
-        return Universe.Unchanged
-
-    def FollowerSelection(self, alt_coarse: List[QuiverQuantTwitterFollowersUniverse]) -> List[Symbol]:
-        self.followers = [d.Symbol for d in alt_coarse if d.Followers > 200000 and d.WeekPercentChange > 0]
-        return list(set(self.coarse) & set(self.followers))
-
-    def OnSecuritiesChanged(self, changes):
-        for added in changes.AddedSecurities:
-            self.AddData(QuiverQuantTwitterFollowers, added.Symbol)
-
-    def OnData(self, data):
-        # Prices in the slice from the universe selection
-        # Alternative data in slice from OnSecuritiesChanged Addition
-        # for ticker,bar in data.Bars.items():
-        #     pass
-        for dataset_symbol, data_point in data.Get(QuiverQuantTwitterFollowers).items():
-            self.Debug(f"{dataset_symbol} followers at {data.Time}: {data_point.Followers}")
-
diff --git a/03 Writing Algorithms/12 Universes/11 Chained Universes/08 Chaining ETF Universe and Alt Data.html b/03 Writing Algorithms/12 Universes/11 Chained Universes/08 Chaining ETF Universe and Alt Data.html deleted file mode 100644 index dd50b89d13..0000000000 --- a/03 Writing Algorithms/12 Universes/11 Chained Universes/08 Chaining ETF Universe and Alt Data.html +++ /dev/null @@ -1,104 +0,0 @@ -

-The following example chains a QuiverQuantTwitterFollowersUniverse alternative universe to the SPY ETF universe. It first selects all constituents of SPY and then filters them down with based on their Twitter followers number and weekly change. The output of the alternative universe selection method is the output of the chained universe. -

-
-
using System.Collections.Generic;
-using System.Linq;
-using QuantConnect.Data;
-using QuantConnect.Data.UniverseSelection;
-using QuantConnect.DataSource;
-using QuantConnect.Securities;
-
-namespace QuantConnect.Algorithm.CSharp
-{
-    public class ChainedUniverseAlgorithm : QCAlgorithm
-    {
-        private List<Symbol> _etf = new();
-        private Universe _universeEtf;
-        private Universe _universeTwitter;
-
-        public override void Initialize()
-        {
-            SetStartDate(2023, 1, 2);
-            SetCash(100000);
-
-            _universeEtf = AddUniverse(Universe.ETF("SPY", Market.USA, UniverseSettings, ETFConstituentsFilter));
-            // or var symbol = QuantConnect.Symbol.Create("SPY", SecurityType.Equity, Market.USA);
-            // _universeEtf = AddUniverseSelection(new ETFConstituentsUniverseSelectionModel(
-            //    symbol, UniverseSettings, ETFConstituentsFilter));
-            _universeTwitter = AddUniverse<QuiverQuantTwitterFollowersUniverse>(
-                "QuiverQuantTwitterFollowersUniverse", Resolution.Daily, FollowerSelection);
-        }
-
-        private IEnumerable<Symbol> ETFConstituentsFilter(IEnumerable<ETFConstituentData> constituents)
-        {
-            _etf = constituents.Select(c => c.Symbol).ToList();
-            return Universe.Unchanged;
-        }
-
-        private IEnumerable<Symbol> FollowerSelection(IEnumerable<QuiverQuantTwitterFollowersUniverse> altCoarse)
-        {
-            var followers = from d in altCoarse
-                            where d.Followers > 200000m && d.WeekPercentChange > 0m
-                            select d.Symbol;
-            return _etf.Intersect(followers);
-        }
-
-        public override void OnSecuritiesChanged(SecurityChanges changes)
-        {
-            foreach (var added in changes.AddedSecurities)
-            {
-                AddData<QuiverQuantTwitterFollowers>(added.Symbol);
-            }
-        }
-
-        public override void OnData(Slice data)
-        {
-            foreach (var kvp in data.Get<QuiverQuantTwitterFollowers>())
-            {
-                var datasetSymbol = kvp.Key;
-                var dataPoint = kvp.Value;
-                Debug($"{datasetSymbol} followers at {data.Time}: {dataPoint.Followers}");
-            }
-        }
-    }
-}
-
from AlgorithmImports import * 
-
-class ChainedUniverseAlgorithm(QCAlgorithm):
-
-    etf = []
-    universe_etf = None
-    universe_twitter = None
-
-    def Initialize(self):
-        self.SetCash(100000)
-        self.SetStartDate(2023, 1, 2)
-        
-        self.universe_etf = self.AddUniverse(self.Universe.ETF("SPY", Market.USA, self.UniverseSettings, self.ETFConstituentsFilter))
-        # or symbol = Symbol.Create("SPY", SecurityType.Equity, Market.USA)
-        # self.universe_etf = self.AddUniverseSelection(ETFConstituentsUniverseSelectionModel(
-        #   symbol, self.UniverseSettings, self.ETFConstituentsFilter))
-        self.universe_twitter = self.AddUniverse(QuiverQuantTwitterFollowersUniverse, 
-            "QuiverQuantTwitterFollowersUniverse", Resolution.Daily, self.FollowerSelection)
-
-    def ETFConstituentsFilter(self, constituents: List[ETFConstituentData]) -> List[Symbol]:
-        self.etf = [c.Symbol for c in constituents]
-        return Universe.Unchanged
-
-    def FollowerSelection(self, alt_coarse: List[QuiverQuantTwitterFollowersUniverse]) -> List[Symbol]:
-        self.followers = [d.Symbol for d in alt_coarse if d.Followers > 200000 and d.WeekPercentChange > 0]
-        return list(set(self.etf) & set(self.followers))
-
-    def OnSecuritiesChanged(self, changes):
-        for added in changes.AddedSecurities:
-            self.AddData(QuiverQuantTwitterFollowers, added.Symbol)
-
-    def OnData(self, data):
-        # Prices in the slice from the universe selection
-        # Alternative data in slice from OnSecuritiesChanged Addition
-        # for ticker,bar in data.Bars.items():
-        #     pass
-        for dataset_symbol, data_point in data.Get(QuiverQuantTwitterFollowers).items():
-            self.Debug(f"{dataset_symbol} followers at {data.Time}: {data_point.Followers}")
-
\ No newline at end of file diff --git a/03 Writing Algorithms/12 Universes/11 Chained Universes/10 Chaining to US Equity Options.html b/03 Writing Algorithms/12 Universes/11 Chained Universes/10 Chaining to US Equity Options.html deleted file mode 100644 index d18b345ac9..0000000000 --- a/03 Writing Algorithms/12 Universes/11 Chained Universes/10 Chaining to US Equity Options.html +++ /dev/null @@ -1,108 +0,0 @@ -

The following example chains an OptionFilterUniverse to the QQQ ETF universe. It first selects the 30 largest-weighted constituents of QQQ and then selects their call Option contracts that expire within 60 days.

-
-
using System.Collections.Generic;
-using System.Linq;
-using QuantConnect.Data;
-using QuantConnect.Data.UniverseSelection;
-
-namespace QuantConnect.Algorithm.CSharp
-{
-    public class ChainedUniverseAlgorithm : QCAlgorithm
-    {
-        private Universe _universeEtf;
-        private List<Symbol> _optionContracts = new();
-
-        public override void Initialize()
-        {
-            SetStartDate(2023, 2, 2);
-            SetCash(100000);
-
-            UniverseSettings.DataNormalizationMode = DataNormalizationMode.Raw;
-            _universeEtf = AddUniverse(Universe.ETF("QQQ", Market.USA, UniverseSettings, ETFConstituentsFilter));
-        }
-
-        private IEnumerable<Symbol> ETFConstituentsFilter(IEnumerable<ETFConstituentData> constituents)
-        {
-            return (from c in constituents
-                    orderby c.Weight descending
-                    select c.Symbol).Take(10);
-        }
-
-        public override void OnSecuritiesChanged(SecurityChanges changes)
-        {
-            foreach (var added in changes.AddedSecurities)
-            {
-                if (added.Type != SecurityType.Equity) continue;
-
-                var contracts = OptionChainProvider.GetOptionContractList(added.Symbol, Time);
-                var filteredContracts = (from contract in contracts
-                                        where contract.ID.OptionRight == OptionRight.Call
-                                        && contract.ID.StrikePrice >= 100
-                                        && contract.ID.Date <= Time.AddDays(10)
-                                        && contract.ID.OptionStyle == OptionStyle.American
-                                        select AddOptionContract(contract).Symbol);
-                _optionContracts = _optionContracts.Union(filteredContracts).ToList();
-            }
-            
-            foreach (var removed in changes.RemovedSecurities)
-            {
-                if (_optionContracts.Contains(removed.Symbol))
-                {
-                    _optionContracts.Remove(removed.Symbol);
-                }
-            }
-        }
-
-        public override void OnData(Slice data)
-        {
-            foreach (var chain in data.OptionChains)
-            {
-                var symbol = chain.Key;
-                foreach (var contract in chain.Value)
-                {
-                    Debug($"Found {contract.Symbol} option contract for {symbol}");
-                }
-            }
-        }
-    }
-}
-
from AlgorithmImports import *
-
-class ChainedUniverseAlgorithm(QCAlgorithm):
-
-    universe_etf = None
-    option_contracts = []
-
-    def Initialize(self):
-        self.SetCash(100000)
-        self.SetStartDate(2023, 2, 2)
-        
-        self.UniverseSettings.DataNormalizationMode = DataNormalizationMode.Raw
-        self.universe_etf = self.AddUniverse(self.Universe.ETF("QQQ", Market.USA, self.UniverseSettings, self.ETFConstituentsFilter))
-
-    def ETFConstituentsFilter(self, constituents: List[ETFConstituentData]) -> List[Symbol]:
-        sorted_by_weight = sorted(constituents, key=lambda x: x.Weight, reverse=True) 
-        return [c.Symbol for c in sorted_by_weight[:10]]
-
-    def OnSecuritiesChanged(self, changes: SecurityChanges) -> None:
-        for added in changes.AddedSecurities:
-            if added.Type != SecurityType.Equity: continue
-
-            contracts = self.OptionChainProvider.GetOptionContractList(added.Symbol, self.Time)
-            filtered_contracts = [self.AddOptionContract(contract).Symbol for contract in contracts \
-                                    if contract.ID.OptionRight == OptionRight.Call \
-                                    and contract.ID.StrikePrice >= 100 \
-                                    and contract.ID.Date <= self.Time + timedelta(10) \
-                                    and contract.ID.OptionStyle == OptionStyle.American]
-            self.option_contracts = self.option_contracts + filtered_contracts
-
-        for removed in changes.RemovedSecurities:
-            if removed.Symbol in self.option_contracts:
-                self.option_contracts.remove(removed.Symbol)
-
-    def OnData(self, data: Slice) -> None:
-        for chain in data.OptionChains:
-            symbol = chain.Key
-            for contract in chain.Value:
-                self.Debug(f"Found {contract.Symbol} option contract for {symbol}")
-
\ No newline at end of file diff --git a/03 Writing Algorithms/12 Universes/11 Chained Universes/12 Chaining ETF and Fundamental Universe.html b/03 Writing Algorithms/12 Universes/11 Chained Universes/12 Chaining ETF and Fundamental Universe.html deleted file mode 100644 index 8bfcdfe654..0000000000 --- a/03 Writing Algorithms/12 Universes/11 Chained Universes/12 Chaining ETF and Fundamental Universe.html +++ /dev/null @@ -1,76 +0,0 @@ - - - -

- The following example chains an ETF constituents universe with a fundamental universe to select ETF constituents with a low PE ratio. -

-
-
using System.Collections.Generic;
-using System.Linq;
-using QuantConnect.Data;
-using QuantConnect.Data.Fundamental;
-using QuantConnect.Data.UniverseSelection;
-using QuantConnect.Securities;
-
-namespace QuantConnect.Algorithm.CSharp
-{
-    public class ChainedUniverseAlgorithm : QCAlgorithm
-    {
-        private Universe _universeEtf;
-        private Universe _universeFine;
-
-        public override void Initialize()
-        {
-            SetStartDate(2023, 1, 2);
-            SetCash(100000);
-
-            _universeEtf = Universe.ETF("QQQ", Market.USA, UniverseSettings, ETFConstituentsFilter);
-            _universeFine = AddUniverse(_universeEtf, FineSelection);
-        }
-
-        private IEnumerable<Symbol> ETFConstituentsFilter(IEnumerable<ETFConstituentData> constituents)
-        {
-            return constituents.Select(c => c.Symbol);
-        }
-
-        private IEnumerable<Symbol> FineSelection(IEnumerable<FineFundamental> fine)
-        {
-            return (from f in fine
-                    orderby f.ValuationRatios.PERatio
-                    select f.Symbol).Take(20);
-        }
-
-        public override void OnData(Slice data)
-        {
-            foreach (var symbol in data.Keys)
-            {
-                Debug($"{symbol} PE Ratio: {Securities[symbol].Fundamentals.ValuationRatios.PERatio}");
-            }
-        }
-    }
-}
-
from AlgorithmImports import * 
-
-class ChainedUniverseAlgorithm(QCAlgorithm):
-
-    universe_etf = None
-    universe_fine = None
-
-    def Initialize(self):
-        self.SetCash(100000)
-        self.SetStartDate(2023, 2, 2)
-        
-        self.universe_etf = self.Universe.ETF("QQQ", Market.USA, self.UniverseSettings, self.ETFConstituentsFilter)
-        self.universe_fine = self.AddUniverse(self.universe_etf, self.FineSelection)
-
-    def ETFConstituentsFilter(self, constituents: List[ETFConstituentData]) -> List[Symbol]:
-        return [c.Symbol for c in constituents]
-
-    def FineSelection(self, fine: List[FineFundamental]) -> List[Symbol]:
-        sorted_by_pe_ratio = sorted(fine, key=lambda f: f.ValuationRatios.PERatio)
-        return [f.Symbol for f in sorted_by_pe_ratio[:20]]
-
-    def OnData(self, data):
-        for symbol in data.Keys:
-            self.Debug(f"{symbol} PE Ratio: {self.Securities[symbol].Fundamentals.ValuationRatios.PERatio}")
-
diff --git a/03 Writing Algorithms/12 Universes/12 Alternative Data Universes/01 Introduction.html b/03 Writing Algorithms/12 Universes/12 Alternative Data Universes/01 Introduction.html deleted file mode 100644 index a25845514d..0000000000 --- a/03 Writing Algorithms/12 Universes/12 Alternative Data Universes/01 Introduction.html +++ /dev/null @@ -1 +0,0 @@ -

An alternative data universe lets you select a basket of assets based on an alternative dataset that's linked to securities. If you use an alternative data universe, you limit your universe to only the securities in the dataset, which avoids unnecessary subscriptions.

\ No newline at end of file diff --git a/03 Writing Algorithms/12 Universes/12 Alternative Data Universes/02 Supported Datasets.php b/03 Writing Algorithms/12 Universes/12 Alternative Data Universes/02 Supported Datasets.php deleted file mode 100644 index 5d774e89c5..0000000000 --- a/03 Writing Algorithms/12 Universes/12 Alternative Data Universes/02 Supported Datasets.php +++ /dev/null @@ -1,3 +0,0 @@ - \ No newline at end of file diff --git a/03 Writing Algorithms/12 Universes/12 Alternative Data Universes/metadata.json b/03 Writing Algorithms/12 Universes/12 Alternative Data Universes/metadata.json deleted file mode 100644 index 4128927f28..0000000000 --- a/03 Writing Algorithms/12 Universes/12 Alternative Data Universes/metadata.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "type": "metadata", - "values": { - "description": "An alternative data universe lets you select a basket of assets based on an alternative dataset that's linked to securities.", - "keywords": "universe selection, alternative data, alt data", - "og:description": "An alternative data universe lets you select a basket of assets based on an alternative dataset that's linked to securities.", - "og:title": "Alternative Data Universes - Documentation QuantConnect.com", - "og:type": "website", - "og:site_name": "Alternative Data Universes - QuantConnect.com", - "og:image": "https://cdn.quantconnect.com/docs/i/writing-algorithms/universes/alternative-data-universes.png" - } -} diff --git a/03 Writing Algorithms/16 Importing Data/03 Bulk Downloads/05 Transport Binary Data.html b/03 Writing Algorithms/16 Importing Data/03 Bulk Downloads/05 Transport Binary Data.html index 35f8f7c405..34074d0a94 100644 --- a/03 Writing Algorithms/16 Importing Data/03 Bulk Downloads/05 Transport Binary Data.html +++ b/03 Writing Algorithms/16 Importing Data/03 Bulk Downloads/05 Transport Binary Data.html @@ -13,7 +13,7 @@ base64_str = base64.b64encode(pickle_bytes).decode('ascii')
-
  • Save the string representation of your object to one of the supported external sources.
  • +
  • Save the string representation of your object to one of the supported sources.
  • Download the remote file into your project.
  • diff --git a/03 Writing Algorithms/28 Indicators/08 Indicator Universes/02 Define SymbolData Objects.html b/03 Writing Algorithms/28 Indicators/08 Indicator Universes/02 Define SymbolData Objects.html index d772209454..eacfa2aea0 100644 --- a/03 Writing Algorithms/28 Indicators/08 Indicator Universes/02 Define SymbolData Objects.html +++ b/03 Writing Algorithms/28 Indicators/08 Indicator Universes/02 Define SymbolData Objects.html @@ -41,4 +41,4 @@ }
    -

    You need to use a SymbolData class instead of assigning the indicators to the CoarseFundamental object because you can't create custom propertiesattributes on CoarseFundamental objects like you can with Security objects.

    +

    You need to use a SymbolData class instead of assigning the indicators to the Fundamental object because you can't create custom propertiesattributes on Fundamental objects like you can with Security objects.

    diff --git a/03 Writing Algorithms/28 Indicators/08 Indicator Universes/03 Define the Universe.html b/03 Writing Algorithms/28 Indicators/08 Indicator Universes/03 Define the Universe.html index 1930f2c49a..acdeb95c89 100644 --- a/03 Writing Algorithms/28 Indicators/08 Indicator Universes/03 Define the Universe.html +++ b/03 Writing Algorithms/28 Indicators/08 Indicator Universes/03 Define the Universe.html @@ -15,25 +15,25 @@ self.UniverseSettings.Resolution = Resolution.Daily self.UniverseSettings.Leverage = 2 - self.coarse_count = 10 + self.count = 10 self.averages = { } # this add universe method accepts two parameters: - # - coarse selection function: accepts an IEnumerable<CoarseFundamental> and returns an IEnumerable<Symbol> - self.AddUniverse(self.CoarseSelectionFunction) + # - fundamental selection function: accepts an IEnumerable<Fundamental> and returns an IEnumerable<Symbol> + self.AddUniverse(self.FundamentalSelectionFunction) # sort the data by daily dollar volume and take the top 'NumberOfSymbols' - def CoarseSelectionFunction(self, coarse: List[CoarseFundamental]) -> List[Symbol]: + def FundamentalSelectionFunction(self, fundamental: List[Fundamental]) -> List[Symbol]: # We are going to use a dictionary to refer the object that will keep the moving averages - for cf in coarse: - if cf.Symbol not in self.averages: - self.averages[cf.Symbol] = SymbolData(cf.Symbol) + for f in fundamental: + if f.Symbol not in self.averages: + self.averages[f.Symbol] = SymbolData(f.Symbol) # Updates the SymbolData object with current EOD price - avg = self.averages[cf.Symbol] - avg.update(cf.EndTime, cf.AdjustedPrice) + avg = self.averages[f.Symbol] + avg.update(f.EndTime, f.AdjustedPrice) # Filter the values of the dict: we only want up-trending securities values = list(filter(lambda x: x.is_uptrend, self.averages.values())) @@ -41,11 +41,11 @@ # Sorts the values of the dict: we want those with greater difference between the moving averages values.sort(key=lambda x: x.scale, reverse=True) - for x in values[:self.coarse_count]: + for x in values[:self.count]: self.Log('symbol: ' + str(x.symbol.Value) + ' scale: ' + str(x.scale)) # we need to return only the symbol objects - return [ x.symbol for x in values[:self.coarse_count] ] + return [ x.symbol for x in values[:self.count] ]
    namespace QuantConnect.Algorithm.CSharp
     {
         public class EmaCrossUniverseSelectionAlgorithm : QCAlgorithm
    @@ -56,7 +56,7 @@
             // use Buffer+Count to leave a little in cash
             private const decimal TargetPercent = 0.1m;
             private SecurityChanges _changes = SecurityChanges.None;
    -        // holds our coarse fundamental indicators by symbol
    +        // holds our fundamental indicators by symbol
             private readonly ConcurrentDictionary<Symbol, SelectionData> _averages = new ConcurrentDictionary<Symbol, SelectionData>();
         
             public override void Initialize()
    @@ -68,19 +68,19 @@
                 SetEndDate(2015, 01, 01);
                 SetCash(100*1000);
     
    -            AddUniverse(coarse =>
    +            AddUniverse(fundamental =>
                 {
    -                return (from cf in coarse
    +                return (from f in fundamental
                             // grab th SelectionData instance for this symbol
    -                        let avg = _averages.GetOrAdd(cf.Symbol, sym => new SelectionData())
    +                        let avg = _averages.GetOrAdd(f.Symbol, sym => new SelectionData())
                             // Update returns true when the indicators are ready, so don't accept until they are
    -                        where avg.Update(cf.EndTime, cf.AdjustedPrice)
    +                        where avg.Update(f.EndTime, f.AdjustedPrice)
                             // only pick symbols who have their 50 day ema over their 100 day ema
                             where avg.Fast > avg.Slow*(1 + Tolerance)
                             // prefer symbols with a larger delta by percentage between the two averages
                             orderby avg.ScaledDelta descending
                             // we only need to return the symbol and return 'Count' symbols
    -                        select cf.Symbol).Take(Count);
    +                        select f.Symbol).Take(Count);
                 });
             }
         }
    diff --git a/03 Writing Algorithms/34 Algorithm Framework/02 Universe Selection/01 Key Concepts/04 Multi-Universe Algorithms.html b/03 Writing Algorithms/34 Algorithm Framework/02 Universe Selection/01 Key Concepts/04 Multi-Universe Algorithms.html
    index 0fd318ac6c..54a81e92b5 100644
    --- a/03 Writing Algorithms/34 Algorithm Framework/02 Universe Selection/01 Key Concepts/04 Multi-Universe Algorithms.html	
    +++ b/03 Writing Algorithms/34 Algorithm Framework/02 Universe Selection/01 Key Concepts/04 Multi-Universe Algorithms.html	
    @@ -1,11 +1,14 @@
     

    You can add multiple Universe Selection models to a single algorithm.

    -
    AddUniverseSelection(new EmaCrossUniverseSelectionModel());
    -AddUniverseSelection(new FineFundamentalUniverseSelectionModel(SelectCoarse, SelectFine));
    -
    self.AddUniverseSelection(EmaCrossUniverseSelectionModel())
    -self.AddUniverseSelection(FineFundamentalUniverseSelectionModel(self.SelectCoarse, self.SelectFine))
    -
    +
    var symbols = new [] {QuantConnect.Symbol.Create("SPY", SecurityType.Equity, Market.USA)};
    +AddUniverseSelection(new ManualUniverseSelectionModel(symbols));
    +
    +AddUniverseSelection(new EmaCrossUniverseSelectionModel());
    +
    symbols = [Symbol.Create("SPY", SecurityType.Equity, Market.USA)]
    +self.AddUniverseSelection(ManualUniverseSelectionModel(symbols))
    +		
    +self.AddUniverseSelection(EmaCrossUniverseSelectionModel())

    If you add multiple Universe Selection models, the algorithm subscribes to the constituents of all the models.

    diff --git a/03 Writing Algorithms/34 Algorithm Framework/02 Universe Selection/04 Fundamental Universes/01 Introduction.html b/03 Writing Algorithms/34 Algorithm Framework/02 Universe Selection/04 Fundamental Universes/01 Introduction.html index 5712602464..8eeffab311 100644 --- a/03 Writing Algorithms/34 Algorithm Framework/02 Universe Selection/04 Fundamental Universes/01 Introduction.html +++ b/03 Writing Algorithms/34 Algorithm Framework/02 Universe Selection/04 Fundamental Universes/01 Introduction.html @@ -1,6 +1,5 @@ -

    A FundamentalUniverseSelectionModel selects a universe of US Equities based on CoarseFundamental and, sometimes, FineFundamental data. If the model uses CoarseFundamental data, it relies on the US Equity Coarse Universe dataset. If the Universe Selection model uses FineFundamental data, it relies on the US Fundamental dataset.

    +

    A FundamentalUniverseSelectionModel selects a universe of US Equities based on Fundamental data. Depending on the Fundamental properties you use, these universes rely on the US Equity Coarse Universe dataset, the US Fundamental dataset, or both.

    These types of universes operate on daily schedule. In backtests, they select assets at midnight. In live trading, the selection timing depends on the data feed you use.

    -

    If you use a fundamental Universe Selection model, the only way to unsubscribe from a security is to return a list from the selection functions that doesn't include the security Symbol. The RemoveSecurity method doesn't work with these types of Universe Selection models.

    - +

    If you use a fundamental Universe Selection model, the only way to unsubscribe from a security is to return a list from the selection function that doesn't include the security Symbol. The RemoveSecurity method doesn't work with these types of Universe Selection models.

    diff --git a/08 Drafts/03 Writing Algorithms/34 Algorithm Framework/02 Universe Selection/04 Fundamental Universes/02 Fundamental Selection.html b/03 Writing Algorithms/34 Algorithm Framework/02 Universe Selection/04 Fundamental Universes/02 Fundamental Selection.html similarity index 100% rename from 08 Drafts/03 Writing Algorithms/34 Algorithm Framework/02 Universe Selection/04 Fundamental Universes/02 Fundamental Selection.html rename to 03 Writing Algorithms/34 Algorithm Framework/02 Universe Selection/04 Fundamental Universes/02 Fundamental Selection.html diff --git a/08 Drafts/03 Writing Algorithms/34 Algorithm Framework/02 Universe Selection/04 Fundamental Universes/03 EMA Cross Selection.html b/03 Writing Algorithms/34 Algorithm Framework/02 Universe Selection/04 Fundamental Universes/03 EMA Cross Selection.html similarity index 100% rename from 08 Drafts/03 Writing Algorithms/34 Algorithm Framework/02 Universe Selection/04 Fundamental Universes/03 EMA Cross Selection.html rename to 03 Writing Algorithms/34 Algorithm Framework/02 Universe Selection/04 Fundamental Universes/03 EMA Cross Selection.html diff --git a/03 Writing Algorithms/34 Algorithm Framework/02 Universe Selection/04 Fundamental Universes/15 EMA Cross Selection.html b/03 Writing Algorithms/34 Algorithm Framework/02 Universe Selection/04 Fundamental Universes/15 EMA Cross Selection.html deleted file mode 100644 index 9e95a2585a..0000000000 --- a/03 Writing Algorithms/34 Algorithm Framework/02 Universe Selection/04 Fundamental Universes/15 EMA Cross Selection.html +++ /dev/null @@ -1,54 +0,0 @@ -

    The EmaCrossUniverseSelectionModel applies two exponential moving average (EMA) indicators to the price history of assets and then selects the assets that have their fast EMA furthest above their slow EMA on a percentage basis.

    - -
    -
    public override void Initialize()
    -{
    -    AddUniverseSelection(new EmaCrossUniverseSelectionModel());
    -}
    -
    def Initialize(self) -> None:
    -    self.AddUniverseSelection(EmaCrossUniverseSelectionModel())
    -
    - -

    The following table describes the arguments the model accepts:

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    ArgumentData TypeDescriptionDefault Value
    fastPeriodintFast EMA period100
    slowPeriodintSlow EMA period300
    universeCountintMaximum number of members of this universe selection500
    universeSettingsUniverseSettingsThe settings used when adding symbols to the algorithmNonenull
    - -

    If you don't provide a universeSettings argument, the algorithm.UniverseSettings are used by default.

    - - -

    To view the implementation of this model, see the LEAN GitHub repositoryLEAN GitHub repository.

    diff --git a/08 Drafts/03 Writing Algorithms/34 Algorithm Framework/02 Universe Selection/04 Fundamental Universes/99 Examples.html b/03 Writing Algorithms/34 Algorithm Framework/02 Universe Selection/04 Fundamental Universes/99 Examples.html similarity index 100% rename from 08 Drafts/03 Writing Algorithms/34 Algorithm Framework/02 Universe Selection/04 Fundamental Universes/99 Examples.html rename to 03 Writing Algorithms/34 Algorithm Framework/02 Universe Selection/04 Fundamental Universes/99 Examples.html diff --git a/03 Writing Algorithms/34 Algorithm Framework/02 Universe Selection/04 Fundamental Universes/metadata.json b/03 Writing Algorithms/34 Algorithm Framework/02 Universe Selection/04 Fundamental Universes/metadata.json index c657d0bb02..68844a3476 100644 --- a/03 Writing Algorithms/34 Algorithm Framework/02 Universe Selection/04 Fundamental Universes/metadata.json +++ b/03 Writing Algorithms/34 Algorithm Framework/02 Universe Selection/04 Fundamental Universes/metadata.json @@ -1,9 +1,9 @@ { "type": "metadata", "values": { - "description": "A FundamentalUniverseSelectionModel selects a universe of US Equities based on CoarseFundamental and, sometimes, FineFundamental data.", - "keywords": "US Equity universe, operate on daily schedule, fundamental Universe Selection model, coarse selection function, ine selection function, provides corporate fundamental data, ema cross universe selection, uncorrelated asset selection", - "og:description": "A FundamentalUniverseSelectionModel selects a universe of US Equities based on CoarseFundamental and, sometimes, FineFundamental data.", + "description": "A FundamentalUniverseSelectionModel selects a universe of US Equities based on Fundamental data.", + "keywords": "US Equity universe, operate on daily schedule, fundamental Universe Selection model, fundamental selection function, provides corporate fundamental data, ema cross universe selection, uncorrelated asset selection", + "og:description": "A FundamentalUniverseSelectionModel selects a universe of US Equities based on Fundamental data.", "og:title": "Fundamental Universes - Documentation QuantConnect.com", "og:type": "website", "og:site_name": "Fundamental Universes - QuantConnect.com", diff --git a/08 Drafts/03 Writing Algorithms/34 Algorithm Framework/02 Universe Selection/09 Legacy Fundamental Universes/01 Introduction.html b/03 Writing Algorithms/34 Algorithm Framework/02 Universe Selection/09 Legacy Fundamental Universes/01 Introduction.html similarity index 100% rename from 08 Drafts/03 Writing Algorithms/34 Algorithm Framework/02 Universe Selection/09 Legacy Fundamental Universes/01 Introduction.html rename to 03 Writing Algorithms/34 Algorithm Framework/02 Universe Selection/09 Legacy Fundamental Universes/01 Introduction.html diff --git a/03 Writing Algorithms/34 Algorithm Framework/02 Universe Selection/04 Fundamental Universes/13 Coarse Fundamental Selection.html b/03 Writing Algorithms/34 Algorithm Framework/02 Universe Selection/09 Legacy Fundamental Universes/13 Coarse Fundamental Selection.html similarity index 100% rename from 03 Writing Algorithms/34 Algorithm Framework/02 Universe Selection/04 Fundamental Universes/13 Coarse Fundamental Selection.html rename to 03 Writing Algorithms/34 Algorithm Framework/02 Universe Selection/09 Legacy Fundamental Universes/13 Coarse Fundamental Selection.html diff --git a/03 Writing Algorithms/34 Algorithm Framework/02 Universe Selection/04 Fundamental Universes/14 Fine Fundamental Selection.html b/03 Writing Algorithms/34 Algorithm Framework/02 Universe Selection/09 Legacy Fundamental Universes/14 Fine Fundamental Selection.html similarity index 100% rename from 03 Writing Algorithms/34 Algorithm Framework/02 Universe Selection/04 Fundamental Universes/14 Fine Fundamental Selection.html rename to 03 Writing Algorithms/34 Algorithm Framework/02 Universe Selection/09 Legacy Fundamental Universes/14 Fine Fundamental Selection.html diff --git a/03 Writing Algorithms/34 Algorithm Framework/05 Risk Management/02 Supported Models/06 Maximum Sector Exposure Model.html b/03 Writing Algorithms/34 Algorithm Framework/05 Risk Management/02 Supported Models/06 Maximum Sector Exposure Model.html index ff234475a7..07a41c9505 100644 --- a/03 Writing Algorithms/34 Algorithm Framework/05 Risk Management/02 Supported Models/06 Maximum Sector Exposure Model.html +++ b/03 Writing Algorithms/34 Algorithm Framework/05 Risk Management/02 Supported Models/06 Maximum Sector Exposure Model.html @@ -1,4 +1,4 @@ -

    The MaximumSectorExposureRiskManagementModel limits the absolute portfolio exposure in a each industry sector to a predefined maximum percentage. If the absolute portfolio exposure exceeds the maximum percentage, the weight of each Equity in the sector is scaled down so the sector doesn't exceed the maximum percentage. This process requires assets that are selected by Morningstar fine fundamental data. This model can operate even when the Portfolio Construction model provides an empty list of PortfolioTarget objects.

    +

    The MaximumSectorExposureRiskManagementModel limits the absolute portfolio exposure in a each industry sector to a predefined maximum percentage. If the absolute portfolio exposure exceeds the maximum percentage, the weight of each Equity in the sector is scaled down so the sector doesn't exceed the maximum percentage. This process requires assets that are selected by Morningstar fundamental data. This model can operate even when the Portfolio Construction model provides an empty list of PortfolioTarget objects.

    AddRiskManagement(new MaximumSectorExposureRiskManagementModel());
    diff --git a/03 Writing Algorithms/34 Algorithm Framework/07 Hybrid Algorithms/02 Universe Selection.html b/03 Writing Algorithms/34 Algorithm Framework/07 Hybrid Algorithms/02 Universe Selection.html index 7d749c9d6e..9c5c92fe56 100644 --- a/03 Writing Algorithms/34 Algorithm Framework/07 Hybrid Algorithms/02 Universe Selection.html +++ b/03 Writing Algorithms/34 Algorithm Framework/07 Hybrid Algorithms/02 Universe Selection.html @@ -6,10 +6,10 @@ { SetUniverseSelection(new ManualUniverseSelectionModel(QuantConnect.Symbol.Create("SPY", SecurityType.Equity, Market.USA))); AddUniverseSelection(new ManualUniverseSelectionModel(QuantConnect.Symbol.Create("AAPL", SecurityType.Equity, Market.USA))); - AddUniverse(CoarseSelection); + AddUniverse(FundamentalSelection); }
    def Initialize(self):
         self.SetUniverseSelection(ManualUniverseSelectionModel([ Symbol.Create("SPY", SecurityType.Equity, Market.USA) ]))
         self.AddUniverseSelection(ManualUniverseSelectionModel([ Symbol.Create("AAPL", SecurityType.Equity, Market.USA) ]))
    -    self.AddUniverse(self.CoarseSelection)
    + self.AddUniverse(self.FundamentalSelection) \ No newline at end of file diff --git a/03 Writing Algorithms/40 Live Trading/99 Signal Exports/03 Numerai/04 Universe Selection.html b/03 Writing Algorithms/40 Live Trading/99 Signal Exports/03 Numerai/04 Universe Selection.html index bc591c8fe3..834d2d044b 100644 --- a/03 Writing Algorithms/40 Live Trading/99 Signal Exports/03 Numerai/04 Universe Selection.html +++ b/03 Writing Algorithms/40 Live Trading/99 Signal Exports/03 Numerai/04 Universe Selection.html @@ -1,6 +1,6 @@

    The Numerai Signals stock market universe covers roughly the top 5,000 largest stocks in the world. The universe available on QuantConnect that's the closest match to the Numerai Signals universe is the CRSP US Total Market Index, which represents approximately 100% of the investable US Equity market regularly traded on the New York Stock Exchange and Nasdaq. This Index doesn't contain all of the stocks in the Numerai Signals universe, but you don't need to submit signals for all the stocks in the Numerai Signals universe.

    -

    To get the constituents of the CRSP US Total Market Index, add an ETF constituents universe for the Vanguard Total Stock Market ETF, VTI.

    +

    To get the constituents of the CRSP US Total Market Index, add an ETF constituents universe for the Vanguard Total Stock Market ETF, VTI.

    _etfSymbol = AddEquity("VTI").Symbol;
    diff --git a/04 Research Environment/03 Datasets/06 Equity Fundamental Data/01 Introduction.html b/04 Research Environment/03 Datasets/06 Equity Fundamental Data/01 Introduction.html
    index 1e9b27e6fb..b75cc094ed 100644
    --- a/04 Research Environment/03 Datasets/06 Equity Fundamental Data/01 Introduction.html	
    +++ b/04 Research Environment/03 Datasets/06 Equity Fundamental Data/01 Introduction.html	
    @@ -1 +1 @@
    -

    This page explains how to request, manipulate, and visualize historical Equity Fundamental data. Corporate fundamental data is available through the US Fundamental Data from Morningstar.

    \ No newline at end of file +

    This page explains how to request, manipulate, and visualize historical Equity Fundamental data. Corporate fundamental data is available through the US Fundamental Data from Morningstar.

    diff --git a/08 Drafts/04 Research Environment/03 Datasets/06 Equity Fundamental Data/02 Create Subscriptions.php b/04 Research Environment/03 Datasets/06 Equity Fundamental Data/02 Create Subscriptions.php similarity index 100% rename from 08 Drafts/04 Research Environment/03 Datasets/06 Equity Fundamental Data/02 Create Subscriptions.php rename to 04 Research Environment/03 Datasets/06 Equity Fundamental Data/02 Create Subscriptions.php diff --git a/04 Research Environment/03 Datasets/06 Equity Fundamental Data/03 Create Subscriptions.php b/04 Research Environment/03 Datasets/06 Equity Fundamental Data/03 Create Subscriptions.php deleted file mode 100644 index 03c15fd967..0000000000 --- a/04 Research Environment/03 Datasets/06 Equity Fundamental Data/03 Create Subscriptions.php +++ /dev/null @@ -1,41 +0,0 @@ -

    Follow these steps to subscribe to an Equity security:

    - -
      - -
    1. Create a QuantBook.
    2. -
      -
      var qb = new QuantBook();
      -
      qb = QuantBook()
      -
      -
    3. Call the AddEquity method with a ticker and then save a reference to the Equity Symbol.
    4. - -
      -
      var symbols = new [] 
      -    {
      -        "AAL",  // American Airlines Group, Inc.
      -        "ALGT", // Allegiant Travel Company
      -        "ALK",  // Alaska Air Group, Inc.
      -        "DAL",  // Delta Air Lines, Inc.
      -        "LUV",  // Southwest Airlines Company
      -        "SKYW", // SkyWest, Inc.
      -        "UAL"   // United Air Lines
      -    }
      -    .Select(ticker => qb.AddEquity(ticker).Symbol);
      -
      symbols = [qb.AddEquity(ticker).Symbol
      -    for ticker in [
      -        "AAL",   # American Airlines Group, Inc.
      -        "ALGT",  # Allegiant Travel Company
      -        "ALK",   # Alaska Air Group, Inc.
      -        "DAL",   # Delta Air Lines, Inc.
      -        "LUV",   # Southwest Airlines Company
      -        "SKYW",  # SkyWest, Inc.
      -        "UAL"    # United Air Lines
      -    ]]
      -
      - -
    - -

    To view the supported assets in the US Equities dataset, see the Data Explorer.

    \ No newline at end of file diff --git a/04 Research Environment/03 Datasets/06 Equity Fundamental Data/04 Get Historical Data.html b/04 Research Environment/03 Datasets/06 Equity Fundamental Data/04 Get Historical Data.html index 73e7e4f33b..9ccb04880d 100644 --- a/04 Research Environment/03 Datasets/06 Equity Fundamental Data/04 Get Historical Data.html +++ b/04 Research Environment/03 Datasets/06 Equity Fundamental Data/04 Get Historical Data.html @@ -1,14 +1,112 @@ -

    You need a subscription before you can request historical fundamental data for a US Equity.

    +

    + You need a subscription before you can request historical fundamental data for US Equities. + On the time dimension, you can request an amount of historical data based on a trailing number of bars, a trailing period of time, or a defined period of time. + On the security dimension, you can request historical data for a single US Equity, a set of US Equities, or all of the US Equities in the US Fundamental dataset. + On the property dimension, you can call the History method to get all fundamental properties or you can call the GetFundamental method to get a specific property (for example, the price–earnings ratio). +

    -

    To get historical data, call the GetFundamental method with a list of Symbol objects, a fundamental data field name, a start DateTimedatetime, and an end DateTimedatetime. The start and end times you provide are based in the notebook time zone. To view the possible fundamental data field names, see the FineFundamental attributes in Data Point Attributes. For example, to get data for airline companies over 2014, run:

    +

    + When you call the History method, you can request Fundamental or Fundamentals objects. + If you use Fundamental, the method returns all fundamental properties for the Symbol object(s) you provide. + If you use Fundamentals, the method returns all fundamental properties for all the US Equities in the US Fundamental dataset that were trading during that time period you request, including companies that no longer trade. +

    +

    Trailing Number of Trading Days

    +

    To get historical data for a number of trailing trading days, call the History method with the number of trading days. If you didn't use Resolution.Daily when you subscribed to the US Equities, pass it as the last argument to the History method.

    -
    var startTime = new DateTime(2014, 1, 1);
    -var endTime = new DateTime(2015, 1, 1);
    -var history = qb.GetFundamental(symbols, "ValuationRatios.PERatio", startTime, endTime);
    -
    start_time = datetime(2014, 1, 1)
    -end_time = datetime(2015, 1, 1)
    -history = qb.GetFundamental(symbols, "ValuationRatios.PERatio", start_time, end_time)
    +
    // Fundamental objects
    +var singleFundamentalHistory = qb.History<Fundamental>(symbols.First(), 10);
    +var setFundamentalHistory = qb.History<Fundamental>(symbols, 10);
    +var allFundamentalHistory = qb.History<Fundamental>(qb.Securities.Keys, 10);
    +    
    +// Fundamentals objects
    +var allFundamentalsHistory = qb.History<Fundamentals>(qb.Securities.Keys, 10);
    +
    # DataFrame of fundamental data
    +single_fundamental_df = qb.History(Fundamental, symbols[0], 10)
    +set_fundamental_df = qb.History(Fundamental, symbols, 10)
    +all_fundamental_df = qb.History(Fundamental, qb.Securities.Keys, 10)
    +
    +# Fundamental objects
    +single_fundamental_history = qb.History[Fundamental](symbols[0], 10)
    +set_fundamental_history = qb.History[Fundamental](symbols, 10)
    +all_fundamental_history = qb.History[Fundamental](qb.Securities.Keys, 10)
    +
    +# Fundamentals objects
    +all_fundamentals_history = qb.History[Fundamentals](qb.Securities.Keys, 10)
    +
    +

    The preceding calls return fundamental data for the 10 most recent trading days.

    + +

    Trailing Period of Time

    +

    To get historical data for a trailing period of time, call the History method with a TimeSpantimedelta object.

    + +
    +
    // Fundamental objects
    +var singleFundamentalHistory = qb.History<Fundamental>(symbols.First(), TimeSpan.FromDays(10));
    +var setFundamentalHistory = qb.History<Fundamental>(symbols, TimeSpan.FromDays(10));
    +var allFundamentalHistory = qb.History<Fundamental>(qb.Securities.Keys, TimeSpan.FromDays(10));
    +    
    +// Fundamentals objects
    +var allFundamentalsHistory = qb.History<Fundamentals>(TimeSpan.FromDays(10));
    +
    # DataFrame of fundamental data
    +single_fundamental_df = qb.History(Fundamental, symbols[0], timedelta(days=10))
    +set_fundamental_df = qb.History(Fundamental, symbols, timedelta(days=10))
    +all_fundamental_df = qb.History(Fundamental, qb.Securities.Keys, timedelta(days=10))
    +
    +# Fundamental objects
    +single_fundamental_history = qb.History[Fundamental](symbols[0], timedelta(days=10))
    +set_fundamental_history = qb.History[Fundamental](symbols, timedelta(days=10))
    +all_fundamental_history = qb.History[Fundamental](qb.Securities.Keys, timedelta(days=10))
    +
    +# Fundamentals objects
    +all_fundamentals_history = qb.History[Fundamentals](timedelta(days=10))
    +

    The preceding calls return fundamental data for the most recent trading days.

    + +

    Defined Period of Time

    +

    + To get the historical data of all the fundamental properties over specific period of time, call the History method with a start DateTimedatetime and an end DateTimedatetime. + To get the historical data of a single fundamental property over a specific period of time, call the GetFundamental method and include the name of a fundamental property. + To view the possible fundamental properties, see the Fundamental attributes in Data Point Attributes. + The start and end times you provide to these methods are based in the notebook time zone. +

    + +
    +
    var startDate = new DateTime(2021, 1, 1);
    +var endDate = new DateTime(2021, 2, 1);
    +
    +// Fundamental objects
    +var singleFundamentalHistory = qb.History<Fundamental>(symbols.First(), startDate, endDate);
    +var setFundamentalHistory = qb.History<Fundamental>(symbols, startDate, endDate);
    +var allFundamentalHistory = qb.History<Fundamental>(qb.Securities.Keys, startDate, endDate);
    +    
    +// Fundamentals objects
    +var allFundamentalsHistory = qb.History<Fundamentals>(qb.Securities.Keys, startDate, endDate);
    +
    +// DataDictionary objects
    +var singleOneAttributeHistory = qb.GetFundamental(symbols.First(), "ValuationRatios.PERatio", startDate, endDate);
    +var setOneAttributeHistory = qb.GetFundamental(symbols, "ValuationRatios.PERatio", startDate, endDate);
    +var allOneAttributeHistory = qb.GetFundamental(qb.Securities.Keys, "ValuationRatios.PERatio", startDate, endDate);
    +
    start_date = datetime(2021, 1, 1)
    +end_date = datetime(2021, 2, 1)
    +
    +# DataFrame of all fundamental properties
    +single_fundamental_df = qb.History(Fundamental, symbols[0], start_date, end_date)
    +set_fundamental_df = qb.History(Fundamental, symbols, start_date, end_date)
    +all_fundamental_df = qb.History(Fundamental, qb.Securities.Keys, start_date, end_date)
    +
    +# DataFrame of a fundamental property
    +single_one_attribute_df = qb.GetFundamental(symbols[0], "ValuationRatios.PERatio", start_date, end_date)
    +set_one_attribute_df = qb.GetFundamental(symbols, "ValuationRatios.PERatio", start_date, end_date)
    +all_one_attribute_df = qb.GetFundamental(qb.Securities.Keys, "ValuationRatios.PERatio", start_date, end_date)
    +
    +# Fundamental objects
    +single_fundamental_history = qb.History[Fundamental](symbols[0], start_date, end_date)
    +set_fundamental_history = qb.History[Fundamental](symbols, start_date, end_date)
    +all_fundamental_history = qb.History[Fundamental](qb.Securities.Keys, start_date, end_date)
    +
    +# Fundamentals objects
    +all_fundamentals_history = qb.History[Fundamentals](qb.Securities.Keys, start_date, end_date)
    +
    + +

    The preceding method returns the fundamental property values that are timestamped within the defined period of time.

    -

    The preceding method returns the fundamental data field values that are timestamped within the defined period of time.

    diff --git a/04 Research Environment/03 Datasets/06 Equity Fundamental Data/05 Wrangle Data.html b/04 Research Environment/03 Datasets/06 Equity Fundamental Data/05 Wrangle Data.html index fd19af450b..0c40523f70 100644 --- a/04 Research Environment/03 Datasets/06 Equity Fundamental Data/05 Wrangle Data.html +++ b/04 Research Environment/03 Datasets/06 Equity Fundamental Data/05 Wrangle Data.html @@ -1,17 +1,83 @@

    You need some historical data to perform wrangling operations. To display pandas objects, run a cell in a notebook with the pandas object as the last line. To display other data formats, call the print method.

    You need some historical data to perform wrangling operations. Use LINQ to wrangle the data and then call the Console.WriteLine method in a Jupyter Notebook to display the data.

    -

    The DataFrame index is the EndTime of the data sample. The columns of the DataFrame are the Equity Symbol objects.

    +

    DataFrame Objects

    +

    The History method returns a multi-index DataFrame where the first level is the Equity Symbol and the second level is the EndTime of the trading day. The columns of the DataFrame are the names of the fundamental properties. The following image shows the first 4 columns of an example DataFrame:

    +Historical fundamental properties dataframe for US Equities -Historical PE ratio of US Equities +

    The GetFundamental method returns a DataFrame where the index is the EndTime of the trading day. The columns of the DataFrame are the Equity Symbol objects.

    +Historical PE ratio of US Equities +

    To select the historical data of a single Equity in the preceding DataFrame, index it with the Equity Symbol. Each history slice may not have data for all of your Equity subscriptions. To avoid issues, check if it contains data for your Equity before you index it with the Equity Symbol.

    +
    +
    all_one_attribute_df[symbols[1]]
    +
    +Historical PE ratio of a single symbol -

    To get the fundamental data points for each Equity, iterate through the history request result.

    +

    Fundamental Objects

    +

    If you pass a Symbol to the History[Fundamental]History<Fundamental> method, run the following code to get the fundamental properties over time:

    +
    +
    for fundamental in single_fundamental_history:
    +    symbol = fundamental.Symbol
    +    end_time = fundamental.EndTime
    +    pe_ratio = fundamental.ValuationRatios.PERatio
    +
    foreach (var fundamental in singleFundamentalHistory) // Iterate trading days
    +{
    +    var endTime = fundamental.EndTime;
    +    var peRatio = fundamental.ValuationRatios.PERatio;
    +}
    +
    -

    To select the historical data of a single Equity, index the DataFrame with the Equity Symbol. Each history slice may not have data for all of your Equity subscriptions. To avoid issues, check if it contains data for your Equity before you index it with the Equity Symbol.

    +

    If you pass a list of Symbol objects to the History[Fundamental]History<Fundamental> method, run the following code to get the fundamental properties over time:

    +
    +
    for fundamental_dict in set_fundamental_history: # Iterate trading days
    +    for symbol, fundamental in fundamental_dict.items(): # Iterate Symbols
    +        end_time = fundamental.EndTime
    +        pe_ratio = fundamental.ValuationRatios.PERatio
    +
    foreach (var fundamentalDict in setFundamentalHistory) // Iterate trading days
    +{
    +    foreach (var kvp in fundamentalDict) // Iterate Symbols
    +    {
    +        var symbol = kvp.Key;
    +        var fundamental = kvp.Value;
    +        var endTime = fundamental.EndTime;
    +        var peRatio = fundamental.ValuationRatios.PERatio;
    +    }
    +}
    +
    +

    Fundamentals Objects

    +

    If you request all fundamental properties for all US Equities with the History[Fundamentals]History<Fundamentals> method, run the following code to get the fundamental properties over time:

    -
    foreach (var slice in history)
    +    
    for fundamentals_dict in all_fundamentals_history: # Iterate trading days
    +    fundamentals = list(fundamentals_dict.Values)[0]
    +    end_time = fundamentals.EndTime
    +    for fundamental in fundamentals.Data: # Iterate Symbols
    +        if not fundamental.HasFundamentalData:
    +            continue
    +        symbol = fundamental.Symbol
    +        pe_ratio = fundamental.ValuationRatios.PERatio
    +
    foreach (var fundamentalsDict in allFundamentalsHistory) // Iterate trading days
     {
    +    var fundamentals = fundamentalsDict.Values.First().Data;
    +    foreach (Fundamental fundamental in fundamentals) // Iterate Symbols
    +    {
    +        if (!fundamental.HasFundamentalData)
    +        {
    +            continue;
    +        }
    +        var endTime = fundamental.EndTime;
    +        var symbol = fundamental.Symbol;
    +        var peRatio = fundamental.ValuationRatios.PERatio;
    +    }
    +}
    +
    + +

    DataDictionary Objects

    +

    To get the fundamental data points for each Equity, iterate through the history request result.

    +
    +
    foreach (var slice in allOneAttributeHistory)
    +{
    +    var endTime = slice.Time;
         foreach (var symbol in symbols)
         {
             if (slice.ContainsKey(symbol))
    @@ -20,15 +86,13 @@
             }
         }
     }
    -
    history[symbols[1]]
    -Historical PE ratio of a single symbol -

    You can also iterate through each data point in the slice.

    -
    foreach (var slice in history)
    +    
    foreach (var slice in allOneAttributeHistory)
     {
    +    var endTime = slice.Time;
         foreach (var kvp in slice)
         {
             var symbol = kvp.Key;
    @@ -41,6 +105,5 @@
     
     
    var symbol = symbols.Last();
    -var values = history.Select(slice => slice[symbol]);
    +var values = allOneAttributeHistory.Select(slice => slice[symbol]);
    - diff --git a/04 Research Environment/03 Datasets/06 Equity Fundamental Data/06 Plot Data.html b/04 Research Environment/03 Datasets/06 Equity Fundamental Data/06 Plot Data.html index 2e1160fed1..cff3e9def5 100644 --- a/04 Research Environment/03 Datasets/06 Equity Fundamental Data/06 Plot Data.html +++ b/04 Research Environment/03 Datasets/06 Equity Fundamental Data/06 Plot Data.html @@ -2,33 +2,41 @@

    Follow these steps to plot line charts using built-in methodsPlotly.NET package:

    -
      -
    1. Call the plot method on the history DataFrame.
    2. -
      -
      history.plot(title='PE Ratio Over Time', figsize=(15, 8))
      +
        +
      1. Get some historical data.
      2. +
        +
        var history = qb.GetFundamental(symbols, "ValuationRatios.PERatio", new DateTime(2014, 1, 1), new DateTime(2015, 1, 1));
        +
        history = qb.GetFundamental(symbols, "ValuationRatios.PERatio", datetime(2014, 1, 1), datetime(2015, 1, 1))
        -
      3. Create Line charts.
      4. +
      5. Load the Plotly.NET package.
      6. -
        var chart1 = Chart2D.Chart.Line<DateTime, decimal, string>(
        -    history.Select(x => (DateTime)x.Time),
        -    history.Select(x => (decimal)x[aapl]),
        -    Name: "AAPL"
        -);
        -var chart2 = Chart2D.Chart.Line<DateTime, decimal, string>(
        -    history.Select(x => (DateTime)x.Time),
        -    history.Select(x => (decimal)x[goog]),
        -    Name: "GOOG"
        +        
        #r "../Plotly.NET.dll"
        +#r "../Plotly.NET.Interactive.dll"
        +
        +using Plotly.NET;
        +using Plotly.NET.Interactive;
        +using Plotly.NET.LayoutObjects;
        +
        + +
      7. Create Line objects for each Symbol.
      8. +
        +
        var charts = symbols.Select(
        +    symbol => Chart2D.Chart.Line<DateTime, decimal, string>(
        +        history.Select(x => (DateTime)x.Time),
        +        history.Select(x => (decimal)x[symbol]),
        +        Name: symbol.Value
        +    )
         );
      9. Create a Layout.
      10. -
        LinearAxis xAxis = new LinearAxis();
        +        
        LinearAxis xAxis = new LinearAxis();
         xAxis.SetValue("title", "Time");
         LinearAxis yAxis = new LinearAxis();
         yAxis.SetValue("title", "PE Ratio");
        -Title title = Title.init("AAPL & GOOG PE Ratio");
        +Title title = Title.init("PE Ratios Over Time");
         
         Layout layout = new Layout();
         layout.SetValue("xaxis", xAxis);
        @@ -38,9 +46,14 @@
         
             
      11. Combine the charts and assign the Layout to the chart.
      12. -
        var chart = Plotly.NET.Chart.Combine(new []{chart1, chart2});
        +        
        var chart = Plotly.NET.Chart.Combine(charts);
         chart.WithLayout(layout);
        + +
      13. Call the plot method on the history DataFrame.
      14. +
        +
        history.plot(title='PE Ratio Over Time', figsize=(15, 8))
        +
      15. Show the plot.
      16. @@ -51,4 +64,4 @@
      Line plot of PE ratio of US Equities -Line plot of PE ratio of AAPL & GOOG \ No newline at end of file +Line plot of PE ratio of US Equities diff --git a/04 Research Environment/03 Datasets/06 Equity Fundamental Data/metadata.json b/04 Research Environment/03 Datasets/06 Equity Fundamental Data/metadata.json index de647ed6fc..00bef67a8c 100644 --- a/04 Research Environment/03 Datasets/06 Equity Fundamental Data/metadata.json +++ b/04 Research Environment/03 Datasets/06 Equity Fundamental Data/metadata.json @@ -9,4 +9,4 @@ "og:site_name": "Equity Fundamental Data - QuantConnect.com", "og:image": "https://cdn.quantconnect.com/docs/i/research-environment/datasets/equity-fundamental-data.png" } -} \ No newline at end of file +} diff --git a/05 Lean CLI/05 Datasets/02 Downloading Data/01 Download By Ticker/02 Costs/02 US Equity.php b/05 Lean CLI/05 Datasets/02 Downloading Data/01 Download By Ticker/02 Costs/02 US Equity.php index 5589297740..782986b6c3 100644 --- a/05 Lean CLI/05 Datasets/02 Downloading Data/01 Download By Ticker/02 Costs/02 US Equity.php +++ b/05 Lean CLI/05 Datasets/02 Downloading Data/01 Download By Ticker/02 Costs/02 US Equity.php @@ -54,13 +54,13 @@ - Coarse or Dollar Volume + Fundamental or Dollar Volume US Equity Coarse Universe One file per day. 5 QCC = $0.05 USD - ETF Constituents + ETF Constituents US ETF Constituents One file per ETF per day. 50 QCC = $0.50 USD diff --git a/08 Drafts/03 Writing Algorithms/03 Securities/99 Asset Classes/01 US Equity/06 Corporate Fundamentals/01 Introduction.html b/08 Drafts/03 Writing Algorithms/03 Securities/99 Asset Classes/01 US Equity/06 Corporate Fundamentals/01 Introduction.html deleted file mode 100644 index c4f39a1abf..0000000000 --- a/08 Drafts/03 Writing Algorithms/03 Securities/99 Asset Classes/01 US Equity/06 Corporate Fundamentals/01 Introduction.html +++ /dev/null @@ -1 +0,0 @@ -

      Corporate fundamental data contains all the information on the underlying company of an Equity asset and the information in their financial statements. Since corporate data contains information not found in price and alternative data, adding corporate data to your trading strategies provides you with more information so you can make more informed trading decisions. Corporate fundamental data is available through the US Fundamental Data from Morningstar.

      diff --git a/08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/03 ETF Constituents Universes/metadata.json b/08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/03 ETF Constituents Universes/metadata.json deleted file mode 100644 index 9d1e68696e..0000000000 --- a/08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/03 ETF Constituents Universes/metadata.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "type": "metadata", - "values": { - "description": "You can select a universe based on coarse data or the constituents of an ETF, and then you can further filter your universe down with fundamentals.", - "keywords": "ETF constituents", - "og:description": "You can select a universe based on coarse data or the constituents of an ETF, and then you can further filter your universe down with fundamentals.", - "og:title": "Equity - Documentation QuantConnect.com", - "og:type": "website", - "og:site_name": "Equity - QuantConnect.com", - "og:image": "https://cdn.quantconnect.com/docs/i/writing-algorithms/universes/equity.png" - } -} diff --git a/08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/04 Chained Universes/00 Introduction.html b/08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/04 Chained Universes/00 Introduction.html deleted file mode 100644 index 0d2e8c9671..0000000000 --- a/08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/04 Chained Universes/00 Introduction.html +++ /dev/null @@ -1 +0,0 @@ -

      You can combine ("chain") universes together to fetch fundamental and alternative data on a specific subset of assets. Universes filter input data and return Symbol objects. The only requirement is that Symbol objects the filter returns are a subset of the input data. The source of the Symbol objects is unrestricted, so you can feed the output of one universe into another.

      \ No newline at end of file diff --git a/08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/05 Legacy Fundamental Universes/01 Introduction.html b/08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/05 Legacy Fundamental Universes/01 Introduction.html deleted file mode 100644 index 543428fa91..0000000000 --- a/08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/05 Legacy Fundamental Universes/01 Introduction.html +++ /dev/null @@ -1 +0,0 @@ -

      There are several ways to create an Equities universe. You can select a universe based on CoarseFundamental data or the constituents of an ETF, and then you can further filter your universe down with corporate fundamentals. The following sections explain each of these techniques in detail.

      \ No newline at end of file diff --git a/08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/05 Legacy Fundamental Universes/02 Coarse Universe Selection.php b/08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/05 Legacy Fundamental Universes/02 Coarse Universe Selection.php deleted file mode 100644 index ba57e7f3d0..0000000000 --- a/08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/05 Legacy Fundamental Universes/02 Coarse Universe Selection.php +++ /dev/null @@ -1,31 +0,0 @@ -

      A coarse universe enables you pick a set of stocks based on their trading volume, price, or whether they have fundamental data. To add a coarse universe, in the Initialize method, pass a filter function to the AddUniverse method. The coarse filter function receives a list of CoarseFundamental objects and must return a list of Symbol objects. The Symbol objects you return from the function are the constituents of the universe and LEAN automatically creates subscriptions for them. Don't call AddEquity in the filter function.

      - -
      -
      public class MyCoarseUniverseAlgorithm : QCAlgorithm
      -{
      -    public override void Initialize()
      -    {
      -        AddUniverse(CoarseFilterFunction);
      -    }
      -
      -    private IEnumerable<Symbol> CoarseFilterFunction(IEnumerable<CoarseFundamental> coarse)
      -    {
      -        return (from c in coarse
      -            orderby c.DollarVolume descending
      -            select c.Symbol).Take(100);
      -    }
      -}
      -
      class MyCoarseUniverseAlgorithm(QCAlgorithm):
      -    def Initialize(self) -> None:
      -        self.AddUniverse(self.CoarseFilterFunction)
      -
      -    def CoarseFilterFunction(self, coarse: List[CoarseFundamental]) -> List[Symbol]:
      -        sorted_by_dollar_volume = sorted(coarse, key=lambda x: x.DollarVolume, reverse=True) 
      -        return [c.Symbol for c in sorted_by_dollar_volume[:100]]
      -
      - -

      CoarseFundamental objects have the following attributes:

      - -
      - -

      The total number of stocks in the US Equity Security Master dataset is but your coarse filter function won't receive all of these at one time because the US Equity Security Master dataset is free of survivorship bias and some of the securities have delisted over time. The number of securities that are passed into your coarse filter function depends on the date of your algorithm. Currently, there are about securities that LEAN passes into your coarse filter function.

      diff --git a/08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/05 Legacy Fundamental Universes/05 Fundamentals Selection.php b/08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/05 Legacy Fundamental Universes/05 Fundamentals Selection.php deleted file mode 100644 index a77ceb73ab..0000000000 --- a/08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/05 Legacy Fundamental Universes/05 Fundamentals Selection.php +++ /dev/null @@ -1,161 +0,0 @@ - - -

      A fundamental universe lets you select stocks based on corporate fundamental data. This data is powered by Morningstar® and includes approximately tickers with 900 properties each. Due to the sheer volume of information, fundamental selection is performed on the output of another universe filter. Think of this process as a 2-stage filter. An initial filter function selects a set of stocks and then a fine fundamental filter function selects a subset of those stocks.

      - - -
      -Fundamental selection process -
      QuantConnect Coarse and Fine Universe Selection
      -
      - -

      To add a fundamental universe, in the Initialize method, pass two filter functions to the AddUniverse method. The first filter function can be a coarse universe filter, dollar volume filter, or an ETF constituents filter. The second filter function receives a list of FineFundamental objects and must return a list of Symbol objects. The list of FineFundamental objects contains a subset of the Symbol objects that the first filter function returned. The Symbol objects you return from the second function are the constituents of the fundamental universe and LEAN automatically creates subscriptions for them. Don't call AddEquity in the filter function.

      - -
      - Tip: -

      Only assets have fundamental data. If your first filter function receives CoarseFundamental data, you should only select assets that have a true value for their HasFundamentalData property.

      -
      - -
      -
      -public class MyUniverseAlgorithm : QCAlgorithm {
      -    public override void Initialize() 
      -    {
      -        AddUniverse(CoarseFilterFunction, FineFundamentalFilterFunction);
      -    }
      -    // filter based on CoarseFundamental
      -    IEnumerable<Symbol> CoarseFilterFunction(IEnumerable<CoarseFundamental> coarse) 
      -    {
      -         // In addition to further coarse universe selection, ensure the security has fundamental data
      -         return (from c in coarse
      -             where c.HasFundamentalData
      -             select c.Symbol);
      -    }
      -    // filter based on FineFundamental
      -    public IEnumerable<Symbol> FineFundamentalFilterFunction(IEnumerable<FineFundamental> fine)
      -    {
      -        // Return a list of Symbols
      -    }
      -}
      -
      -
      -class MyUniverseAlgorithm(QCAlgorithm):
      -    def Initialize(self) -> None:
      -        self.AddUniverse(self.CoarseFilterFunction, self.FineFundamentalFunction)
      -
      -    def CoarseFilterFunction(self, coarse: List[CoarseFundamental]) -> List[Symbol]:
      -        # In addition to further coarse universe selection, ensure the security has fundamental data
      -        return [c.Symbol for c in coarse if c.HasFundamentalData]
      -
      -    def FineFundamentalFunction(self, fine: List[FineFundamental]) -> List[Symbol]:
      -        # Return a list of Symbols
      -
      -
      - -

      FineFundamental objects have the following attributes:

      -
      - - - -

      Example

      -

      -The simplest example of accessing the fundamental object would be harnessing the iconic PE ratio for a stock. This is a ratio of the price it commands to the earnings of a stock. The lower the PE ratio for a stock, the more affordable it appears. -

      - -
      -
      // Take the top 50 by dollar volume using coarse
      -// Then the top 10 by PERatio using fine
      -AddUniverse(
      -    coarse => {
      -        return (from c in coarse
      -            where c.Price > 10 && c.HasFundamentalData
      -            orderby c.DollarVolume descending
      -            select c.Symbol).Take(50);
      -    },
      -    fine => {
      -        return (from f in fine
      -            orderby f.ValuationRatios.PERatio ascending
      -            select f.Symbol).Take(10);
      -    });
      -
      -
      # In Initialize:
      -self.AddUniverse(self.CoarseSelectionFunction, self.FineSelectionFunction)
      -
      -def CoarseSelectionFunction(self, coarse: List[CoarseFundamental]) -> List[Symbol]:
      -    sortedByDollarVolume = sorted(coarse, key=lambda x: x.DollarVolume, reverse=True)
      -    filtered = [x.Symbol for x in sortedByDollarVolume if x.HasFundamentalData]
      -    return filtered[:50]
      -
      -def FineSelectionFunction(self, fine: List[FineFundamental]) -> List[Symbol]:
      -    sortedByPeRatio = sorted(fine, key=lambda x: x.ValuationRatios.PERatio, reverse=False)
      -    return [x.Symbol for x in sortedByPeRatio[:10]]
      -
      -
      - -

      Asset Categories

      -

      In addition to valuation ratios, the US Fundamental Data from Morningstar has many other data point attributes, including over 200 different categorization fields for each US stock. Morningstar groups these fields into sectors, industry groups, and industries.

      - -

      Sectors are large super categories of data. To get the sector of a stock, use the MorningstarSectorCode property.

      -
      -
      var tech = fine.Where(x => x.AssetClassification.MorningstarSectorCode == MorningstarSectorCode.Technology);
      -
      tech = [x for x in fine if x.AssetClassification.MorningstarSectorCode == MorningstarSectorCode.Technology]
      -
      -
      - -

      Industry groups are clusters of related industries that tie together. To get the industry group of a stock, use the MorningstarIndustryGroupCode property.

      -
      -
      var ag = fine.Where(x => x.AssetClassification.MorningstarIndustryGroupCode == MorningstarIndustryGroupCode.Agriculture);
      -
      ag = [x for x in fine if x.AssetClassification.MorningstarIndustryGroupCode == MorningstarIndustryGroupCode.Agriculture]
      -
      -
      - -

      Industries are the finest level of classification available. They are the individual industries according to the Morningstar classification system. To get the industry of a stock, use the MorningstarIndustryCode.

      -
      -
      var coal = fine.Where(x => x.AssetClassification.MorningstarIndustryCode == MorningstarSectorCode.Coal);
      -
      coal = [x for x in fine if x.AssetClassification.MorningstarIndustryCode == MorningstarSectorCode.Coal]
      -
      -
      - - -

      Practical Limitations

      -

      -Like coarse universes, fine universes allow you to select an unlimited universe of assets to analyze. Each asset in the universe consumes approximately 5MB of RAM, so you may quickly run out of memory if your universe filter selects many assets. If you backtest your algorithms in the Algorithm Lab, familiarize yourself with the RAM capacity of your backtesting and live trading nodes. To keep your algorithm fast and efficient, only subscribe to the assets you need. -

      diff --git a/08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/05 Legacy Fundamental Universes/07 Live Trading Considerations.php b/08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/05 Legacy Fundamental Universes/07 Live Trading Considerations.php deleted file mode 100644 index 11c93ca2dd..0000000000 --- a/08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/05 Legacy Fundamental Universes/07 Live Trading Considerations.php +++ /dev/null @@ -1 +0,0 @@ - diff --git a/08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/05 Legacy Fundamental Universes/08 Examples.html b/08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/05 Legacy Fundamental Universes/08 Examples.html deleted file mode 100644 index e85cdb67fd..0000000000 --- a/08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/05 Legacy Fundamental Universes/08 Examples.html +++ /dev/null @@ -1,189 +0,0 @@ - - -

      The following examples are typical filter functions you may want.

      -

      Example 1: Take 500 stocks that are worth more than $10 and have more than $10M daily trading volume

      -

      -The most common use case is to select a lot of liquid stocks. With a coarse universe filter, this is simple and fast. The following example selects the top most liquid 500 stocks over $10 per share. -

      -
      -
      IEnumerable<Symbol> CoarseFilterFunction(IEnumerable<CoarseFundamental> coarse) 
      -{
      -    // Linq makes this a piece of cake;
      -    return (from c in coarse
      -        where c.DollarVolume > 10000000 &&
      -            c.Price > 10
      -        orderby c.DollarVolume descending
      -        select c.Symbol).Take(500);
      -}
      -
      def CoarseFilterFunction(self, coarse: List[CoarseFundamental]) -> List[Symbol]:
      -    sortedByDollarVolume = sorted(coarse, key=lambda x: x.DollarVolume, reverse=True)
      -    filtered = [ x.Symbol for x in sortedByDollarVolume 
      -                if x.Price > 10 and x.DollarVolume > 10000000 ]
      -    return filtered[:500]
      -
      - - -

      Example 2: Take 10 stocks above their 200-Day EMA and have more than $1B daily trading volume

      -

      -Another common request is to filter the universe by a technical indicator, such as only picking stocks above their 200-day EMA. The CoarseFundamental object has adjusted price and volume information, so you can do any price-related analysis. -

      -
      -
      ConcurrentDictionary<Symbol, SelectionData>
      -    _stateData = new ConcurrentDictionary<Symbol, SelectionData>();
      -
      -// Coarse filter function
      -IEnumerable<Symbol> CoarseFilterFunction(IEnumerable<CoarseFundamental> coarse) {
      -    // Linq makes this a piece of cake;
      -    return (from c in coarse
      -        let avg = _stateData.GetOrAdd(c.Symbol, sym => new SelectionData(200))
      -        where avg.Update(c.EndTime, c.AdjustedPrice)
      -        where c.DollarVolume > 1000000000 &&
      -                c.Price > avg.Ema
      -        orderby c.DollarVolume descending
      -        select c.Symbol).Take(10);
      -}
      -
      # setup state storage in initialize method
      -self.stateData = { }
      -
      -def CoarseFilterFunction(self, coarse: List[CoarseFundamental]) -> List[Symbol]:
      -    # We are going to use a dictionary to refer the object that will keep the moving averages
      -    for c in coarse:
      -        if c.Symbol not in self.stateData:
      -            self.stateData[c.Symbol] = SelectionData(c.Symbol, 200)
      -
      -        # Updates the SymbolData object with current EOD price
      -        avg = self.stateData[c.Symbol]
      -        avg.update(c.EndTime, c.AdjustedPrice, c.DollarVolume)
      -
      -    # Filter the values of the dict to those above EMA and more than $1B vol.
      -    values = [x for x in self.stateData.values() if x.is_above_ema and x.volume > 1000000000]
      -    
      -    # sort by the largest in volume.
      -    values.sort(key=lambda x: x.volume, reverse=True)
      -
      -    # we need to return only the symbol objects
      -    return [ x.symbol for x in values[:10] ]
      -
      -

      -In this example, the SelectionData class group variables for the universe selection and updates the indicator of each asset. We highly recommend you follow this pattern to keep your algorithm tidy and bug free. The following snippet shows an example implementation of the SelectionData class, but you can make this whatever you need to store your custom universe filters. -

      -
      -
      class SelectionData(object):
      -    def __init__(self, symbol, period):
      -        self.symbol = symbol
      -        self.ema = ExponentialMovingAverage(period)
      -        self.is_above_ema = False
      -        self.volume = 0
      -
      -    def update(self, time, price, volume):
      -        self.volume = volume
      -        if self.ema.Update(time, price):
      -            self.is_above_ema = price > ema
      -
      // example selection data class
      -private class SelectionData
      -{
      -    // variables you need for selection
      -    public readonly ExponentialMovingAverage Ema;
      -
      -    // initialize your variables and indicators.
      -    public SelectionData(int period)
      -    {
      -        Ema = new ExponentialMovingAverage(period);
      -    }
      -
      -    // update your variables and indicators with the latest data.
      -    // you may also want to use the History API here.
      -    public bool Update(DateTime time, decimal value)
      -    {
      -        return Ema.Update(time, value);
      -    }
      -}
      -
      - -

      Note that the preceding SelectionData class uses a manual EMA indicator instead of the automatic version. For more information about universes that select assets based on indicators, see Indicator Universes. You need to use a SelectionData class instead of assigning the EMA to the CoarseFundamental object because you can't create custom propertiesattributes on CoarseFundamental objects like you can with Security objects.

      - -

      Example 3: Take 10 stocks that are the furthest above their 10-day SMA of volume

      -

      -The process to get the 10-day SMA stock volume is the same process as in Example 2. First, you should define a SelectionData class that performs the averaging. For this example, the following class will serve this purpose: -

      -
      -
      class SelectionData(object):
      -    def __init__(self, symbol, period):
      -        self.symbol = symbol
      -        self.volume = 0
      -        self.volume_ratio = 0
      -        self.sma = SimpleMovingAverage(period)
      -
      -    def update(self, time, price, volume):
      -        self.volume = volume
      -        if self.sma.Update(time, volume):
      -            # get ratio of this volume bar vs previous 10 before it.
      -            self.volume_ratio = volume / self.sma.Current.Value
      -
      private class SelectionData
      -{
      -    public readonly Symbol Symbol;
      -    public readonly SimpleMovingAverage VolumeSma;
      -    public decimal VolumeRatio;
      -    public SelectionData(Symbol symbol, int period)
      -    {
      -        Symbol = symbol;
      -        VolumeSma = new SimpleMovingAverage(period);
      -    }
      -    public bool Update(DateTime time, decimal value)
      -    {
      -        var ready = VolumeSma.Update(time, value);
      -        VolumeRatio = value / VolumeSma;
      -        return ready;
      -    }
      -}
      -
      -

      -This class tracks the ratio of today's volume relative to historical volumes. You can use this ratio to select assets that are above their 10-day simple moving average and sort the results by the ones that have had the biggest jump since yesterday. -

      - -
      -
      def CoarseFilterFunction(self, coarse: List[CoarseFundamental]) -> List[Symbol]:
      -    for c in coarse:
      -        if c.Symbol not in self.stateData:
      -            self.stateData[c.Symbol] = SelectionData(c.Symbol, 10)
      -        avg = self.stateData[c.Symbol]
      -        avg.update(c.EndTime, c.AdjustedPrice, c.DollarVolume)
      -
      -    # filter the values of selectionData(sd) above SMA
      -    values = [sd for sd in self.stateData.values() if sd.volume > sd.sma.Current.Value and sd.volume_ratio > 0]
      -        
      -    # sort sd by the largest % jump in volume.
      -    values.sort(key=lambda sd: sd.volume_ratio, reverse=True)
      -
      -    # return the top 10 symbol objects
      -    return [ sd.symbol for sd in values[:10] ]
      -
      -
       
      -IEnumerable<Symbol> CoarseFilterFunction(IEnumerable<CoarseFundamental> coarse) 
      { - return (from c in coarse - let avg = _stateData.GetOrAdd(c.Symbol, sym => new SelectionData(10)) - where avg.Update(c.EndTime, c.Volume) - where c.Volume > avg.VolumeSma - orderby avg.VolumeRatio descending - select c.Symbol).Take(10); -}
      -
      - - -

      Example 4: Take the top 10 "fastest moving" stocks with a 50-Day EMA > 200 Day EMA

      -

      You can construct complex universe filters with the SelectionData helper class pattern. To view a full example of this algorithm, see the EmaCrossUniverseSelectionAlgorithmEmaCrossUniverseSelectionAlgorithm in the LEAN GitHub repository or take the related Boot Camp lesson.

      - - - diff --git a/08 Drafts/03 Writing Algorithms/34 Algorithm Framework/02 Universe Selection/01 Key Concepts/04 Multi-Universe Algorithms.html b/08 Drafts/03 Writing Algorithms/34 Algorithm Framework/02 Universe Selection/01 Key Concepts/04 Multi-Universe Algorithms.html deleted file mode 100644 index 54a81e92b5..0000000000 --- a/08 Drafts/03 Writing Algorithms/34 Algorithm Framework/02 Universe Selection/01 Key Concepts/04 Multi-Universe Algorithms.html +++ /dev/null @@ -1,14 +0,0 @@ -

      You can add multiple Universe Selection models to a single algorithm.

      - -
      -
      var symbols = new [] {QuantConnect.Symbol.Create("SPY", SecurityType.Equity, Market.USA)};
      -AddUniverseSelection(new ManualUniverseSelectionModel(symbols));
      -
      -AddUniverseSelection(new EmaCrossUniverseSelectionModel());
      -
      symbols = [Symbol.Create("SPY", SecurityType.Equity, Market.USA)]
      -self.AddUniverseSelection(ManualUniverseSelectionModel(symbols))
      -		
      -self.AddUniverseSelection(EmaCrossUniverseSelectionModel())
      -
      - -

      If you add multiple Universe Selection models, the algorithm subscribes to the constituents of all the models.

      diff --git a/08 Drafts/03 Writing Algorithms/34 Algorithm Framework/02 Universe Selection/04 Fundamental Universes/01 Introduction.html b/08 Drafts/03 Writing Algorithms/34 Algorithm Framework/02 Universe Selection/04 Fundamental Universes/01 Introduction.html deleted file mode 100644 index 8eeffab311..0000000000 --- a/08 Drafts/03 Writing Algorithms/34 Algorithm Framework/02 Universe Selection/04 Fundamental Universes/01 Introduction.html +++ /dev/null @@ -1,5 +0,0 @@ -

      A FundamentalUniverseSelectionModel selects a universe of US Equities based on Fundamental data. Depending on the Fundamental properties you use, these universes rely on the US Equity Coarse Universe dataset, the US Fundamental dataset, or both.

      - -

      These types of universes operate on daily schedule. In backtests, they select assets at midnight. In live trading, the selection timing depends on the data feed you use.

      - -

      If you use a fundamental Universe Selection model, the only way to unsubscribe from a security is to return a list from the selection function that doesn't include the security Symbol. The RemoveSecurity method doesn't work with these types of Universe Selection models.

      diff --git a/08 Drafts/03 Writing Algorithms/34 Algorithm Framework/02 Universe Selection/09 Legacy Fundamental Universes/13 Coarse Fundamental Selection.html b/08 Drafts/03 Writing Algorithms/34 Algorithm Framework/02 Universe Selection/09 Legacy Fundamental Universes/13 Coarse Fundamental Selection.html deleted file mode 100644 index dc82bf9ec6..0000000000 --- a/08 Drafts/03 Writing Algorithms/34 Algorithm Framework/02 Universe Selection/09 Legacy Fundamental Universes/13 Coarse Fundamental Selection.html +++ /dev/null @@ -1,65 +0,0 @@ -

      The CoarseFundamentalUniverseSelectionModel selects assets based on CoarseFundamental data. To use this model, define a coarse selection function. The coarse selection function receives a list of -CoarseFundamental objects and returns a list of Symbol objects. The Symbol objects you return from the coarse selection function are the constituents of the universe.

      - -
      -
      public override void Initialize()
      -{
      -    AddUniverseSelection(new CoarseFundamentalUniverseSelectionModel(SelectCoarse));
      -}
      -
      -private IEnumerable<Symbol> SelectCoarse(IEnumerable<CoarseFundamental> coarse)
      -{
      -    // Return most liquid assets w/ fundamentals
      -    return coarse.Where(c => c.HasFundamentalData)
      -                 .OrderByDescending(c => c.DollarVolume)
      -                 .Take(100)
      -                 .Select(c => c.Symbol);
      -}
      -
      def Initialize(self) -> None:
      -    self.AddUniverseSelection(CoarseFundamentalUniverseSelectionModel(self.SelectCoarse))
      -
      -def SelectCoarse(self, coarse: List[CoarseFundamental]) -> List[Symbol]:
      -    selected = [c for c in coarse if c.HasFundamentalData]
      -    sorted_by_dollar_volume = sorted(selected, key=lambda c: c.DollarVolume, reverse=True)
      -    return [c.Symbol for c in sorted_by_dollar_volume[:100]] # Return most liquid assets w/ fundamentals
      -
      - -

      To move the coarse selection function outside of the algorithm class, create a universe selection model that inherits the CoarseFundamentalUniverseSelectionModel class.

      - -
      -
      // In Initialize
      -AddUniverseSelection(new MostLiquidFundamentalUniverseSelectionModel(UniverseSettings));
      -
      -// Outside of the algorithm class
      -class MostLiquidFundamentalUniverseSelectionModel : CoarseFundamentalUniverseSelectionModel
      -{
      -    public MostLiquidFundamentalUniverseSelectionModel(UniverseSettings universeSettings)
      -        : base(default(Func<IEnumerable<CoarseFundamental>, IEnumerable<Symbol>>), universeSettings)
      -    {
      -    }
      -
      -    public override IEnumerable<Symbol> SelectCoarse(QCAlgorithm algorithm, IEnumerable<CoarseFundamental> coarse)
      -    {
      -        return coarse.Where(c => c.HasFundamentalData)
      -                     .OrderByDescending(c => c.DollarVolume)
      -                     .Take(100)
      -                     .Select(c => c.Symbol);
      -    }
      -}
      -
      # In Initialize
      -self.AddUniverseSelection(MostLiquidFundamentalUniverseSelectionModel(self.UniverseSettings))
      -
      -# Outside of the algorithm class
      -class MostLiquidFundamentalUniverseSelectionModel(CoarseFundamentalUniverseSelectionModel):
      -    def __init__(self, universe_settings: UniverseSettings) -> None:
      -        super().__init__(self.SelectCoarse, universe_settings)
      -
      -    def SelectCoarse(self, coarse: List[CoarseFundamental]) -> List[Symbol]:
      -        selected = [c for c in coarse if c.HasFundamentalData]
      -        sorted_by_dollar_volume = sorted(selected, key=lambda c: c.DollarVolume, reverse=True)
      -        return [c.Symbol for c in sorted_by_dollar_volume[:100]]
      -
      - -

      To return the current universe constituents from the coarse selection function, return Universe.Unchanged.

      - -

      To view the implementation of this model, see the LEAN GitHub repository.

      diff --git a/08 Drafts/03 Writing Algorithms/34 Algorithm Framework/02 Universe Selection/09 Legacy Fundamental Universes/14 Fine Fundamental Selection.html b/08 Drafts/03 Writing Algorithms/34 Algorithm Framework/02 Universe Selection/09 Legacy Fundamental Universes/14 Fine Fundamental Selection.html deleted file mode 100644 index a744f8f8a4..0000000000 --- a/08 Drafts/03 Writing Algorithms/34 Algorithm Framework/02 Universe Selection/09 Legacy Fundamental Universes/14 Fine Fundamental Selection.html +++ /dev/null @@ -1,94 +0,0 @@ -

      The FineFundamentalUniverseSelectionModel selects assets based on CoarseFundamental and FineFundamental data. This is the only model that provides corporate fundamental data to your algorithm. To use this model, define a coarse selection function and a fine selection function. The coarse selection function receives a list of -CoarseFundamental objects and returns a list of Symbol objects. To filter the CoarseFundamental down to the securities that have fundamental data, add a HasFundamentalData filter to the coarse selection function. The fine selection function receives a subset of FineFundamental objects generated from coarse selection results and returns a list of Symbol objects. The Symbol objects you return from the fine selection function are the constituents of the universe.

      - -
      -
      public override void Initialize()
      -{
      -     AddUniverseSelection(new FineFundamentalUniverseSelectionModel(SelectCoarse, SelectFine));
      -}
      -
      -private IEnumerable<Symbol> SelectCoarse(IEnumerable<CoarseFundamental> coarse)
      -{
      -    // Return most liquid assets w/ fundamentals
      -    return coarse.Where(c => c.HasFundamentalData)
      -                 .OrderByDescending(c => c.DollarVolume)
      -                 .Take(100)
      -                 .Select(c => c.Symbol);
      -}
      -
      -private IEnumerable<Symbol> SelectFine(IEnumerable<FineFundamental> fine)
      -{
      -    // Return assets with lowest P/E ratios
      -    return fine.OrderBy(f => f.ValuationRatios.PERatio)
      -               .Take(10)
      -               .Select(f => f.Symbol);
      -}
      -
      -
      def Initialize(self) -> None:
      -    self.AddUniverseSelection(FineFundamentalUniverseSelectionModel(self.SelectCoarse, self.SelectFine))
      -
      -def SelectCoarse(self, coarse: List[CoarseFundamental]) -> List[Symbol]:
      -    selected = [c for c in coarse if c.HasFundamentalData]
      -    sorted_by_dollar_volume = sorted(selected, key=lambda c: c.DollarVolume, reverse=True)
      -    return [c.Symbol for c in sorted_by_dollar_volume[:100]] # Return most liquid assets w/ fundamentals
      -
      -def SelectFine(self, fine: List[FineFundamental]) -> List[Symbol]:
      -    sorted_by_pe_ratio = sorted(fine, key=lambda x: x.ValuationRatios.PERatio, reverse=False)
      -    return [c.Symbol for c in sorted_by_pe_ratio[:10]] # Return assets with lowest P/E ratios
      -
      - - -

      To move the selection functions outside of the algorithm class, create a universe selection model that inherits the FineFundamentalUniverseSelectionModel class.

      - -
      -
      // In Initialize
      -AddUniverseSelection(new LowPERatioUniverseSelectionModel(UniverseSettings));
      -
      -// Outside of the algorithm class
      -class LowPERatioUniverseSelectionModel : FineFundamentalUniverseSelectionModel
      -{
      -    public LowPERatioUniverseSelectionModel(UniverseSettings universeSettings = null)
      -        : base(default(Func<IEnumerable<CoarseFundamental>, IEnumerable<Symbol>>), 
      -               default(Func<IEnumerable<FineFundamental>, IEnumerable<Symbol>>),
      -               universeSettings)
      -    {
      -    }
      -
      -    public override IEnumerable<Symbol> SelectCoarse(QCAlgorithm algorithm, IEnumerable<CoarseFundamental> coarse)
      -    {
      -        return coarse.Where(c => c.HasFundamentalData)
      -                     .OrderByDescending(c => c.DollarVolume)
      -                     .Take(100)
      -                     .Select(c => c.Symbol);
      -    }
      -
      -    public override IEnumerable<Symbol> SelectFine(QCAlgorithm algorithm, IEnumerable<FineFundamental> fine)
      -    {
      -        return fine.OrderBy(f => f.ValuationRatios.PERatio)
      -                   .Take(10)
      -                   .Select(f => f.Symbol);
      -    }
      -}
      -
      # In Initialize
      -self.AddUniverseSelection(LowPERatioUniverseSelectionModel(self.UniverseSettings))
      -
      -# Outside of the algorithm class
      -class LowPERatioUniverseSelectionModel(FineFundamentalUniverseSelectionModel):
      -    def __init__(self, universe_settings: UniverseSettings = None) -> None:
      -        super().__init__(self.SelectCoarse, self.SelectFine, universe_settings)
      -
      -    def SelectCoarse(self, coarse: List[CoarseFundamental]) -> List[Symbol]:
      -        selected = [c for c in coarse if c.HasFundamentalData]
      -        sorted_by_dollar_volume = sorted(selected, key=lambda c: c.DollarVolume, reverse=True)
      -        return [c.Symbol for c in sorted_by_dollar_volume[:100]]
      -
      -    def SelectFine(self, fine: List[FineFundamental]) -> List[Symbol]:
      -        sorted_by_pe_ratio = sorted(fine, key=lambda x: x.ValuationRatios.PERatio, reverse=False)
      -        return [c.Symbol for c in sorted_by_pe_ratio[:10]]
      -
      - -

      To return the current universe constituents from the coarse or fine selection function, return Universe.Unchanged.

      - -

      If you add a FineFundamentalUniverseSelectionModel to your algorithm, you can access fundamental data in the fine selection function or from the Equity object. To access fundamental data from the Equity object, use the Equity.Fundamentals property.

      - -

      To view the implementation of this model, see the LEAN GitHub repository.

      diff --git a/08 Drafts/04 Research Environment/03 Datasets/06 Equity Fundamental Data/01 Introduction.html b/08 Drafts/04 Research Environment/03 Datasets/06 Equity Fundamental Data/01 Introduction.html deleted file mode 100644 index b75cc094ed..0000000000 --- a/08 Drafts/04 Research Environment/03 Datasets/06 Equity Fundamental Data/01 Introduction.html +++ /dev/null @@ -1 +0,0 @@ -

      This page explains how to request, manipulate, and visualize historical Equity Fundamental data. Corporate fundamental data is available through the US Fundamental Data from Morningstar.

      diff --git a/08 Drafts/04 Research Environment/03 Datasets/06 Equity Fundamental Data/04 Get Historical Data.html b/08 Drafts/04 Research Environment/03 Datasets/06 Equity Fundamental Data/04 Get Historical Data.html deleted file mode 100644 index 7567d070c9..0000000000 --- a/08 Drafts/04 Research Environment/03 Datasets/06 Equity Fundamental Data/04 Get Historical Data.html +++ /dev/null @@ -1,112 +0,0 @@ -

      - You need a subscription before you can request historical fundamental data for US Equities. - On the time dimension, you can request an amount of historical data based on a trailing number of bars, a trailing period of time, or a defined period of time. - On the security dimension, you can request historical data for a single US Equity, a set of US Equities, or all of the US Equities in the US Fundamental dataset. - On the property dimension, you can call the History method to get all fundamental properties or you can call the GetFundamental method to get a specific property (for example, the price–earnings ratio). -

      - -

      - When you call the History method, you can request Fundamental or Fundamentals objects. - If you use Fundamental, the method returns all fundamental properties for the Symbol object(s) you provide. - If you use Fundamentals, the method returns all fundamental properties for all the US Equities in the US Fundamental dataset that were trading during that time period you request, including companies that no longer trade. -

      - -

      Trailing Number of Trading Days

      -

      To get historical data for a number of trailing trading days, call the History method with the number of trading days. If you didn't use Resolution.Daily when you subscribed to the US Equities, pass it as the last argument to the History method.

      -
      -
      // Fundamental objects
      -var singleFundamentalHistory = qb.History<Fundamental>(symbols.First(), 10);
      -var setFundamentalHistory = qb.History<Fundamental>(symbols, 10);
      -var allFundamentalHistory = qb.History<Fundamental>(qb.Securities.Keys, 10);
      -    
      -// Fundamentals objects
      -var allFundamentalsHistory = qb.History<Fundamentals>(qb.Securities.Keys, 10);
      -
      # DataFrame of fundamental data
      -single_fundamental_df = qb.History(Fundamental, symbols[0], 10)
      -set_fundamental_df = qb.History(Fundamental, symbols, 10)
      -all_fundamental_df = qb.History(Fundamental, qb.Securities.Keys, 10)
      -
      -# Fundamental objects
      -single_fundamental_history = qb.History[Fundamental](symbols[0], 10)
      -set_fundamental_history = qb.History[Fundamental](symbols, 10)
      -all_fundamental_history = qb.History[Fundamental](qb.Securities.Keys, 10)
      -
      -# Fundamentals objects
      -all_fundamentals_history = qb.History[Fundamentals](qb.Securities.Keys, 10)
      -
      -

      The preceding calls return fundamental data for the 10 most recent trading days.

      - -

      Trailing Period of Time

      -

      To get historical data for a trailing period of time, call the History method with a TimeSpantimedelta object.

      - -
      -
      // Fundamental objects
      -var singleFundamentalHistory = qb.History<Fundamental>(symbols.First(), TimeSpan.FromDays(10));
      -var setFundamentalHistory = qb.History<Fundamental>(symbols, TimeSpan.FromDays(10));
      -var allFundamentalHistory = qb.History<Fundamental>(qb.Securities.Keys, TimeSpan.FromDays(10));
      -    
      -// Fundamentals objects
      -var allFundamentalsHistory = qb.History<Fundamentals>(TimeSpan.FromDays(10));
      -
      # DataFrame of fundamental data
      -single_fundamental_df = qb.History(Fundamental, symbols[0], timedelta(days=10))
      -set_fundamental_df = qb.History(Fundamental, symbols, timedelta(days=10))
      -all_fundamental_df = qb.History(Fundamental, qb.Securities.Keys, timedelta(days=10))
      -
      -# Fundamental objects
      -single_fundamental_history = qb.History[Fundamental](symbols[0], timedelta(days=10))
      -set_fundamental_history = qb.History[Fundamental](symbols, timedelta(days=10))
      -all_fundamental_history = qb.History[Fundamental](qb.Securities.Keys, timedelta(days=10))
      -
      -# Fundamentals objects
      -all_fundamentals_history = qb.History[Fundamentals](timedelta(days=10))
      -
      -

      The preceding calls return fundamental data for the most recent trading days.

      - -

      Defined Period of Time

      -

      - To get the historical data of all the fundamental properties over specific period of time, call the History method with a start DateTimedatetime and an end DateTimedatetime. - To get the historical data of a single fundamental property over a specific period of time, call the GetFundamental method and include the name of a fundamental property. - To view the possible fundamental properties, see the Fundamental attributes in Data Point Attributes. - The start and end times you provide to these methods are based in the notebook time zone. -

      - -
      -
      var startDate = new DateTime(2021, 1, 1);
      -var endDate = new DateTime(2021, 2, 1);
      -
      -// Fundamental objects
      -var singleFundamentalHistory = qb.History<Fundamental>(symbols.First(), startDate, endDate);
      -var setFundamentalHistory = qb.History<Fundamental>(symbols, startDate, endDate);
      -var allFundamentalHistory = qb.History<Fundamental>(qb.Securities.Keys, startDate, endDate);
      -    
      -// Fundamentals objects
      -var allFundamentalsHistory = qb.History<Fundamentals>(qb.Securities.Keys, startDate, endDate);
      -
      -// DataDictionary objects
      -var singleOneAttributeHistory = qb.GetFundamental(symbols.First(), "ValuationRatios.PERatio", startDate, endDate);
      -var setOneAttributeHistory = qb.GetFundamental(symbols, "ValuationRatios.PERatio", startDate, endDate);
      -var allOneAttributeHistory = qb.GetFundamental(qb.Securities.Keys, "ValuationRatios.PERatio", startDate, endDate);
      -
      start_date = datetime(2021, 1, 1)
      -end_date = datetime(2021, 2, 1)
      -
      -# DataFrame of all fundamental properties
      -single_fundamental_df = qb.History(Fundamental, symbols[0], start_date, end_date)
      -set_fundamental_df = qb.History(Fundamental, symbols, start_date, end_date)
      -all_fundamental_df = qb.History(Fundamental, qb.Securities.Keys, start_date, end_date)
      -
      -# DataFrame of a fundamental property
      -single_one_attribute_df = qb.GetFundamental(symbols[0], "ValuationRatios.PERatio", start_date, end_date)
      -set_one_attribute_df = qb.GetFundamental(symbols, "ValuationRatios.PERatio", start_date, end_date)
      -all_one_attribute_df = qb.GetFundamental(qb.Securities.Keys, "ValuationRatios.PERatio", start_date, end_date)
      -
      -# Fundamental objects
      -single_fundamental_history = qb.History[Fundamental](symbols[0], start_date, end_date)
      -set_fundamental_history = qb.History[Fundamental](symbols, start_date, end_date)
      -all_fundamental_history = qb.History[Fundamental](qb.Securities.Keys, start_date, end_date)
      -
      -# Fundamentals objects
      -all_fundamentals_history = qb.History[Fundamentals](qb.Securities.Keys, start_date, end_date)
      -
      - -

      The preceding method returns the fundamental property values that are timestamped within the defined period of time.

      - diff --git a/08 Drafts/04 Research Environment/03 Datasets/06 Equity Fundamental Data/05 Wrangle Data.html b/08 Drafts/04 Research Environment/03 Datasets/06 Equity Fundamental Data/05 Wrangle Data.html deleted file mode 100644 index 0c40523f70..0000000000 --- a/08 Drafts/04 Research Environment/03 Datasets/06 Equity Fundamental Data/05 Wrangle Data.html +++ /dev/null @@ -1,109 +0,0 @@ -

      You need some historical data to perform wrangling operations. To display pandas objects, run a cell in a notebook with the pandas object as the last line. To display other data formats, call the print method.

      -

      You need some historical data to perform wrangling operations. Use LINQ to wrangle the data and then call the Console.WriteLine method in a Jupyter Notebook to display the data.

      - -

      DataFrame Objects

      -

      The History method returns a multi-index DataFrame where the first level is the Equity Symbol and the second level is the EndTime of the trading day. The columns of the DataFrame are the names of the fundamental properties. The following image shows the first 4 columns of an example DataFrame:

      -Historical fundamental properties dataframe for US Equities - -

      The GetFundamental method returns a DataFrame where the index is the EndTime of the trading day. The columns of the DataFrame are the Equity Symbol objects.

      -Historical PE ratio of US Equities -

      To select the historical data of a single Equity in the preceding DataFrame, index it with the Equity Symbol. Each history slice may not have data for all of your Equity subscriptions. To avoid issues, check if it contains data for your Equity before you index it with the Equity Symbol.

      -
      -
      all_one_attribute_df[symbols[1]]
      -
      -Historical PE ratio of a single symbol - -

      Fundamental Objects

      -

      If you pass a Symbol to the History[Fundamental]History<Fundamental> method, run the following code to get the fundamental properties over time:

      -
      -
      for fundamental in single_fundamental_history:
      -    symbol = fundamental.Symbol
      -    end_time = fundamental.EndTime
      -    pe_ratio = fundamental.ValuationRatios.PERatio
      -
      foreach (var fundamental in singleFundamentalHistory) // Iterate trading days
      -{
      -    var endTime = fundamental.EndTime;
      -    var peRatio = fundamental.ValuationRatios.PERatio;
      -}
      -
      - -

      If you pass a list of Symbol objects to the History[Fundamental]History<Fundamental> method, run the following code to get the fundamental properties over time:

      -
      -
      for fundamental_dict in set_fundamental_history: # Iterate trading days
      -    for symbol, fundamental in fundamental_dict.items(): # Iterate Symbols
      -        end_time = fundamental.EndTime
      -        pe_ratio = fundamental.ValuationRatios.PERatio
      -
      foreach (var fundamentalDict in setFundamentalHistory) // Iterate trading days
      -{
      -    foreach (var kvp in fundamentalDict) // Iterate Symbols
      -    {
      -        var symbol = kvp.Key;
      -        var fundamental = kvp.Value;
      -        var endTime = fundamental.EndTime;
      -        var peRatio = fundamental.ValuationRatios.PERatio;
      -    }
      -}
      -
      - -

      Fundamentals Objects

      -

      If you request all fundamental properties for all US Equities with the History[Fundamentals]History<Fundamentals> method, run the following code to get the fundamental properties over time:

      -
      -
      for fundamentals_dict in all_fundamentals_history: # Iterate trading days
      -    fundamentals = list(fundamentals_dict.Values)[0]
      -    end_time = fundamentals.EndTime
      -    for fundamental in fundamentals.Data: # Iterate Symbols
      -        if not fundamental.HasFundamentalData:
      -            continue
      -        symbol = fundamental.Symbol
      -        pe_ratio = fundamental.ValuationRatios.PERatio
      -
      foreach (var fundamentalsDict in allFundamentalsHistory) // Iterate trading days
      -{
      -    var fundamentals = fundamentalsDict.Values.First().Data;
      -    foreach (Fundamental fundamental in fundamentals) // Iterate Symbols
      -    {
      -        if (!fundamental.HasFundamentalData)
      -        {
      -            continue;
      -        }
      -        var endTime = fundamental.EndTime;
      -        var symbol = fundamental.Symbol;
      -        var peRatio = fundamental.ValuationRatios.PERatio;
      -    }
      -}
      -
      - -

      DataDictionary Objects

      -

      To get the fundamental data points for each Equity, iterate through the history request result.

      -
      -
      foreach (var slice in allOneAttributeHistory)
      -{
      -    var endTime = slice.Time;
      -    foreach (var symbol in symbols)
      -    {
      -        if (slice.ContainsKey(symbol))
      -        {
      -            var peRatio = slice[symbol];
      -        }
      -    }
      -}
      -
      - -

      You can also iterate through each data point in the slice.

      -
      -
      foreach (var slice in allOneAttributeHistory)
      -{
      -    var endTime = slice.Time;
      -    foreach (var kvp in slice)
      -    {
      -        var symbol = kvp.Key;
      -        var peRatio = kvp.Value;
      -    }
      -}
      -
      - -

      You can also use LINQ to select the historical data points.

      - -
      -
      var symbol = symbols.Last();
      -var values = allOneAttributeHistory.Select(slice => slice[symbol]);
      -
      diff --git a/08 Drafts/04 Research Environment/03 Datasets/06 Equity Fundamental Data/06 Plot Data.html b/08 Drafts/04 Research Environment/03 Datasets/06 Equity Fundamental Data/06 Plot Data.html deleted file mode 100644 index cff3e9def5..0000000000 --- a/08 Drafts/04 Research Environment/03 Datasets/06 Equity Fundamental Data/06 Plot Data.html +++ /dev/null @@ -1,67 +0,0 @@ -

      You need some historical Equity fundamental data to produce plots. You can use many of the supported plotting librariesPlot.NET package to visualize data in various formats. For example, you can plot line charts.

      - -

      Follow these steps to plot line charts using built-in methodsPlotly.NET package:

      - -
        -
      1. Get some historical data.
      2. -
        -
        var history = qb.GetFundamental(symbols, "ValuationRatios.PERatio", new DateTime(2014, 1, 1), new DateTime(2015, 1, 1));
        -
        history = qb.GetFundamental(symbols, "ValuationRatios.PERatio", datetime(2014, 1, 1), datetime(2015, 1, 1))
        -
        - -
      3. Load the Plotly.NET package.
      4. -
        -
        #r "../Plotly.NET.dll"
        -#r "../Plotly.NET.Interactive.dll"
        -
        -using Plotly.NET;
        -using Plotly.NET.Interactive;
        -using Plotly.NET.LayoutObjects;
        -
        - -
      5. Create Line objects for each Symbol.
      6. -
        -
        var charts = symbols.Select(
        -    symbol => Chart2D.Chart.Line<DateTime, decimal, string>(
        -        history.Select(x => (DateTime)x.Time),
        -        history.Select(x => (decimal)x[symbol]),
        -        Name: symbol.Value
        -    )
        -);
        -
        - -
      7. Create a Layout.
      8. -
        -
        LinearAxis xAxis = new LinearAxis();
        -xAxis.SetValue("title", "Time");
        -LinearAxis yAxis = new LinearAxis();
        -yAxis.SetValue("title", "PE Ratio");
        -Title title = Title.init("PE Ratios Over Time");
        -
        -Layout layout = new Layout();
        -layout.SetValue("xaxis", xAxis);
        -layout.SetValue("yaxis", yAxis);
        -layout.SetValue("title", title);
        -
        - -
      9. Combine the charts and assign the Layout to the chart.
      10. -
        -
        var chart = Plotly.NET.Chart.Combine(charts);
        -chart.WithLayout(layout);
        -
        - -
      11. Call the plot method on the history DataFrame.
      12. -
        -
        history.plot(title='PE Ratio Over Time', figsize=(15, 8))
        -
        - -
      13. Show the plot.
      14. -
        -
        plt.show()
        -
        HTML(GenericChart.toChartHTML(chart))
        -
        -

        Line charts display the value of the property you selected in a time series.

        -
      - -Line plot of PE ratio of US Equities -Line plot of PE ratio of US Equities diff --git a/08 Drafts/04 Research Environment/03 Datasets/06 Equity Fundamental Data/metadata.json b/08 Drafts/04 Research Environment/03 Datasets/06 Equity Fundamental Data/metadata.json deleted file mode 100644 index 00bef67a8c..0000000000 --- a/08 Drafts/04 Research Environment/03 Datasets/06 Equity Fundamental Data/metadata.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "type": "metadata", - "values": { - "description": "Learn how to request and handle equity fundamental data in the research environment in QuantConnect", - "keywords": "algorithmic trading, research, research environment, jupyter notebook, datasets, equity fundamental data", - "og:description": "Learn how to request and handle equity fundamental data in the research environment in QuantConnect", - "og:title": "Equity Fundamental Data - Documentation QuantConnect.com", - "og:type": "website", - "og:site_name": "Equity Fundamental Data - QuantConnect.com", - "og:image": "https://cdn.quantconnect.com/docs/i/research-environment/datasets/equity-fundamental-data.png" - } -} diff --git a/Resources/algorithm-framework/universe-settings.php b/Resources/algorithm-framework/universe-settings.php index e3a7e58764..b0fd6ef081 100644 --- a/Resources/algorithm-framework/universe-settings.php +++ b/Resources/algorithm-framework/universe-settings.php @@ -82,9 +82,9 @@
      // Request second resolution data. This will be slow!
       UniverseSettings.Resolution = Resolution.Second;
      -AddUniverse(MyCoarseFilterFunction);
      +AddUniverse(MyFundamentalFilterFunction);
    # Request second resolution data. This will be slow!
     self.UniverseSettings.Resolution = Resolution.Second
    -self.AddUniverse(self.MyCoarseFilterFunction)
    +self.AddUniverse(self.MyFundamentalFilterFunction)
    \ No newline at end of file diff --git a/Resources/data-feeds/universe-selection.php b/Resources/data-feeds/universe-selection.php index 63aa954bde..20790886c9 100644 --- a/Resources/data-feeds/universe-selection.php +++ b/Resources/data-feeds/universe-selection.php @@ -1,16 +1,6 @@ -Universe selection is"; - if (!$availability) { - echo "n't"; - } - echo " available with the $dataFeedName data feed.

    "; - if ($availability) - { - echo "
    -
    AddUniverse(CoarseUniverseSelection, FineUniverseSelection);
    -
    self.AddUniverse(self.CoarseUniverseSelection, self.FineUniverseSelection)
    -
    "; - } -} -?> +

    Universe selection available with the data feed.

    + +
    +
    AddUniverse(FundamentalUniverseSelection);
    +
    self.AddUniverse(self.FundamentalUniverseSelection)
    +
    \ No newline at end of file diff --git a/Resources/data-feeds/us-equities/coarse-fine-data-availability.html b/Resources/data-feeds/us-equities/coarse-fine-data-availability.html deleted file mode 100644 index 185fa8a403..0000000000 --- a/Resources/data-feeds/us-equities/coarse-fine-data-availability.html +++ /dev/null @@ -1,2 +0,0 @@ - -

    The live data for coarse and fine universe selection arrives at 7 AM Eastern Time (ET), so coarse and fine universe selection runs for live algorithms between 7 and 8 AM ET. This timing allows you to place trades before the market opens. Don't schedule anything for midnight because the universe selection data isn't ready yet.

    diff --git a/08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/02 Fundamental Universes/11 Live Trading Considerations.html b/Resources/data-feeds/us-equities/fundamental-data-availability.html similarity index 97% rename from 08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/02 Fundamental Universes/11 Live Trading Considerations.html rename to Resources/data-feeds/us-equities/fundamental-data-availability.html index 3455c5f71e..af7600b040 100644 --- a/08 Drafts/03 Writing Algorithms/12 Universes/03 Equity/02 Fundamental Universes/11 Live Trading Considerations.html +++ b/Resources/data-feeds/us-equities/fundamental-data-availability.html @@ -1 +1 @@ -

    The live data for fundamental universe selection arrives at 6/7 AM Eastern Time (ET), so fundamental universe selection runs for live algorithms between 7 and 8 AM ET. This timing allows you to place trades before the market opens. Don't schedule anything for midnight because the universe selection data isn't ready yet.

    +

    The live data for fundamental universe selection arrives at 6/7 AM Eastern Time (ET), so fundamental universe selection runs for live algorithms between 7 and 8 AM ET. This timing allows you to place trades before the market opens. Don't schedule anything for midnight because the universe selection data isn't ready yet.

    \ No newline at end of file