コード例 #1
0
ファイル: monitor.py プロジェクト: hsun/python-collection
    def eval(self, symbol, trend_up, midpoint, support, resist):
        try:
            quote = float(yahoo.get_all(symbol)['price'])
            odds = 0.0
            gap = 0.0
            if trend_up:
                stop = max(midpoint, support)
                if quote > stop:
                    odds = (resist - quote) / (quote - stop) 
                    gain = (resist - quote) / quote * 100.0
                    gap = (quote - stop) /quote * 100.0
                    shares = min(500, int(self.RISK_CAPITAL / (quote - stop)))
            else:
                stop = min(midpoint, resist)
                if quote < stop:
                    odds = (quote - support) / (stop - quote) 
                    gain = (quote - support) / quote * 100.0
                    gap = (stop - quote) /quote * 100.0
                    shares = min(500, int(self.RISK_CAPITAL / (stop - quote)))

            if odds > 3.0 and gap > 0.5:
                print "%s: %.2f, %.2f, %.2f, %.2f, %.2f, %.2f" % (symbol, odds, gap, gain, shares, quote, stop)
                
        except Exception, e:
            print "Failed to evaluate %s: %s " % (symbol, e)
コード例 #2
0
ファイル: monitor.py プロジェクト: hsun/python-collection
 def get_sector_trends(self):
     for sector in self.SECTOR_INDEX:
         change = float(yahoo.get_all(sector)['change'])
         print "Sector fund %s: %.2f" % (sector, change)
         if change > 0.0:
             self.sector_trends.append('UP')
         else:
             self.sector_trends.append('DOWN')
コード例 #3
0
ファイル: backtest.py プロジェクト: hsun/python-collection
 def market_status():
     market_symbol = 'SPY'
     market_quotes = yahoo.get_historical_prices(market_symbol, start_date, end_date)[1:]
     market_direction = _close(market_quotes[0]) > _close(market_quotes[-1])
     cur_quotes = yahoo.get_all(market_symbol)
     above_200ma = cur_quotes['price'] > cur_quotes['200day_moving_avg']
     above_50ma = cur_quotes['price'] > cur_quotes['50day_moving_avg']
     ma50_above_ma200 = cur_quotes['50day_moving_avg'] > cur_quotes['200day_moving_avg']
     print "For period from %s to %s" % (start_date, end_date)
     print "SP 500 is %s " % ("UP" if market_direction else "DOWN")
     print "Current price level is %s its 50 MA" % ("above" if above_50ma else "below") 
     print "Current price level is %s its 200 MA" % ("above" if above_200ma else "below") 
     print "Current 50 MA is %s 200 MA" % ("above" if ma50_above_ma200 else "below") 
     print
コード例 #4
0
 def evaluate_bear(self, symbol, meta):
     try:
         data = yahoo.get_all(symbol)
         price = data['price']
         change = data['change'] * -1.0
         moving_average_50 = data['50day_moving_avg']
         short_ratio = data['short_ratio']
         # volume is less important for price dropping 
         if (price is None or change is None or change/price < self.PRICE_CHANGE_THRESHOLD) \
                 and (moving_average_50 is None or price < moving_average_50) :
             print "Accept %s for its price volume pattern"  % (symbol)
             meta[symbol]['eval'].append("Price Volume Pattern")
             meta[symbol]['weight'] = meta[symbol]['weight'] + self.WEIGHT
         else:
             print "Reject %s for its price volume pattern: Change: %.2f Price: %.2f MA: %.2f Short Ratio: %.2f"\
               % (symbol, change or 0.0, price or 0.0, moving_average_50 or 0.0, short_ratio or 0.0)
             meta[symbol]['weight'] = -1000
     except Exception, e:
         print "Failed to evaluate price volume pattern for symbol %s: %s" % (symbol, e)
コード例 #5
0
 def evaluate_bull(self, symbol, meta):
     try:
         data = yahoo.get_all(symbol)
         price = data['price']
         change = data['change']
         volume = data['volume']
         avg_volume = data['avg_daily_volume']
         moving_average_50 = data['50day_moving_avg']
         short_ratio = data['short_ratio']
         if (volume is None or avg_volume is None or volume > avg_volume * self.VOLUME_THRESHOLD) \
             and (moving_average_50 is None or price > moving_average_50) \
             and (price is None or change is None or change/price < self.PRICE_CHANGE_THRESHOLD):
             print "Accept %s for its price volume pattern"  % (symbol)
             meta[symbol]['eval'].append("Price Volume Pattern")
             meta[symbol]['weight'] = meta[symbol]['weight'] + self.WEIGHT
         else:
             print "Reject %s for its price volume pattern: Change: %.2f Volume: %.2f Avg Volume: %.2f Price: %.2f MA: %.2f Short Ratio: %.2f"\
               % (symbol, change or 0.0, volume or 0.0, avg_volume or 0.0, price or 0.0, moving_average_50 or 0.0, short_ratio or 0.0)
             meta[symbol]['weight'] = -1000
     except Exception, e:
         print "Failed to evaluate price volume pattern for symbol %s: %s" % (symbol, e)
コード例 #6
0
ファイル: monitor.py プロジェクト: hsun/python-collection
 def is_market_up(self):
     return float(yahoo.get_all(self.MARKET)['change']) > 0
コード例 #7
0
ファイル: fund.py プロジェクト: hsun/python-collection
import sys, operator
from siteutil import Site
from BeautifulSoup import BeautifulSoup
from statlib import stats
from debug import say
from optutil import get_opts
from msn import MsnReport
import yahoo

if __name__ == '__main__':

    opts = get_opts({"s" : "symbol"})
    symbol = opts["symbol"].upper()

    data = yahoo.get_all(symbol)
    print "Symbol -- %s (%s)" % (symbol, data['market_cap'])

    print "---- Market ----"
    print "Quote: %s Change: %s" % (data['price'], data['change'])
    print "52-w High: %.2f 52-w Low: %.2f" % (float(data['52_week_high']), float(data['52_week_low']))
    print "50 SMA: %.2f 200 SMA: %.2f" % (float(data['50day_moving_avg']), float(data['200day_moving_avg']))
    volume = float(data['volume'])
    avg_volume = float(data['avg_daily_volume'])
    print "Volumn: %.0f Change: %.2f%%" % (volume, (volume - avg_volume)/volume * 100.0)
    print "Book Value: %s Price Book Ration: %s" % (data['book_value'], data['price_book_ratio'])
    print "EPS: %s Price Earning Ration: %s Price Earning Growth Ration: %s" % \
        (data['earnings_per_share'], data['price_earnings_ratio'], data['price_earnings_growth_ratio'])
    print "Ebitda: %s Price Sales raio: %s" % (data['ebitda'], data['price_sales_ratio'])
    print "Dividend Yield: %s Divident Per Share: %s" % (data['dividend_yield'], data['dividend_per_share'])
    print "Short Ratio: %s" % (data['short_ratio'])