Skip to content

Instantly share code, notes, and snippets.

@shmalex
Created April 18, 2023 02:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shmalex/13d51a5eba94360a6d3b3e96dfb18366 to your computer and use it in GitHub Desktop.
Save shmalex/13d51a5eba94360a6d3b3e96dfb18366 to your computer and use it in GitHub Desktop.
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