# copt rsi2_nodef*.pyd and rsi2_def*.pyd generated by compiling pyx files to this local directory

import pandas as pd
import mdata
import ta.indicators as indi
import time
import rsi2_nodef
import rsi2_def

if __name__ == "__main__":
    ticker = 'SPY'
    PX = mdata.loadcsv()
    PX['close'] = PX['close'].round(2)
    RSI_PERIOD = 2
    MA_LONG_PERIOD = 200
    MA_SHORT_PERIOD = 5
    RSI_N = indi.rsi(PX['close'], RSI_PERIOD)
    MA_LONG = indi.sma(PX['close'], MA_LONG_PERIOD)
    MA_SHORT = indi.sma(PX['close'], MA_SHORT_PERIOD)
    STARTING_CAPITAL = 10_000.0

    CLOSE = PX['close'].round(2).tolist()
    MA_LONG = MA_LONG.tolist()
    MA_SHORT = MA_SHORT.tolist()
    RSI_N = RSI_N.tolist()
    SIX = 199
    POSN = len(CLOSE) * [0]
    CASH = len(CLOSE) * [STARTING_CAPITAL]

    DATA = pd.DataFrame([CLOSE, MA_LONG, MA_SHORT, RSI_N]).transpose()
    DATA.columns = ['close', 'ma_long', 'ma_short', 'rsi']

    ST_TM = time.time()
    for IX in range(0, 100):
        rsi2_nodef.run_strategy(CLOSE, MA_LONG, MA_SHORT, RSI_N, 20.0, SIX, POSN, CASH)
    ED_TM = time.time()
    TM = (ED_TM - ST_TM) / 100
    print("Time in seconds for run_strategy: {}".format(str(TM)))

    ST_TM = time.time()
    for IX in range(0, 100):
        rsi2_nodef.run_strategy_df(DATA, 20.0, SIX, POSN, CASH)
    ED_TM = time.time()
    TM = (ED_TM - ST_TM) / 100
    print("Time in seconds for run_strategy: {}".format(str(TM)))

    ST_TM = time.time()
    for IX in range(0, 100):
        rsi2_def.run_strategy(CLOSE, MA_LONG, MA_SHORT, RSI_N, 20.0, SIX, POSN, CASH)
    ED_TM = time.time()
    TM = (ED_TM - ST_TM) / 100
    print("Time in seconds for run_strategy: {}".format(str(TM)))
