def _generate_random_transactions(instruments, total_amount, commission):
  
  # Load historic prices
  quotes = quotes_by_symbols(instruments)
  
  cutoff_date = datetime.now().date() - timedelta(days = DEMO_DAYS_CUTOFF)
  prices = dict([ (quote.symbol, {}) for quote in quotes ])
  dates = set([])
  quote_map = { }
  for quote in quotes:
    quote_map[quote.symbol] = quote
    for history in quote.pricehistory_set.filter(as_of_date__gte = cutoff_date).order_by('as_of_date'):
      cur_date =  history.as_of_date.date()
      prices.get(quote.symbol)[cur_date] = history.price
      dates.add(cur_date)

  # portfolio probabilities
  transaction_probability = float(len(dates)) / DEMO_TARGET_TRANSACTIONS
  deposit_probability = DEMO_TARGET_DEPOSITS / float(DEMO_TARGET_TRANSACTIONS)
  buy_sell_probability = DEMO_BUY_SELL_RATIO / float(DEMO_BUY_SELL_RATIO + 1)

  # generate transactions
  transactions = []
  quantities = dict([ (symbol, 0.0) for symbol in instruments ])
  undeposited_cash = total_amount
  cash = 0
  for date in sorted(dates):
    sell_candidates = [ q[0] for q in quantities.items() if q[1] > 0 ]
    
    # see if there is a transaction today or if we are just starting out
    if random() <= transaction_probability or len(transactions) == 0:
      
      # deposits
      if undeposited_cash > 1 and random() <= deposit_probability:
        deposit = min([ undeposited_cash, round(undeposited_cash * (randint(10, 100) / 100.0), -2), total_amount * 0.5 ])
        undeposited_cash -= deposit
        cash += deposit
        transactions.append(Transaction(type = 'DEPOSIT',
            as_of_date = date,
            symbol = CASH_SYMBOL,
            quantity = deposit,
            price = 1.0,
            total = deposit,
          ))
        
      # buys - if we have any cash
      elif random() <= buy_sell_probability:
        amount = min([ cash, round(cash * (randint(20, 100) / 100.0)), total_amount * 0.1 ])
        symbol = choice(instruments)
        price = (prices.get(symbol).get(date) if not quote_map.get(symbol).cash_equivalent else 1.0)
        quantity = floor((amount - commission) / price)
        if quantity > 0:
          total = (quantity * price) + commission
          cash -= total
          quantities[symbol] = quantities.get(symbol) + quantity
          transactions.append(Transaction(type = 'BUY',
              as_of_date = date,
              symbol = symbol,
              quantity = quantity,
              price = price,
              total = total,
            ))
        
      # sells - if there is anything to sell
      elif len(sell_candidates) > 0:
        symbol = choice(sell_candidates)
        price = (prices.get(symbol).get(date) if not quote_map.get(symbol).cash_equivalent else 1.0)
        available_quantity = quantities.get(symbol)
        quantity = min(available_quantity, round(available_quantity * (randint(20, 100) / 100.0)))
        if quantity > 0:
          total = (quantity * price) - commission
          cash += total
          quantities[symbol] = quantities.get(symbol) - quantity
          transactions.append(Transaction(type = 'SELL',
              as_of_date = date,
              symbol = symbol,
              quantity = quantity,
              price = price,
              total = total,
            ))

  return transactions
dataset/ETHPy150Open fxdemolisher/frano/frano/main/demo.py/_generate_random_transactions/swapped operands of `/`