def get_plot_price(code, start, end=None, interval="d", kind="Open"):
    try:
        price = get_prices(code,
                           start="2016/05/01",
                           end=end,
                           interval="m",
                           kind=kind,
                           verbose=True,
                           output_dataframe=True)
    except:
        print("get price error")

    plot_prices(price, kind=kind)
Beispiel #2
0
def run_simulation(symbol):
    query_params = request.args
    trim_start = query_params.get('start_date') or '2015-11-01'
    trim_end = query_params.get('end_date') or '2015-12-31'
    prices = get_prices([symbol], trim_start=trim_start, trim_end=trim_end)
    prices = prices[symbol]
    signal_crosses, simulation, earnings = simulate(prices)
    dailies = prices
    for timestamp in dailies.keys():
        dailies[timestamp] = {
            'price': prices[timestamp],
            'signal': signal_crosses[timestamp],
            'shares': simulation[timestamp]['shares'],
            'cash_on_hand': simulation[timestamp]['cash_on_hand']
        }
    dailies = SortedDict(dailies)
    return json.dumps({'earnings': earnings, 'dailies': dailies})
Beispiel #3
0
def run_simulation(symbol):
    query_params = request.args
    print query_params.get('startdate')
    print query_params.get('enddate')
    trim_start = query_params.get('startdate') or '2015-11-01'
    trim_end = query_params.get('enddate') or '2016-11-01'
    prices = get_prices([symbol], trim_start=trim_start, trim_end=trim_end)
    prices = prices[symbol]
    signal_crosses, simulation, earnings = simulate(prices)
    dailies = prices
    for timestamp in dailies.keys():
        dailies[timestamp] = {
            'price': prices[timestamp],
            'signal': signal_crosses[timestamp],
            'shares': simulation[timestamp]['shares'],
            'cash_on_hand': simulation[timestamp]['cash_on_hand']
        }
    dailies = SortedDict(dailies)
    return json.dumps({'earnings': earnings, 'dailies': dailies})
Beispiel #4
0
            float(players_list.index(steamid)) / float(len(players_list)) *
            100), "%."
        continue

    # load his items, without prices for now
    # revorked in 2.0
    itemlist = get_items.get_items(steamid, apikey)
    if itemlist == 0:
        print "Profile skipped because of backpack privacy", steamid
        print "Completed: ", str(
            float(players_list.index(steamid)) / float(len(players_list)) *
            100), "%."
        continue

    # tag prices and item names
    itemlistpriced = get_prices.get_prices(itemlist, bpdata)

    # let's sort it, this way it becomes sorted by price(1) and item name(2)
    pricedlistsorted = sorted(itemlistpriced,
                              key=itemgetter(2, 4),
                              reverse=True)

    # for some unknown for me yet reason I end up with
    # empty-priced and empty-named objects in here, now i will
    # just delete them, but later I'll have to find what causes them
    # here I make a little KOCTblJlb, don't judge
    list2 = pricedlistsorted
    pricedlistsorted = []
    for item in list2:
        if item[2] == '':
            continue
    for i in range(num_tries):
        final_portfolio = run_simulation(policy, budget, num_stocks, prices,
                                         hist)
        final_portfolios.append(final_portfolio)
        print("final budget: {}".format(final_portfolio))

    avg, std = np.mean(final_portfolios), np.std(final_portfolios)

    return avg, std


if __name__ == "__main__":
    prices = get_prices(9104,
                        start="2015/01/01",
                        end="2016/01/01",
                        interval="d",
                        kind="Open",
                        verbose=False,
                        output_dataframe=False,
                        length_info=False)
    #plot_prices(prices)

    actions = ["Buy", "Sell", "Hold"]
    hist = 20

    policy = RandomDesiopnPolicy(actions)
    budget = 1000.0
    num_stocks = 0

    avg, std = run_simulations(policy, budget, num_stocks, prices, hist)
    print("avg: {}, std: {}".format(avg, std))
Beispiel #6
0
	
	if hours_played > hours_max:
		print "Profile skipped because of excessive amount of playtime", steamid
		print "Completed: ", str( float(players_list.index(steamid)) / float(len(players_list))*100 ),"%."
		continue
		
	# load his items, without prices for now
	# revorked in 2.0
	itemlist = get_items.get_items( steamid , apikey)
	if itemlist == 0:
		print "Profile skipped because of backpack privacy", steamid
		print "Completed: ", str( float(players_list.index(steamid)) / float(len(players_list))*100 ),"%."
		continue
	
	# tag prices and item names
	itemlistpriced = get_prices.get_prices(itemlist, bpdata)
	
	# let's sort it, this way it becomes sorted by price(1) and item name(2)
	pricedlistsorted = sorted(itemlistpriced, key=itemgetter(2,4), reverse=True)
	
	# for some unknown for me yet reason I end up with
	# empty-priced and empty-named objects in here, now i will
	# just delete them, but later I'll have to find what causes them 
	# here I make a little KOCTblJlb, don't judge
	list2 = pricedlistsorted
	pricedlistsorted = []
	for item in list2:
		if item[2] == '':
			continue
		else:
			pricedlistsorted.append(item)