Skip to content

Instantly share code, notes, and snippets.

View joeng03's full-sized avatar
🏠
Working from home

Yin Joe Ng joeng03

🏠
Working from home
View GitHub Profile
for i in range(0,len(local_max)-3):
(m,c),r,_,_,_= np.polyfit(local_max_idx[i:i+3],local_max[i:i+3],1,full=True)
if(m<=3 and m>=-3 and (r[0]<20 and r[0]>-20)):
start=local_max_idx[i+2]
for k in range(start,start+7):
if(k<len(prices_close) and prices_close[k]>(k*m+c)):
plt.figure(figsize=(10,5))
plt.plot(local_max_idx,m*local_max_idx+c,'m')
plt.plot(prices_close)
plt.plot(k,prices_close[k],'bo')
local_min_idx=argrelextrema(prices_low,np.less)[0]
local_max_idx=argrelextrema(prices_high,np.greater)[0]
local_min_idx=np.array(local_min_idx)
local_max_idx=np.array(local_max_idx)
local_min=[]
local_max=[]
for loc in local_min_idx:
local_min.append(prices_low[loc])
for loc in local_max_idx:
data=requests.get('https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&outputsize=full&symbol=FB&apikey=YOURAPIKEY')
data=data.json()
prices_low,prices_high,prices_close=[],[],[]
for i in range(200,1,-1):
d=date.today()-timedelta(i)
d=d.strftime("%Y-%m-%d")
try:
prices_high.append(float(data["Time Series (Daily)"][d]["2. high"]))
prices_low.append(float(data["Time Series (Daily)"][d]["3. low"]))
prices_close.append(float(data["Time Series (Daily)"][d]["4. close"]))
#import the required libraries
import requests
from datetime import timedelta,date
import numpy as np
from scipy.signal import argrelextrema
import matplotlib.pyplot as plt
import time
function move(element,direction,duration=1000){
var elStyle = window.getComputedStyle(element);
var x_coord= elStyle.getPropertyValue('left').replace("px", "");
var y_coord= elStyle.getPropertyValue('top').replace("px", "");
var x_frameDistance = direction[0]/ (duration / 10);
var y_frameDistance = direction[1] / (duration / 10);
function moveAFrame() {
elStyle = window.getComputedStyle(element);
x_coord = elStyle.getPropertyValue('left').replace("px","");
var x_newLocation = Number(x_coord) + x_frameDistance;
function move_by_vector(element,direction,duration=1000) {
var elStyle = window.getComputedStyle(element);
var x_isNegated =(direction[0]<0)?true:false;
var y_isNegated =(direction[1]<0)?true:false;
var x_coord= elStyle.getPropertyValue('left').replace("px", "");
var y_coord= elStyle.getPropertyValue('top').replace("px", "");
var x_destination = Number(x_coord) + direction[0];
var y_destination = Number(y_coord) + direction[1];
var x_frameDistance = direction[0]/ (duration / 10);
var y_frameDistance = direction[1] / (duration / 10);
for i in range(65,y_train.shape[0]):
a_train.append(X_train[i-65:i-5,0])
b_train.append(y_train[i-5:i,0])
for x in range(65,y_test.shape[0]):
c_test.append(X_test[x-65:x-5,0])
d_test.append(y_test[x-5:x,0])
import pandas as pd
import numpy as np
import pandas_datareader as pdr
from sklearn.preprocessing import MinMaxScaler
import matplotlib.pyplot as plt
TI= TechnicalIndicators()
close_data=TI.close_data[['4. close']]
macd_data=TI.macd_data
rsi_data=TI.rsi_data
bbands_data=TI.bbands_data
import pandas as pd
import numpy as np
import pandas_datareader as pdr
from sklearn.preprocessing import MinMaxScaler
import matplotlib.pyplot as plt
TI= TechnicalIndicators()
close_data=TI.close_data[['4. close']]
macd_data=TI.macd_data
rsi_data=TI.rsi_data
bbands_data=TI.bbands_data
from keras.models import Sequential
from keras.layers import Dense, Dropout,LSTM
from keras.optimizers import Adam
model = Sequential()
model.add(LSTM(units=100,input_shape=(x_train.shape[1],1),return_sequences=True))
model.add(LSTM(units=100))
model.add(Dropout(0.4))
model.add(Dense(1))
ADAM = Adam(0.0005, beta_1=0.9, beta_2=0.999, amsgrad=False)
model.compile(loss='mean_squared_error', optimizer=ADAM)