def RunTradingModelBuyHoldMultipleStocks(tickerList: list, startDate: str, durationInYears: int, totalFunds: int, verbose: bool = False, saveHistoryToFile: bool = True, returndailyValues: bool = False): modelName = 'BuyHold_MultipleStocks' tm = TradingModel(modelName, tickerList[0], startDate, durationInYears, totalFunds, verbose) if not tm.modelReady: print('Unable to initialize price history for model for ' + str(startDate)) if returndailyValues: return pandas.DataFrame() else: return totalFunds else: while not tm.ModelCompleted(): tm.ProcessDay() if tm.TraunchesAvailable(): for t in tickerList: if not tm.TraunchesAvailable(): break currentPrices = tm.GetPriceSnapshot(t) if not currentPrices == None: if tm.TraunchesAvailable( ) and tm.FundsAvailable() > currentPrices.high: tm.PlaceBuy(t, currentPrices.low, True) if tm.AccountingError(): break if returndailyValues: tm.CloseModel(verbose, saveHistoryToFile) return tm.GetdailyValue() #return daily value else: return tm.CloseModel(verbose, saveHistoryToFile) #return closing value
def RunTradingModelBuyHold(tm: TradingModel, ticker: str): currentPrices = tm.GetPriceSnapshot() if tm.verbose: print(currentPrices.snapShotDate, currentPrices.nextDayTarget) if not currentPrices == None: if tm.TraunchesAvailable() > 0 and tm.FundsAvailable( ) > currentPrices.high: tm.PlaceBuy(ticker, currentPrices.low, True)