def __init__(self, backlight, display): self.record_channels = [(2,3), (4,5), (6,7), (8,10), (11,12), (13, 14), (0, 1)] self.chord_channel, self.melody_channel = self.record_channels[-1] self.drum_channel = 9 #This is imposed by General MIDI self.p = None #Polyphony; Assigned by Polyphony itself, upon initializatinon self.b = backlight self.d = display self.f = flash.Flash(8) self.recorded = 0 #bit map self.playing = 0 #bit map self.recording = None #channel number self.recording_start_timestamp = None #*#self.records = [[],[],[],[],[],[],[],[]] self.record_lengths = [0]*8 self.cursors = [0]*8 self.durations = [0]*8 self.loop_start = [0]*8 #Timestamps self.toggle_play_waitlist = 0 #bit map self.loop_names = ["C", "D", "E", "F", "G", "A"] #TODO: load recorded tracks status here #Check & fix inconsitent flash disk state if self.f.check_erased(self.loop_exists): #Whole flash is being erased. Make sure we don't expect any tracks self.recorded = 0 indicator.Indicator(self.d, ["flash_blank", "flash_w"], self.indicator_status) #The indicator registers itself with display
import TradeData as td import indicator as ind from datetime import datetime as dt from dateutil.relativedelta import * # download data from yahoo daily data, 1min, 2min myTd = td.TradeData() myTd.get_new('') # # myTd.get_2min('', dt.now() + relativedelta(days=-5), dt.now()) myTd.get_min('', dt.now() + relativedelta(days=-4), dt.now()) # # # # calculate indicator MyInd = ind.Indicator() MyInd.ema() MyInd.kdj() MyInd.rsi(tickers=[]) MyInd.demark9Point() MyInd.KDJDaysInRange() MyInd.RSIDaysInRange()
def __init__(self): indicator.Indicator()
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import indicator class Init(): def __init__(self): indicator.Indicator() indicator.Indicator()
import pandas as pd import stock_price as sp import exploratory_data_analysis as eda import indicator # # test for web crawler # sp.download_stock_price('AAPL') # # x = sp.dataframe_of_single_stock('TSLA') # print(x) # # y = sp.dataframe_of_stocks(['BIDU', 'SINA']) # print(y) # # df = pd.read_csv('company_list.csv') # list_of_stock_symbol = df['Symbol'][:5] # first twenty stocks in the company list provided. # z = sp.dataframe_of_stocks(list_of_stock_symbol) # print(z) # # test for EDA # x = eda.EDA(['AAPL', 'TSLA', 'GS', 'MS']) # x.compare_close_price() # x.show_moving_avg() # x.show_corr_map() # test for indicator x = indicator.Indicator('AAPL') x.get_Volume()
def __init__(self): self.Price = price.Price() self.Price.parse() self.Indicator = indicator.Indicator()
def _handle_coin(self, coin): decision_point = len(self.interval) - 1 break_point = len(self.interval) - decision_point buy = 0 force_buy = 0 force_sell = 0 sell = 0 df = None for i, minute in enumerate(self.interval): array = np.array(self.public_v2.candles(minute, "t" + coin.upper(), "hist"))[::-1] df = pd.DataFrame(data=array[:, 0:6], columns=["date", "open", "close", "high", "low", "volume"]) indicator = ind.Indicator(df) signal = indicator.rate(coin, minute) time.sleep(2.0) if signal >= 1: if coin in self.available_currencies and i >= break_point and signal < 2: break buy = buy + 1 if signal >= 2: force_buy = force_buy + 1 elif signal <= -1: if coin not in self.available_currencies and i >= break_point and signal < 2: break sell = sell + 1 if signal <= -2: force_sell = force_sell + 1 if buy == 0 and sell == 0 and i >= break_point: time.sleep(2.0) break if df is None or 'close' not in df: logging.error(coin + " is missing price data") return price = float(df["close"][len(df) - 1]) if coin in self.buy_history and coin in self.available_currencies: if price > self.buy_history[coin] * self.profit_multiplier: logging.debug(coin + " IS profitable with price " + str(price) + " > " + str( self.buy_history[coin] * self.profit_multiplier)) force_sell = force_sell + 1 else: logging.debug(coin + " is NOT profitable with price " + str(price) + " < " + str( self.buy_history[coin] * self.profit_multiplier)) self.latest_score[coin] = sell if coin in self.latest_price: if self.latest_price[coin] > price: logging.debug(coin + " price is going down " + str(self.latest_price[coin]) + " -> " + str(price)) force_sell = force_sell + 1 if self.latest_price[coin] < price: logging.debug(coin + " price is going up " + str(self.latest_price[coin]) + " -> " + str(price)) force_buy = force_buy + 1 if sell == len(self.interval): force_sell = force_sell + 1 if buy == len(self.interval): force_buy = force_buy + 1 self.latest_price[coin] = price if buy == len(self.interval): force_buy = force_buy + 1 if sell == len(self.interval): force_sell = force_sell + 1 if coin in self.buy_attempts: if self.buy_attempts[coin] > 6: logging.debug(coin + " it's too late to catch the buy train") buy = 0 force_buy = 0 logging.debug( coin + " decision: B: " + str(buy) + " FB: " + str(force_buy) + " S: " + str(sell) + " FS: " + str( force_sell)) if buy >= decision_point or force_buy >= decision_point: ask = self._get_ask(coin, price) bought = self._buy_coin(coin, str(ask), force_buy >= decision_point) if not bought: if coin not in self.buy_attempts: self.buy_attempts[coin] = 0 elif self.buy_attempts[coin] < 10: self.buy_attempts[coin] = self.buy_attempts[coin] + 1 elif coin in self.buy_attempts: del self.buy_attempts[coin] elif sell >= decision_point or force_sell >= decision_point: bid = self._get_bid(coin, price) sold = self._sell_coin(coin, str(bid), force_sell >= decision_point) if sold and coin in self.buy_attempts: self.buy_attempts[coin] = self.buy_attempts[coin] - 1 else: if coin in self.buy_attempts: self.buy_attempts[coin] = self.buy_attempts[coin] - 1 if coin in self.buy_attempts and self.buy_attempts[coin] <= 0: del self.buy_attempts[coin]
import requests from pandas import DataFrame import talib.abstract as ta import talib import pandas as pd import numpy as np import math import indicator logging.basicConfig( level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') logger = logging.getLogger(__name__) indicators = indicator.Indicator() # Backtesting Counter class Counter: counter = 0 def get_ticker(pair: str, minimum_date: arrow.Arrow) -> dict: """ Request ticker data from Bittrex for a given currency pair """ url = 'https://bittrex.com/Api/v2.0/pub/market/GetTicks' headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36',