Import packages
import matplotlib.pyplot as plt import pandas as pd import numpy as np import math import datetime import torch from torch import nn from torch.autograd import Variable import matplotlib.pyplot as plt |
product = 'AUDUSD' fileName = 'TS_data/'+'AUDUSD1440.csv' ts = pd.read_csv(fileName,parse_dates=[0]) ts = ts.dropna(axis=0,how='any') #print(ts.isna().any()) print(ts.shape) DT_CL = [i for i in ts.values[:,-2]] DT_CL
(2105, 7)
[0.91891, 0.92285, 0.9298, 0.93314, 0.9262600000000001, 0.92438, 0.9322, 0.9317799999999999, 0.9351299999999999,
...
0.7375, 0.7407, 0.7370800000000001, ...]
|
K = []
for eL in range(0,21):
K.append(pow((1.1924 + (33.2383*eL) + (56.2169*eL*eL))/(1 + (43.6106 *eL)),1/3))
print("Energy Level ",eL," K",eL," = ",K[eL])
Energy Level 0 K 0 = 1.0604104260891232 |
DT_RT = [] for d in range(0, ts.shape[0]-1): if DT_CL[d+1] > 0: DT_RT.append(DT_CL[d]/DT_CL[d+1]) else: DT_RT.append(1) # Calculate the s\mu and std dev mu = np.mean(DT_RT) sigma = np.std(DT_RT) # Approximately dr dr = (3 * sigma)/50 print(product+": mu =", mu, "; sigma = ", sigma," dr=",dr)
AUDUSD: mu = 1.0001520172318046 ; sigma = 0.00563034244868513 dr= 0.00033782054692110776
|
auxR = 0 Q = [0 for i in range(100)] NQ = [0 for i in range(100)] maxRno = len(DT_RT) tQno = 0 nQ = 0 numOfRInQSlot = 0 for r in DT_RT: bFound = False nQ = 0 auxR = 1 - (dr * 50) # Left boundary while ((bFound != True) and (nQ < 100)): if r > auxR and r <= (auxR + dr): Q[nQ]+=1 tQno+=1 bFound = True else: nQ+=1 auxR = auxR + dr # Normalize NQ = np.array(Q)/tQno # Find MaxQ and index of MaxQ maxQ = NQ.max() maxQno = NQ.tolist().index(maxQ) print(maxQno) print("maxQ =", maxQ, "; maxQno=", maxQno, "; total number of Q =", tQno) r=[] for i in range(100): r.append(1-50*dr+i*dr) plt.title(product+" Wavefunction") plt.bar([i for i in range(100)], NQ, alpha=0.6,width = 0.8)
50
|
r0 = r[maxQno] - (dr/2) r1 = r0 + dr rn1 = r0 - dr Lup = (pow(rn1,2)*NQ[maxQno-1])-(pow(r1,2)*NQ[maxQno+1]) Ldw = (pow(rn1,4)*NQ[maxQno-1])-(pow(r1,4)*NQ[maxQno+1]) L = abs(Lup/Ldw) print(product+":", " r0 = ",r0," r1 = ",r1," r-1 = ",rn1," Q0 = ",NQ[maxQno]," Q1 = ",NQ[maxQno+1]," Q-1 = ",NQ[maxQno-1]," L = Lup/Ldw = ",Lup,"/",Ldw," = ",L) print(product+"'s lambda = ", L)
AUDUSD: r0 = 0.9998310897265394 r1 = 1.0001689102734606 r-1 = 0.9994932691796183 Q0 = 0.04331087584215592 Q1 = 0.03849855630413859 Q-1 = 0.0370548604427334 L = Lup/Ldw = -0.0014942467280006297 / -0.0015447639489677908 = 0.9672977732287728 |
QFEL = [0 for i in range(21)] QPR = [0 for i in range(21)] NQPR = [0 for i in range(21)] # Cardano Method for eL in range(0, 21): p = -1 * pow((2*eL+1),2); q = -1 * L * pow((2*eL+1),3) * pow(K[eL],3) # Apply Cardano's Method to find the real root of the depressed cubic equation u = pow((-0.5*q + math.sqrt(((q*q/4.0) + (p*p*p/27.0)))),1/3) v = pow((-0.5*q - math.sqrt(((q*q/4.0) + (p*p*p/27.0)))),1/3) QFEL[eL] = u+v print(product+":", "Energy Level",eL," QFEL = ",QFEL[eL]) for eL in range(0, 21): QPR[eL] = QFEL[eL]/QFEL[0] NQPR[eL] = 1 + 0.21*sigma*QPR[eL]
AUDUSD: Energy Level 0 QFEL = 1.3595491196477827 |
daily_stock_data['Open'] # Initialize two-dimensional array P_QPL = [[0 for i in range(len(daily_stock_data['Open']))] for i in range(len(NQPR))] N_QPL = [[0 for i in range(len(daily_stock_data['Open']))] for i in range(len(NQPR))] #Calculate +QPL for i in range(len(NQPR)): for j in range(len(daily_stock_data['Open'])): P_QPL[i][j]=daily_stock_data['Open'][j]*NQPR[i] #Calculate -QPL for i in range(len(NQPR)): for j in range(len(daily_stock_data['Open'])): N_QPL[i][j]=daily_stock_data['Open'][j]/NQPR[i] P_QPL = pd.DataFrame(P_QPL) N_QPL = pd.DataFrame(N_QPL) P_QPL = pd.DataFrame(P_QPL.values.T, index=P_QPL.columns, columns=P_QPL.index) N_QPL = pd.DataFrame(N_QPL.values.T, index=N_QPL.columns, columns=N_QPL.index) daily_stock_data=pd.concat([daily_stock_data, P_QPL], axis=1) daily_stock_data=pd.concat([daily_stock_data, N_QPL], axis=1) new_index = ['Date','Time','Open','High','Low','Close','Volume','QPL1','QPL2','QPL3','QPL4','QPL5','QPL6','QPL7','QPL8','QPL9','QPL10', 'QPL11','QPL12','QPL13','QPL14','QPL15','QPL16','QPL17','QPL18','QPL19','QPL20','QPL21','QPL-1','QPL-2','QPL-3','QPL-4', 'QPL-5','QPL-6','QPL-7','QPL-8','QPL-9','QPL-10','QPL-11','QPL-12','QPL-13','QPL-14','QPL-15','QPL-16','QPL-17','QPL-18','QPL-19', 'QPL-20','QPL-21'] daily_stock_data.columns = new_index daily_stock_data.to_csv('TS_data_with_QPL/'+product+'.csv',index=False) |