-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
40 lines (30 loc) · 1.16 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from flask import Flask, render_template, jsonify
from flask.ext.script import Manager
from flask.ext.bootstrap import Bootstrap
import numpy as np
import asset_sim
app = Flask(__name__)
manager = Manager(app)
bootstrap = Bootstrap(app)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/asset_sim/api/v1.0/random/', defaults={'draws': 10})
@app.route('/asset_sim/api/v1.0/random/<int:draws>', methods=["GET"])
def random_nums(draws):
"""
Generates an arbitrary number of IID draws from the standard normal
distibution and returns them as a JSON object.
"""
return jsonify(dict(enumerate(np.random.standard_normal(draws))))
@app.route('/asset_sim/api/v1.0/wiener', defaults={'sample': 100})
@app.route('/asset_sim/api/v1.0/wiener/<int:sample>', methods=["GET"])
def wiener(sample):
return jsonify(asset_sim.wiener(sample))
@app.route('/asset_sim/api/v1.0/gbm', defaults={'sample': 100, 'price': 100})
@app.route('/asset_sim/api/v1.0/gbm/<int:sample>/<float:price>',
methods=["GET"])
def gbm(sample, price):
return jsonify(asset_sim.geom_bm(S0=price, N=sample))
if __name__ == '__main__':
manager.run()