Hi,
I'm trying to implement a simple recursive calculation in Python that uses the reduce() function however I get an error message: “Runtime Error: NameError : name 'reduce' is not defined”.
I can't import functools module either because I get an error.
The specific code I need is:
#Lineal Deviation Calculation
reduce(lambda a,b:a+abs(avg-b),list,0)/len(list)
where avg=sum(list)/len(list)
Thanks for any help,
Andres
Vladimir
Andres Arizpe,
Try this
Spacetime
Hi Andres Arizpe ,
Please take a look at the attached notebook with couple of examples shown. Also, image of the notebook is shown below.
I am able to import functools module and use reduce() function.
Please let us know if there further questions.
Spacetime
Hi Andres Arizpe ,
Also please note, you have to use functools.reduce() and not just reduce() by itself in notebook.
Vladimir
Andres Arizpe,
This is your indicator calculated based on the SPY closing price.
Andres Arizpe
You guys are awesome!
Thanks for the feedback.
Cheers,
AA
Vladimir
Andres Arizpe,
If you multiply your indicator by sqrt (252) and normalize it to the last closing price,
it behaves very similarly to volatility indicators.
Andres Arizpe
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!