Hello guys, I want to know how can create a custom factor on LEAN, the next example is extracted from my Quantopian code:
from quantopian.pipeline import CustomFilter
import numpy as np
from quantopian.pipeline.data import USEquityPricing
class fibopoint(CustomFilter):
inputs = [USEquityPricing.low, USEquityPricing.high, USEquityPricing.close]
window_length = 21
def compute(self, today, assets, out, low, high, close):
dayshigh20 = np.max(high, axis=0)
dayslow20 = np.min(low, axis=0)
mid_price = (high[-1]+low[-1])/2
fiboprice2 = dayshigh20 - (.50*(dayshigh20-dayslow20))
cond = (np.argmax(dayshigh20, axis=0) - np.argmin(dayslow20, axis=0))>0
fibocondition_2 =mid_price >= fiboprice2
result1 = fibocondition_2 & cond & (high[-1]<= (dayshigh20 - (.10*(dayshigh20-dayslow20))))
out[:] = result1
Thanks a lot!
Aaron Janeiro Stone
An equivalent to factors should be the Coarse selection for universes:
https://www.quantconnect.com/docs/algorithm-reference/universes#Universes-Coarse-Universe-SelectionAll incoming tickers will pass through the fine/coarse selection filters that you define, leaving you with a universe of all equities meeting your conditions. Prices can be retreived a few different way. For example, self.Securities["{tickername}"].{Close/Open/High/Low}, where {} would be the input of your choosing.
For a list of some interesting fundementals other than price, see:
https://www.quantconnect.com/docs/data-library/fundamentalsRene Ordosgoitia
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!