示例#1
0
def review_options():
    stocks = session.query(Stock).join(
        Option, Expiration).filter(Expiration.date >= datetime.now()).all()
    if (datetime.now() - stocks[0].std_timestamp).days > 14:
        refresh_standard_deviation()
    number_of_options = [len(stock.options) for stock in stocks]
    weights = [number / sum(number_of_options) for number in number_of_options]
    allowed_threads = [
        ceil(weight * parameters.max_number_of_threads) for weight in weights
    ]
    rates = fred.Fetched_Rates()
    threads = []
    for index, stock in enumerate(stocks):
        number_of_threads = allowed_threads[index]
        new_conn = setup_database.my_connection()
        thread = Thread(target=evaluate_and_buy,
                        args=[stock, rates, number_of_threads, new_conn])
        thread.start()
        threads.append(thread)
    for thread in threads:
        thread.join()
    return
示例#2
0
from persistency import setup_database
import integrations.marketstack as marketstack

connection = setup_database.my_connection()
session = connection.session


def populate():
    stocks = marketstack.get_tickers('XNAS')
    #with open('data/tickers.txt') as f:
    #    csv_reader = csv.reader(f,delimiter=',')
    #    for row in csv_reader:
    #        stocks += row
    #for idx, stock in enumerate(stocks):
    #    if idx > 10:
    #        break
    #    stock = Stock(isin = None, symbol=stock)
    #    session.add(stock)
    #print(stocks)

    session.add_all(stocks[0:10])
    session.commit()





populate()

#stocks = session.query(Stock).all()
#print(len(stocks))