LEAN is the open source
algorithmic trading engine powering QuantConnect. Founded in 2013 LEAN has been built by a
global community of 80+ engineers and powers more than a dozen hedge funds today.
Alpha League Competition: $1,000 Weekly Prize Pool
Qualifying Alpha Streams Reentered Weekly Learn
more
In the QuantConnect Research notebook, I used qb.GetFundamental to get the fundamental data for a list of stocks. But in the algorithm framework, it looks like we can only get those data as a FineFundamental object, and I guess the data which comes from as a FineFundamental object is set to be the newest data? (For example, if I do
x.ValuationRatios.PERatio in where x is a FineFundamental object, then the peRaio would be the newest one, not the historical data that I'm looking for)
Is there any way we can get a dataframe of historical fundamental data just like the Research notebook(the attached screenshot)?
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Currently we don’t support direct access to historical fundamental data. However, we could implement Rolling Window to store and use fundamental data.
Here is an example using the average PE ratio in past 90 days for fine selection. We build a rolling window for each symbol with a size of 90. Everyday we add the newest PE ratio into the rolling window, and take the average of the rolling window. Notice that in the first 90 days, the rolling window is not filled, so the average is taken from the start date to the current date (you cannot access data before start date). After 90 days, the rolling window only contains data from the most recent 90 days, and works as expected. You might find more help about rolling window here.
You can always change the size of rolling window and the way it is updated for your own purpose. In addition, we are working on historical fundamental data access support. Hope it helps!
class OptimizedHorizontalCoreWave(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2018, 10, 11) # Set Start Date
self.SetEndDate(2019, 10, 10) # Set End Date
self.SetCash(100000) # Set Strategy Cash
self.SetUniverseSelection(FineFundamentalUniverseSelectionModel(self.CoarseSelectionFunction, self.FineSelectionFunction, None, None))
self.historicalPERatio = {}
self.historicalPERatioAverage = {}
self.rollingWindowSize = 90;
# sort the data by daily dollar volume and take the top 'NumberOfSymbols'
def CoarseSelectionFunction(self, coarse):
# sort descending by daily dollar volume
sortedByDollarVolume = sorted(coarse, key=lambda x: x.DollarVolume, reverse=True)
# return the symbol objects of the top entries from our sorted collection
return [ x.Symbol for x in sortedByDollarVolume[:1000] ]
# sort the data by P/E ratio and take the top 'NumberOfSymbolsFine'
def FineSelectionFunction(self, fine):
for x in fine:
if x.Symbol not in self.historicalPERatio.keys():
# Set up rolling window for new ticker
self.historicalPERatio[x.Symbol] = RollingWindow[Decimal](self.rollingWindowSize)
# Add PERatio to rolling window
self.historicalPERatio[x.Symbol].Add(x.ValuationRatios.PERatio)
# Take average of RW
average = 0.0
for pe in self.historicalPERatio[x.Symbol]:
average += pe
average /= self.historicalPERatio[x.Symbol].Count
self.historicalPERatioAverage[x.Symbol] = average
# sort descending by average P/E ratio
sortedByPeRatio = sorted(fine, key=lambda x: self.historicalPERatioAverage[x.Symbol], reverse=True)
# take the top 5 entries from our sorted collection
return [ x.Symbol for x in sortedByPeRatio[:5] ]
0
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Loading...
To unlock posting to the community forums please complete at least 30% of Boot Camp. You can
continue your Boot Camp training progress from the
terminal. We hope to see you in the community soon!
You do not have enough QC Credit to send this award, get a QC Credit Pack
here.
Award Sent Successfully
Thank you for giving back to the community.
Processing...
Choose a Credit Pack
Payment Confirmation
QuantConnect Credit (QCC) can be applied to your cloud-invoices or
gifted to others in the community with Community Awards in recognition of their contributions.
Community Awards highlight the awesome work your fellow community members are doing and inspires
high quality algorithm contributions to the community. Select an option below to add
QuantConnect Credit to your account:
$5
500 Credit Points
 
$10
1,000 Credit Points
 
$18
2,000 Credit Points
10% bonus
$45
5,000 Credit Points
10% bonus
03/23XXXX XXXX XXXX 0592
We will charge your default organization credit card on file, click
here to update.