def price(request): if not request.user.is_superuser: profile = UserProfile.objects.get(user=request.user) calls = profile.calls if profile.get_remaining() > 0: profile.calls += 1 profile.save() else: return redirect('purchase.html') else: calls = 0 model = str(request.GET.get('model','laplace')) days = int(request.GET.get('days', '')) strike = float(request.GET.get('strike', '')) ticker = request.GET.get('ticker', '').upper() putcall = request.GET.get('type', '') f = futurePrice.futurePrice(request.GET.get('ticker', '')) x = 0 for i in range(ITERATIONS): x = x + futurePrice.price(f, days, strike, putcall[0], model) value = x / ITERATIONS response_data = {'ticker': str(ticker), 'days': str(days), 'strike': str(strike), 'type': putcall, 'price': round(value, 3), 'calls': calls} return JsonResponse(response_data)
import time from monte.futurePrice import futurePrice, price from multiprocessing import Pool TICKER = 'GOOGL' ITERATIONS = 200 RUNS = 5 f = futurePrice(TICKER) def parPrice(i): return price(*i) def par(): p = Pool(4) print(sum(p.map(parPrice, [(f, 100, 780) for i in range(ITERATIONS)])) / ITERATIONS) def loop(): x = 0 for i in range(ITERATIONS): x = x + price(f, 100, 780) print(x / ITERATIONS) def gen(): print(sum([price(f, 100, 780) for i in range(ITERATIONS)]) / ITERATIONS)