コード例 #1
0
ファイル: get_stock_data.py プロジェクト: nrodrigo/Scripts
if start_date is None:
    print "Must enter start_date\n"
    sys.exit()

if end_date is None:
    end_date = datetime.today() + timedelta(days=1)

data = []
i=1
get_date = start_date

write_file = "./output/"+write_to
file = open(write_file, "w")
symbol_list = nr2stock.symbol_list()
while get_date.date() < end_date.date():
    if nr2stock.is_market_closed(get_date):
        get_date += timedelta(days=1)
        continue
    for symbol in symbol_list:
        print "Processing %s %s" % (symbol, get_date.strftime("%Y-%m-%d"))
        get_data = nr2stock.get_historical_data_all(symbol, get_date)
        if get_data is None:
            continue
            
        string =  "%s,%s,%s,%s,%s,%s,%s,%s\n" \
            % (symbol, get_data['date'], get_data['open'], get_data['high'], get_data['low'], get_data['close'], get_data['volume'], get_data['adj_close'])
        file.write(string)
    get_date += timedelta(days=1)
file.close()

コード例 #2
0
if start_date is None:
    print "Must enter start_date\n"
    sys.exit()

if end_date is None:
    end_date = datetime.today() + timedelta(days=1)

data = []
i = 1
get_date = start_date

write_file = "./output/" + write_to
file = open(write_file, "w")
symbol_list = nr2stock.symbol_list()
while get_date.date() < end_date.date():
    if nr2stock.is_market_closed(get_date):
        get_date += timedelta(days=1)
        continue
    for symbol in symbol_list:
        print "Processing %s %s" % (symbol, get_date.strftime("%Y-%m-%d"))
        get_data = nr2stock.get_historical_data_all(symbol, get_date)
        if get_data is None:
            continue

        string =  "%s,%s,%s,%s,%s,%s,%s,%s\n" \
            % (symbol, get_data['date'], get_data['open'], get_data['high'], get_data['low'], get_data['close'], get_data['volume'], get_data['adj_close'])
        file.write(string)
    get_date += timedelta(days=1)
file.close()
コード例 #3
0
    for var in row:
        quote[field_names[i]] = var
        i=i+1

    low_strike = float(quote['low_strike'])
    high_strike = float(quote['high_strike'])
    low_fill = float(quote['low_fill'])
    high_fill = float(quote['high_fill'])
    qty = float(quote['qty'])
    price_at_purchase = float(quote['price_at_purchase'])

    print "Symbol: %s, %s @ $%s (%s %s)" % (quote['symbol'], int(qty), "%.2f" % price_at_purchase, quote['outlook'], quote['type'])
    print "Low/High Option: %s @ $%s / %s @ $%s" % (quote['low_call'], "%.2f" % low_fill, quote['high_call'], "%.2f" % high_fill)

    debit_credit = 0.00
    stock_data = nr2stock.get_historical_data_all(quote['symbol'], check_date)
    current = float(stock_data['close'])
    print "Current: $%s" % ("%.2f" % current)
    if quote['type']=='credit':
        debit_credit = (quote['high_fill']-quote['low_fill'])*100
    elif quote['type']=='debit':
        debit_credit = (quote['low_fill']-quote['high_fill'])*100
    debit_credit = float(debit_credit) * qty
    print "Debit(-)/Credit(+): $%s" % ("%.2f" % debit_credit)

    actual_gain = 0.00
    max_gain = 0.00
    max_loss = 0.00
    if quote['type']=='credit':
        max_gain = debit_credit
        max_loss = ((high_strike-low_strike)*100*qty)-debit_credit