Lirsen Myrtaj
Update app.py (#5)
bd2abfa
raw
history blame
4.9 kB
import streamlit as st
from datetime import date, timedelta
#from rest_api.fetch_data import (get_symbol_data)
import pandas as pd
from plots import (
beta,
basic_portfolio,
# display_portfolio_return,
display_heat_map,
#circle_packing,
ER,
buble_interactive
)
### Koi
from ef import(
ef_viz
)
####
def load_heading():
"""The function that displays the heading.
Provides instructions to the user
"""
with st.container():
st.title('Dataminers')
header = st.subheader('This App performs historical portfolio analysis and future analysis ')
st.subheader('Please read the instructions carefully and enjoy!')
# st.text('This is some text.')
def get_choices():
"""Prompts the dialog to get the All Choices.
Returns:
An object of choices and an object of combined dataframes.
"""
choices = {}
tickers = st.sidebar.text_input('Enter 4 stock symbols.', 'GOOG,A,AA,AMD')
# Set the weights
weights_str = st.sidebar.text_input('Enter The Investment Quantities', '50,30,25,25')
# Set Initial Investment
investment = st.sidebar.number_input('Enter The Initial Investment', min_value=5000, max_value=25000, value=5000)
# Every form must have a submit button.
submitted = st.sidebar.button("Submit")
symbols = []
reset = False
# Reusable Error Button DRY!
#def reset_app(error):
# st.sidebar.write(f"{error}!")
# st.sidebar.write(f"Check The Syntax")
# reset = st.sidebar.button("RESET APP")
if submitted:
# convert strings to lists
tickers_list = tickers.split(",")
weights_list = weights_str.split(",")
#crypto_symbols_list = crypto_symbols.split(",")
# Create the Symbols List
symbols.extend(tickers_list)
#symbols.extend(crypto_symbols_list)
# Convert Weights To Decimals
weights = []
for item in weights_list:
weights.append(float(item))
if reset:
# # Clears all singleton caches:
tickers = st.sidebar.selectbox('Enter 11 stock symbols.', ('GOOG','D','AAP','BLK'))
# crypto_symbols = st.sidebar.text_input('Enter 2 crypto symbols only as below', 'BTC-USD,ETH-USD')
weights_str = st.sidebar.text_input('Enter The Investment Weights', '0.3,0.3 ,0.3')
st.experimental_singleton.clear()
else:
# Submit an object with choices
choices = {
'symbols': symbols,
'weights': weights,
'investment': investment
}
# Load combined_df
data = pd.read_csv('data_and_sp500.csv')
combined_df = data[tickers_list]
# return object of objects
return {
'choices': choices,
'combined_df': combined_df,
'data': data
}
def run():
"""The main function for running the script."""
load_heading()
choices = get_choices()
if choices:
st.success('''** Selected Tickers **''')
buble_interactive(choices['data'],choices['choices'])
st.header('Tickers Beta')
"""
The Capital Asset Pricing Model (CAPM) utilizes a formula to enable the application to calculate
risk, return, and variability of return with respect to a benchmark. The application uses this
benchmark, currently S&P 500 annual rate of return, to calculate the return of a stock using
Figure 2 in Appendix A. Elements such as beta can be calculated using the formula in Appendix
A Figure 1. The beta variable will serve as a variable to be used for calculating the variability of
the stock with respect to the benchmark. This variability factor will prove useful for a variety of
calculations such as understanding market risk and return. If the beta is equal to 1.0, the stock
price is correlated with the market. When beta is smaller than 1.0, the stock is less volatile than
the market. If beta is greater than 1.0, the stock is more volatile than the market.
The CAPM model was run for 9 stocks, using 10-year daily historical data for initial test analysis.
With this initial analysis, beta was calculated to determine the stock’s risk by measuring the
price changes to the benchmark. By using CAPM model, annual expected return and portfolio
return is calculated. The model results can be found in Appendix A.
"""
##### EDIT HERE ##### koi
ef_viz(choices['data'],choices['choices'])
##### #####
beta(choices['data'], choices['choices'])
ER(choices['data'], choices['choices'])
basic_portfolio(choices['combined_df'])
display_heat_map(choices['combined_df'])
#display_portfolio_return(choices['combined_df'], choices['choices'])
if __name__ == "__main__":
run()