def toscheme(self, val, shallow=False): "Convert a Python value to a Scheme value." if callable(val): val = self._wrap_python_callable(val, shallow) return expressions.makePrimitiveProcedure(val) if val is True: return symbol.true if val is False: return symbol.false if type(val) is schemepy.types.Symbol: return symbol.Symbol(val.name) if type(val) is schemepy.types.Cons: car = val.car cdr = val.cdr if not shallow: car = self.toscheme(car) cdr = self.toscheme(cdr) return pair.cons(car, cdr) if isinstance(val, list): lst = pair.NIL for el in reversed(val): if not shallow: el = self.toscheme(el) lst = pair.cons(el, lst) return lst if isinstance(val, dict): lst = pair.NIL for key, value in val.items(): key = self.toscheme(key) if not shallow: value = self.toscheme(value) lst = pair.cons(pair.cons(key, value), lst) return lst return val
def d_m_avg_s(my_symbol, m_avg_len): start_date = datetime.strptime( self.trading_days[0], "%Y%M%d") - timedelta(days=300) mysymbol = symbol.Symbol(my_symbol, start_date, self.trading_days[-1]) ts = mysymbol.close.derivative_m_avg(date, date, m_avg_len) return ts.data[0]
def roc_s(my_symbol, hist_len): my_symbol = symbol.Symbol(my_symbol, self.trading_days[0], self.trading_days[-1]) end_index = self.trading_days.index(date) start_index = end_index - hist_len if start_index >= 0: return my_symbol.close.roc(date, hist_len)
def load_symbol_object(interval): '''Load stock historicl prices with default initial values''' # Default values initialised input_file_name = '.\\..\\..\\Data Sets\\Yahoo\\nifty50list.csv' symbol_list = pd.read_csv(input_file_name) # Create a symbol object with the historical data of the stocks in input file symbol = s.Symbol(symbol_list=symbol_list, interval=interval) return symbol
def load_symbol_object(interval): '''Load stock historicl prices with default initial values''' # Default values initialised symbols_file = '.\\..\\..\\Github\\Data Sets\\Quandl\\NSE100_Symbols.csv' symbol_list = pd.read_csv(symbols_file) # Create a symbol object with the historical data of the stocks in input file symbol = s.Symbol(symbol_list=symbol_list, interval=interval) return symbol
def GenerateSymbols(self): i = 0 while i < len(self.values): #make new symbol object and pass the value,frequency and Probability to it self.symbols.append( symbol.Symbol( self.values[i], self.message.count(self.values[i]), self.message.count(self.values[i]) / len(self.message))) i = i + 1
def test_get_price_alphavantage_json(self): symb_vt = symbol.Symbol('vt') self.assertEqual(symb_vt.get_price('2018-06-14'), (76.07, 76.1790, 75.87, 75.97)) self.assertEqual(symb_vt.get_price('20180614'), (76.07, 76.1790, 75.87, 75.97)) self.assertIsNone(symb_vt.get_price('20180630')) self.assertEqual(symb_vt.get_price(('20180601', '20180615')), (76.26, 76.2800, 75.28, 75.65)) self.assertEqual(symb_vt.get_price(('20180402', '20180614')), (73.39, 76.2800, 71.60, 75.97)) self.assertIsNone(symb_vt.get_price(('20180614', '20180630')))
def close_m_avg_up(my_symbol, m_avg, hist_len): m_avg_symbol = symbol.Symbol(my_symbol, self.trading_days[0], self.trading_days[-1]) end_index = self.trading_days.index(date) start_index = end_index - max([m_avg, hist_len]) if start_index >= 0: close_m_avg = m_avg_symbol.close.m_avg( self.trading_days[start_index], date, m_avg) return close_m_avg.monotonous_up(date, hist_len)
def HuffmanCodes(self, arr): print('huffman hufman codes') self.symbarr = arr heapq.heapify(self.symbarr) while (len(self.symbarr) != 1): #get the two smallest symbols' frequencies l = heapq.heappop(self.symbarr) r = heapq.heappop(self.symbarr) #construct a new symbol with frequency = to the summation of the two symbols #value is 'a' dummy valuue just to know that it is a constructed symbol node = symbol.Symbol('a', l.frequency + r.frequency, l.probability + r.probability) # cheeeeeck #keep the two symbols in the left and the right of the new node node.left = l node.right = r #push the new node heapq.heappush(self.symbarr, node) printCodes(self.map, self.symbarr[0], "")
def makeAnd(clauses): return pair.cons(symbol.Symbol("AND"), clauses)
data['document'] = '' elif len(data['document']) > 0: if os.path.isfile(data['document']): data['document'] = os.path.join( document_prefix, data['document']) else: print "Warning: '" + data[ 'document'] + "' not found" data['document'] = '' if 'section' not in data: data['section'] = '' firstElement = True sym = symbol.Symbol(data['name'], data['reference'], data['footprint'], data['alias'], data['description'], data['keywords'], data['document']) last_name = data['name'] if 'unit' not in data: data['unit'] = "0" unit = int(data['unit']) if os.path.isfile(template_file): sym.load(template_file, unit, symbol.representation.normal, data, firstElement) elif os.path.isfile(table_file): sym.fromCSV(table_file, unit, data['section'], unit != 0) #if not unit and 'value' in data:
def gen_ts_fixture(): # time for methods to start at m_start = '20030102' # time series end time end = '20091009' # open database db = anydbm.open('test_time_series.db', 'c') # add time series to database security = symbol.Symbol('AMZN', '20000103', end) ts = security.close db[ 'time_series_1' ] = pickle.dumps(ts) # add dates to database db[ 'm_start' ] = m_start db[ 'end' ] = end # add method returns to database db['max'] = pickle.dumps(ts.max(m_start, end)) db['min'] = pickle.dumps(ts.min(m_start, end)) db['sum'] = pickle.dumps(ts.sum(m_start, end)) db['m_sum'] = pickle.dumps(ts.m_sum(m_start, end, 10)) db['avg'] = pickle.dumps(ts.avg(m_start, end)) db['m_avg'] = pickle.dumps(ts.m_avg(m_start, end, 10)) db['exp_m_avg'] = pickle.dumps(ts.exp_m_avg(m_start, end, 10, None)) db['hist_changes'] = pickle.dumps(ts.hist_changes(m_start, end, 1)) db['hist_adv'] = pickle.dumps(ts.hist_adv(m_start, end, 1)) db['hist_dec'] = pickle.dumps(ts.hist_dec(m_start, end, 1)) db['rsi'] = pickle.dumps(ts.rsi(m_start, end, 10)) db['exp_rsi'] = pickle.dumps(ts.exp_rsi(m_start, end, 10)) db['stdev'] = pickle.dumps(ts.stdev(m_start, end, 10)) db['b_bands'] = pickle.dumps(ts.b_bands(m_start, end, 10, 2)) db['low'] = pickle.dumps(ts.low(m_start, end, 1)) db['high'] = pickle.dumps(ts.high(m_start, end, 1)) low = security.low.low(m_start, end, 10) high = security.high.high(m_start, end, 10) db['fsto_k'] = pickle.dumps(ts.fsto_k(low, high, m_start, end, 10)) db['mfi'] = pickle.dumps(ts.mfi(security.high, security.low, security.close, security.volume, m_start, end, 10)) db['monotonous_up'] = pickle.dumps(ts.monotonous_up(end, 10)) db['monotonous_down'] = pickle.dumps(ts.monotonous_down(end, 10)) db['historic_spread'] = pickle.dumps(ts.historic_spread(end, 10)) db['roc'] = pickle.dumps(ts.roc(end, 10)) db['derivative'] = pickle.dumps(ts.derivative(m_start, end)) db['derivative_m_avg'] = pickle.dumps(ts.derivative_m_avg(m_start, end, 10))
def test_get_price_cnyes_csv(self): symb_50 = symbol.Symbol('0050') self.assertEqual(symb_50.get_price('20160726'), (69.0, 69.4, 68.85, 69.4)) self.assertEqual(symb_50.get_price('20180615'), (81.60, 81.95, 81.20, 81.95)) self.assertEqual(symb_50.get_price(('20160726', '20160801')), (69.0, 69.95, 68.85, 69.7)) self.assertEqual(symb_50.get_price(('20160726', '20180614')), (69.00, 83.10, 68.85, 81.75))
info = ['Market Cap: ', 'P/E: ', 'EPS: '] if (self.ts != None): ts_info = ['Enter Signal: ' + str(self.ts.enter_signal), 'Exit Signal: ' + str(self.ts.exit_signal), 'Trading Commission: $' + str(self.ts.trading_commission), 'Performance Index: ' + str(self.ts.performance_index[ 'p_index' ].data[-1]) ] for i in ts_info: info.append(i) for i in range (0, len(info)): fig.text(padding, v_start - i*v_space ,info[i], fontsize=text_size) if __name__ == '__main__': import symbol k=symbol.Symbol('GOOG', '20050901', '20090924') m=Chart(k) m.add_main_plot(k.close) m.add_subplot(k.close.rsi('20060905', '20090924', 14)) #m.add_subplot(k.close.rsi('20060905', '20090924', 6)) m.show()
def get_symbol_by_index(idx): sbl = None if idx == 0: # DOT sbl = symbol.SymbolDot() elif idx == 1: # KEY_SIGNATURE_1_# sbl = symbol.SymbolKeySignature('KEY_SIGNATURE_1_#', 1) elif idx == 2: # NOTE_QUARTER_UP sbl = symbol.SymbolSingleNote('NOTE_QUARTER_UP', 1 / 4, 'up', 37, False) elif idx == 3: # NOTE_HALF_UP sbl = symbol.SymbolSingleNote('NOTE_HALF_UP', 1 / 2, 'up', 37, False) elif idx == 4: # TIME_SIGNATURE_3_4 sbl = symbol.SymbolTimeSignature('TIME_SIGNATURE_3_4', 3, 4) elif idx == 5: # BAR sbl = symbol.SymbolBar('BAR_SINGLE', 'single') elif idx == 6: # NOTE_QUARTER_DOWN sbl = symbol.SymbolSingleNote('NOTE_QUARTER_DOWN', 1 / 4, 'down', 0, False) elif idx == 7: # BEAM_2_EIGHTH_NOTES_UP sbl = symbol.SymbolBeamNote('BEAM_2_EIGHTH_NOTES_UP', [1 / 8, 1 / 8], 'up', [36, 36]) elif idx == 8: # BEAM_2_EIGHTH_NOTES_DOWN sbl = symbol.SymbolBeamNote('BEAM_2_EIGHTH_NOTES_DOWN', [1 / 8, 1 / 8], 'down', [0, 0]) elif idx == 9: # FINAL_BAR sbl = symbol.SymbolBar('BAR_DOUBLE', 'double') elif idx == 10: # REST_QUARTER sbl = symbol.SymbolRest('REST_QUARTER', 1 / 4) elif idx == 11: # NOTE_HALF_DOWN sbl = symbol.SymbolSingleNote('NOTE_HALF_DOWN', 1 / 2, 'down', 0, False) elif idx == 12: # NOTE_EIGHTH_DOWN sbl = symbol.SymbolSingleNote('NOTE_EIGHTH_DOWN', 1 / 8, 'down', 0, False) elif idx == 13: # KEY_SIGNATURE_2_# sbl = symbol.SymbolKeySignature('KEY_SIGNATURE_2_#', 2) elif idx == 14: # CLEF_TREBLE sbl = symbol.SymbolClef('CLEF_TREBLE', 'treble') elif idx == 15: # NOTE_EIGHTH_UP sbl = symbol.SymbolSingleNote('NOTE_EIGHTH_UP', 1 / 8, 'up', 37, False) elif idx == 16: # NOTE_HALF_UP_WITH_DOT sbl = symbol.SymbolSingleNote('NOTE_HALF_UP_WITH_DOT', 1 / 2, 'up', 37, True) elif idx == 17: # TIE sbl = symbol.SymbolTie() elif idx == 18: # TIME_SIGNATURE_4_4 sbl = symbol.SymbolTimeSignature('TIME_SIGNATURE_4_4', 4, 4) elif idx == 19: # NOTE_QUARTER_UP_WITH_DOT sbl = symbol.SymbolSingleNote('NOTE_QUARTER_UP_WITH_DOT', 1 / 4, 'up', 37, True) elif idx == 20: # NOTE_WHOLE sbl = symbol.SymbolSingleNote('NOTE_WHOLE', 1, 'up', 0, False) elif idx == 21: # NOTE_QUARTER_DOWN_WITH_DOT sbl = symbol.SymbolSingleNote('NOTE_QUARTER_DOWN_WITH_DOT', 1 / 4, 'down', 1.5, True) elif idx == 22: # KEY_SIGNATURE_1_b sbl = symbol.SymbolKeySignature('KEY_SIGNATURE_1_b', -1) elif idx == 23: # TIME_SIGNATURE_2_4 sbl = symbol.SymbolTimeSignature('TIME_SIGNATURE_2_4', 2, 4) pass else: sbl = symbol.Symbol('DEFAULT') print('!FAIL Symbol recognition - getting index:', idx) return sbl
def runNonInteractive(interp, args): """Executes the interpreter on args[0].""" interp.eval(pair.list(symbol.Symbol("load"), args[0]))
def __init__(self, symbol_list, symbol_blacklist, start_date, end_date): self.symbols = self.__expand_list(symbol_list, symbol_blacklist) self.components = {} for csym in self.symbols: self.components[ csym ] = symbol.Symbol(csym, start_date, end_date)
def makeOr(clauses): return pair.cons(symbol.Symbol("OR"), clauses)
import sys import parser import code import symbol name = sys.argv[1][:-4] name = name + ".hack" f = open(sys.argv[1],"r") contents = f.readlines() f.closed p = parser.Parser() trimmed_instructions = p.read_in(contents) s = symbol.Symbol() symbols_replaced = s.replace_symbols(trimmed_instructions) c = code.Code(); output = c.convert_to_binary(symbols_replaced) with open(name, 'w') as the_file: for item in output: the_file.write("%s\n" % item)