File size: 1,301 Bytes
9032234
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71385e9
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, jsonify, render_template
import yfinance as yf
import numpy as np
from datetime import datetime
import time

app = Flask(__name__)

@app.route('/')
def index():
    return render_template('index.html')

@app.route('/fetch-stock-data')
def fetch_stock_data():
    end_date = datetime.now().strftime('%Y-%m-%d')
    sharpe_threshold = 0.04
    top_ten_tickers = ['AAPL', 'MSFT', 'GOOGL', 'AMZN', 'FB', 'TSLA', 'JPM', 'BAC', 'WMT', 'V']

    sharpe_ratios = []

    # Simulating a delay to demonstrate progress
    total_tasks = len(top_ten_tickers)
    for i, ticker_symbol in enumerate(top_ten_tickers):
        time.sleep(1)  # Simulate a delay of 1 second (adjust for real data retrieval)
        
        # Simulated progress update
        progress = int((i + 1) / total_tasks * 100)
        print(f"Progress: {progress}%")

        # Rest of your code to fetch data, calculate Sharpe ratio, and append to sharpe_ratios

    # Once all tasks are completed, return the results
    sorted_sharpe_ratios = sorted(sharpe_ratios, key=lambda x: x[1], reverse=True)
    top_ten = [{'Ticker': ticker, 'Sharpe Ratio': ratio} for ticker, ratio in sorted_sharpe_ratios[:10]]

    return jsonify({'top_ten_sharpe_ratios': top_ten})

if __name__ == '__main__':
    app.run(debug=True)