コード例 #1
0
 def open_position(self, quote):
   shares = Position.get_shares(quote, self.get_risk())
   next_quote = quote.next()
   print "opening on next day", next_quote
   self.positions.append(Position.open(
       quote.symbol, 
       self.currency, 
       self.currency_rate, 
       next_quote.date,
       next_quote.open,
       self.enter_commission,
       shares))
コード例 #2
0
     position = None
   elif quote.is_below_10_day_low():
     print "10 day low MET %s" % position.get_trailing_stop()
     print "Selling %s" % position
     print "Gain %s" % position.get_gain()
     total = total + position.get_value(currency)
     position = None
   # total = total + (stocks * float(quote.close))
   #  position.value = 0
 else:
   over = quote.is_above_20_day_high()
   if over:
     risk = Decimal(total/100)
     shares = Position.get_shares(quote, risk)
     #print "Stop %s, Risk %s, Portfolio max risk %s" % (stop, shares * indicator.atr_exp20 * 2, risk)
     position = Position.open(symbol, currency, 1, quote.date, quote.close,
        Decimal('9'), shares)
     position.current_quote = quote
     position.is_long = True
     print "Opened %s" % position
     #position = Position({'symbol': symbol, 'is_long': True, 'current_quote': quote})
     #position.stop = indicator.calculate_stop(quote)
     print "Buy  %s" % (position)
     #if indicator.atr_14:
     #  print "%s quote over sma50 on %s" % (quote.symbol, quote.date)
     #  stop = float(quote.close) - float(indicator.atr_14) * float(0.1);
     #  stocks = float(total/2)/float(quote.close)
     #  position.value = stocks * float(quote.close)
     total = total - position.get_value(currency)
     #  print "Buying %s, stop at %s, position %s" % (quote, stop, position.value)
 #print "Total %s, position %s, %s" % (total, position.value, quote)
   else: