Back to Community
Stochastic Oscillator -- Need quick help printing values ( Corrected)

Hello,

My name is Mark and i'd like to first thank Quantopian and the community for helping each other tackle programming problems. It'd be almost impossible trying to fiqure these questions out on your own.

I was wondering how would you print the values the talib.STOCH( ) is producing/calculating in the background. I would like to see the exact numbers if possible. This is a stochatic oscillator. I did not use the slowk_period or slowd period but that's not the problem

When using the fastk oscillator (original) formula the output numbers should come out to be 10 ,24 , 25, 76, 100 < - these are just examples

When i printed the fastk values.. i got NaN in return..

Is there anyway to print the exact numbers ( i'd like to see whats going on in the background. )

Here is the real code i've been working with

Clone Algorithm
13
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 591e03d6426b7361a5af0651
There was a runtime error.
4 responses

Mark,
This should work.

# stochastic fast indicator 

import talib

def initialize(context):  
    schedule_function(stochastic_fast_indicator, date_rules.every_day(), time_rules.market_open(minutes=10))  
def stochastic_fast_indicator(context, data):  
    stk = symbol('SPY')  
    fk, fd = 14, 1  
    bars = fk + fd  
    H = data.history(stk, 'high', bars, '1d')  
    L = data.history(stk, 'low', bars, '1d')  
    C = data.history(stk, 'price', bars, '1d')

    fastk, fastd = talib.STOCHF(H,L,C,fk,fd)  
    print fastk[-1]  
    record(fastk = fastk[-1])  

Vladimir,

Sorry for the late response. Thanks a lot this saved me a lot of time. I really appreciate it.

I might have another question soon. Im trying to calculated the percent change using the fastk values. I'm having some trouble de bugging the code. I'll post it soon if anything

Can anyone help me create Stochastic Oscillator on soybean oil 2nd continuous contract month futures trading with high low close data in 15-minute trading parameter plus the stop and reverse trades with minimum 1 lot? Many thanks.

CP YEOH i can try to do this for you during the school year ( So i can start next month ) if everything works out. Whats the best way to reach out to you?