def get_historical_volume(historical, company, scaler): historical_volume = [] #is a dynamic array (list) for python average_volume = [] for i in range(len(historical)): x = float(historical[i]['Volume']) historical_volume.append(x) average_volume.append(float(company.get_avg_daily_volume())) scaled_historical_volume = scale.scale(historical_volume, scaler) scaled_average_volume = scale.scale(average_volume, scaler) return historical_volume, average_volume, scaled_historical_volume, scaled_average_volume
def get_change(historical, scaler): change = [] change.append(0) for i in range(len(historical)-1): x = float(historical[i+1]["Close"]) - float(historical[i]['Close']) change.append(x) scaled_change = scale.scale(change, scaler) return change, scaled_change
def get_historical_low(historical, scaler): days_low = [] for i in range(len(historical)): x = float(historical[i]['Low']) days_low.append(x) scaled_low = scale.scale(days_low, scaler) return days_low, scaled_low
def get_historical_high(historical, scaler): days_high = [] for i in range(len(historical)): x = float(historical[i]['High']) days_high.append(x) scaled_high = scale.scale(days_high, scaler) return days_high, scaled_high
def get_historical_opening(historical, scaler): opening = [] for i in range(len(historical)): x = float(historical[i]['Open']) opening.append(x) scaled_opening = scale.scale(opening, scaler) return opening, scaled_opening
def get_historical_closing(historical, scaler): closing = [] for i in range(len(historical)): x = float(historical[i]['Adj_Close']) closing.append(x) scaled_closing = scale.scale(closing, scaler) return closing, scaled_closing
def get_historical_opening(historical, scaler): opening = [] #is a dynamic array (list) for python for i in range(len(historical)): x = float(historical[i]['Open']) opening.append(x) scaled_opening = scale.scale(opening, scaler) return opening, scaled_opening
def get_back_trading_day(historical, index, scaler): op = float(historical[-index]["Open"]) h = float(historical[-index]['High']) l = float(historical[-index]['Low']) v = float(historical[-index]['Volume']) ch = h - l ths = np.array((op, h, l, v)) sc_ths = scale.scale(ths, scaler) #print index, ". ", historical[-index]['Date'] return sc_ths
def get_historical_closing(historical, scaler): #same for closing closing = [] for i in range(len(historical)): x = float(historical[i]['Adj_Close']) closing.append(x) scaled_closing = scale.scale(closing, scaler) return closing, scaled_closing
def get_trading_day(company, scaler, useSpread, useVolume): opening_price = float(company.get_open()) todays_volume = float(company.get_volume()) high = float(company.get_days_high()) low = float(company.get_days_low()) avg_volume = float(company.get_avg_daily_volume()) change = float(company.get_change()) if useSpread is False and useVolume is False: today = np.array((opening_price, high, low)) elif useSpread is True and useVolume is False: today = np.array((opening_price, high, low, change)) elif useSpread is False and useVolume is True: today = np.array((opening_price, high, low, todays_volume)) else: today = np.array((opening_price, high, low, change, todays_volume)) scaled_today = scale.scale(today, scaler) return today, scaled_today
def test_normalize_scale(self): #scales two points about their midpoint from normalize import scale self.assertEqual(scale(2.4, (64, 34), (36, 34)), ((83, 34), (16, 34)))
receivers.append(int(comps[2])) if int(comps[1]) > lastNodeID: lastNodeID = int(comps[1]) if int(comps[2]) > lastNodeID: lastNodeID = int(comps[2]) #Just for test #if comps[0] == '10': # break nodes = list(range(lastNodeID+1)) # Scale the data edges = scale(edges, normMethod) edges = get_edges_from_list(edges) graph = { "nodes": nodes, "edges": edges, "senders": senders, "receivers": receivers } seed = 2 rand = np.random.RandomState(seed=seed) print("Convert dictionary to graph") graph = dict_to_graph(graph) print("Shortest path") graph = add_shortest_path(rand, graph)