Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
How do I get Slow Stochastic result from FastStochasticOscillator Factor

I Am trying to get the slow stochastic (Simple moving average) from the FastStochasticOscillator Factor.
When I put the Fast Stochastic result in the SimpleMovingAverage factor I get the following error.

ValueError: FastStochasticOscillator does not have multiple outputs.

How do I get multiple outputs from the FastStochasticOscillator Factor?

Thanks

6 responses

@Ted.
Try this:

slow_stoch = SimpleMovingAverage(inputs=[stoch], window_length=4)  

Vladimir:
Thanks so much for answering my question. Adding the brackets around the stoch variable did the trick.

I am guessing that the brackets make it a pointer. Is that true?

Just another rookie,
Ted

In this case, the brackets mean the parameter is a list (see the python docs). The 'inputs' parameter can include more than one dataset or factor. They are passed as a list to accommodate this. A subtle clue is that the parameter name is plural (ie inputs).

One often sees an error message like TypeError: 'int' object is not iterable. This typically implies a list is expected rather than a single value. Putting brackets around the variable will usually fix it. Unfortunately, in this case the error message was rather cryptic (ValueError: FastStochasticOscillator does not have multiple outputs.).

Disclaimer

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 Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian 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.

Dan:
Thanks for the explanation.

Ted

One more question: this is about calculating the slow stochastic %K.
How can one determine the slow stochastic %D?

I thought this would be simply something like this:
fast_stoch = FastStochasticOscillator(window_length=14)
slow_stoch_k = SimpleMovingAverage(inputs=[fast_stoch], window_length=3)
slow_stoch_d = SimpleMovingAverage(inputs=[slow_stoch_k], window_length=3)

Determining slow_stoch_k works fine but determining slow_stoch_d gives the error:
NonWindowSafeInput: Can't compute windowed expression SimpleMovingAverage([SimpleMovingAverage(...)], 3) with windowed input SimpleMovingAverage([FastStochasticOscillator(...)], 3).

I suppose this cannot be solved by using the built in function SimpleMovingAverage?
For this you have to write your own simple moving average?

Ber:
I believe you are correct. You will have to calculate the slow_stoch_d by calculating multiple slow_stoch_k's, This what I did. There may be a better way but I did not find it.

Ted