Created
April 18, 2023 02:46
-
-
Save shmalex/13d51a5eba94360a6d3b3e96dfb18366 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import numpy as np | |
import math | |
from matplotlib import pyplot as plt | |
# data file should have one column with price data | |
df = pd.read_csv('../data/ninja-trade/data.txt') | |
col = 'close' | |
period = 9 | |
fishPrev = 0 | |
tmpValuePrev = 0 | |
Value = [] | |
tmpSeries = [] | |
for i, v in enumerate(df[col]): | |
if i > 0: | |
fishPrev = Value[-1] | |
tmpValuePrev = tmpSeries[-1] | |
min = df[col].iloc[i-period:i+1].min() | |
max = df[col].iloc[i-period:i+1].max() | |
if np.isnan(max): | |
if i == 0: | |
min = v | |
max = v | |
else: | |
min = df[col].iloc[:i+1].min() | |
max = df[col].iloc[:i+1].max() | |
minLo = min | |
num1 = max - minLo | |
if num1<0.01: | |
num1=0.025 | |
tmpValue = 0.66 * ((v - minLo)/num1 - 0.5) + 0.67 * tmpValuePrev | |
if tmpValue > 0.99: | |
tmpValue = 0.999 | |
elif tmpValue < -0.99: | |
tmpValue = -0.99 | |
tmpSeries.append(tmpValue) | |
val = 0.5 * math.log((1+tmpValue)/(1-tmpValue)) + 0.5* fishPrev | |
Value.append(val) | |
#Value - contains final results |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment