Hi there:)
I need some help adding fundamentals and technical indicators in the same algorithm. Ive been trying for a couple days now and have made no headway. I know i need a universe, but i was wondering if there was any way i could get the PE Ratio for a certain predetermined list of stocks, and then buy them if the PE RATIO is good and the MACD crosses.
Sorry, glitchy computer wont let me add a backtest … here's the code:
Thanks for any help ! :)
#region imports
from AlgorithmImports import *
#endregion
class VerticalQuantumInterceptor(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2019, 7, 12)# Set Start Date
self.SetEndDate(2019, 7, 16)
self.SetCash(100000) # Set Strategy Cash
resolution = Resolution.Daily
self.UniverseSettings.Resolution = resolution
self.symbols = [self.AddEquity(x, resolution).Symbol
for x in ["X", "F", "JPM"]]
self.AddUniverse(self.CoarseSelection, self.FineSelection)
self.macd = self.MACD(self.symbols, 12, 26, 9, Resolution.Daily)
def CoarseSelection(self, coarse):
return self.symbols
def FineSelection(self, fine):
return [x.Symbol for x in fine]
fine = [x for x in fine if x.ValuationRatios.PBRatio > 0]
sortedPBRatio = sorted(fine, key=lambda x: x.ValuationRatios.PBRatio)
return self.symbols
def OnData(self, data):
if self.Portfolio[self.symbols].Quantity == 0:
if x.ValuationRatios.PBRatio < 1:
if self.macd.Current.Value > self.macd.Signal.Current.Value:
self.SetHoldings(self.symbols, .1)
Vladimir
Try this way.
If you are satisfied with my answer, please accept it and don't forget to like it.
Christian Olsen
yes!!! thank you vladimir!
Christian Olsen
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.
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!