Posts

Finding Bugs in my Technical Analysis Code

avatar of @chasmic-cosm
25
@chasmic-cosm
·
·
0 views
·
2 min read

Why have I not posted more technical analysis lately?

It's been ages since my last post about my #trading #bot. My next post was supposed to be about the calculation of the Aroon Indicator, but I'm delaying the post after discovering a problem with my calculation (and because work has been super busy), so I thought it might by worth making a post about the problems instead of just posting once I get it right.

Benefit of posting on #hive

By posting the details of my development process on hive, I've forced myself to examine my results more closely. In doing so, I managed to pick up a problem with my aroon_indicator function that wasn't covered by my unit tests. I have no doubt the problem is actually trivial, I just haven't put the time in to figure it out yet.

The Code

import numpy as np 
 
def aroon_indicator(signal, period=25, shift=0): 
    """ 
    Calculate the Aroon indicator for a signal 
    Inputs: 
        signal: numpy array -   A sequence of price points in time 
        period: int 
        shift:  int         -   The amount to shift the up line by 
    Outputs: 
        aroon_up:   numpy array -   The Aroon up line 
        aroon_down: numpy array -   The Aroon down line 
        aroon_osc:  numpy array -   The Aroon oscillator signal 
    """ 
    aroon_up = np.zeros(len(signal)) 
    aroon_down = np.zeros(len(signal)) 
    high = 0 
    low = 0 
    for i in range(1, len(signal)): 
        if signal[i] >= signal[high]: 
            high = i 
        if signal[i] <= signal[low]: 
            low = i 
        aroon_up[i] = 100 <em> (period - (i - high)) / period 
        aroon_down[i] = 100 </em> (period - (i - low)) / period 
    shift_array = np.ones(len(signal)) * shift 
    aroon_osc = ((aroon_up +  shift_array) - aroon_down) - shift_array 
    return aroon_up, aroon_down, aroon_osc 

Posted Using LeoFinance