def initialize_strategy(dateObejct, symbolObject, startPrice, orderBook=None): """ Input: dateObject startPrice symbolObject strategy to be initialized here. return First Orders and parameters set here """ stratData = StratDatabaseObject(round(startPrice, -2)) orders = [] orderBook = pd.DataFrame(columns=[ 'Date', 'Symbol', 'FuturePrice', 'Type', 'StrikePrice', 'Side', 'Quantity', 'Price', 'Value' ]) orders.append( OrderObject(symbol=symbolObject.symbol, optionType='Put', strikePrice=stratData.actionrange[0], side='Sell', quantity=stratData.quantity)) orders.append( OrderObject(symbol=symbolObject.symbol, optionType='Call', strikePrice=stratData.actionrange[1], side='Sell', quantity=stratData.quantity)) orderBook = order_log(dateObejct, orders, orderBook, startPrice) return stratData, orderBook
def initialize_strategy(date,sym,startPrice): lastactionPrice = 235 actionDif = 10 openPrice= 235 maxspell = 6 stratData = [lastactionPrice,actionDif,openPrice,maxspell] orders = [] orders.append(OrderObject(symbol = sym,optionType = 'Put',strikePrice = int(lastactionPrice),side = 'Sell',quantity = 1)) orders.append(OrderObject(symbol = sym,optionType = 'Call',strikePrice = int(lastactionPrice),side = 'Sell',quantity = 1)) orderBook = pd.DataFrame(columns = ['Date','Symbol','FuturePrice','Type','StrikePrice','Side','Quantity','Price','Value']) orderBook = order_log(date,orders,orderBook,startPrice) return stratData,orderBook
def initialize_strategy(dateObejct, symbolObject, startPrice, orderBook=None): """ Input: dateObject startPrice symbolObject strategy to be initialized here. return First Orders and parameters set here """ stratData = StratDatabaseObject(round(startPrice, -2)) orders = [] orderBook = pd.DataFrame(columns=[ 'Date', 'Symbol', 'FuturePrice', 'Type', 'StrikePrice', 'Side', 'Quantity', 'Price', 'Value' ]) orderBook = order_log(dateObejct, orders, orderBook, startPrice) return stratData, orderBook
def initialize_strategy(dateObject, symbolObject, startPrice, orderBook=None): """ Input: date startPrice symbolObject strategy to be initialized here. return First Orders and parameters set here """ stratData = StratDatabaseObject(round(startPrice, -2)) orders = [] try: len(orderBook) # to check if orderBook exists or not except: orderBook = pd.DataFrame(columns=[ 'Date', 'Symbol', 'FuturePrice', 'Type', 'StrikePrice', 'Side', 'Quantity', 'Price', 'Value' ]) orders.append( OrderObject(symbol=symbolObject.symbol, optionType='Put', strikePrice=stratData.startPrice, side='Sell', quantity=stratData.startQunatity)) orders.append( OrderObject(symbol=symbolObject.symbol, optionType='Call', strikePrice=stratData.startPrice, side='Sell', quantity=stratData.startQunatity)) orderBook = order_log(dateObject, orders, orderBook, startPrice) stratData.quantity = stratData.startQunatity return stratData, orderBook
for priceObject in test.simulatedPrices[key]: dateTimeObject = datetime.datetime.strptime( str(date) + " " + str(priceObject.timeStamp.time()), '%Y-%m-%d %H:%M:%S') test.runSimulator(priceObject) stockPrice = priceObject.futPrice order, strategyDataBase = strategy(stockPrice, strategyDataBase, sym) stringToPrint = str(priceObject.timeStamp.date()) + ', ' + str( priceObject.timeStamp.time()) + ', ' + str( priceObject.futPrice) + ', ' + str( priceObject.optionPrice) + '\n' f.write(stringToPrint) priceList.append(stockPrice) if len(order) > 0: orderBook = order_log(dateTimeObject, order, orderBook, stockPrice) strategyDataBase.dayStart = False order, strategyDataBase = strategy(stockPrice, strategyDataBase, sym) orderBook = order_log(dateTimeObject, order, orderBook, stockPrice) # prevHigh = masterData.loc[i,'High'] # prevLow = masterData.loc[i,'Low'] # strategyDataBase.prevHigh = prevHigh # strategyDataBase.prevLow = prevLow expiryPrice = get_price_startEnd(masterData, 'End') final_trade_book = PnL_log(orderBook, expiryPrice) sum(final_trade_book['PnL']) ####### Testing ######### #profits_list = [1, 2, 4, 14, 13, 1, 2, -2, -12, 214, 12, -12]