Spaces:
Runtime error
Runtime error
Commit
·
0fbe3a8
1
Parent(s):
fb9dac7
changes:
Browse files- .env +3 -0
- .vscode/launch.json +20 -0
- README.md +2 -0
- app.py +63 -2
- requirements.txt +5 -0
- subs/access_backend.py +43 -0
- toml/config.prod.toml +125 -0
- toml/credentials.prod.toml +3 -0
.env
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
PYTHONPATH=.
|
| 2 |
+
HOST=https://dax-backend.arthought.com
|
| 3 |
+
# financebackend:8000
|
.vscode/launch.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
// Use IntelliSense to learn about possible attributes.
|
| 3 |
+
// Hover to view descriptions of existing attributes.
|
| 4 |
+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
| 5 |
+
"version": "0.2.0",
|
| 6 |
+
"configurations": [
|
| 7 |
+
{
|
| 8 |
+
"name": "Python: Current File",
|
| 9 |
+
"type": "python",
|
| 10 |
+
"request": "launch",
|
| 11 |
+
"module": "streamlit",
|
| 12 |
+
"args": [
|
| 13 |
+
"run",
|
| 14 |
+
"app.py"
|
| 15 |
+
],
|
| 16 |
+
"console": "integratedTerminal",
|
| 17 |
+
"justMyCode": true
|
| 18 |
+
}
|
| 19 |
+
]
|
| 20 |
+
}
|
README.md
CHANGED
|
@@ -11,3 +11,5 @@ license: apache-2.0
|
|
| 11 |
---
|
| 12 |
|
| 13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
|
|
|
| 11 |
---
|
| 12 |
|
| 13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
| 14 |
+
|
| 15 |
+
The code is derived from https://github.com/hfwittmann/financial-timeseries-dashboard/tree/kedro-based
|
app.py
CHANGED
|
@@ -1,4 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from datetime import date
|
| 2 |
+
import json
|
| 3 |
+
import plotly
|
| 4 |
+
from re import sub
|
| 5 |
+
from plotly import graph_objects as go
|
| 6 |
+
|
| 7 |
import streamlit as st
|
| 8 |
|
| 9 |
+
st.set_page_config(layout="wide")
|
| 10 |
+
|
| 11 |
+
from subs.access_backend import get_tickerlist
|
| 12 |
+
from subs.access_backend import get_plot
|
| 13 |
+
|
| 14 |
+
tickerTable = get_tickerlist().set_index("Ticker")
|
| 15 |
+
|
| 16 |
+
PrimeStandardSector = "Prime Standard Sector"
|
| 17 |
+
sectors = tickerTable[PrimeStandardSector].unique()
|
| 18 |
+
sectors.sort()
|
| 19 |
+
sector = st.selectbox(
|
| 20 |
+
label="Select a Sector. Remark: This sets the default for the selected stocks",
|
| 21 |
+
options=sectors,
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
default_index = tickerTable[PrimeStandardSector] == sector
|
| 25 |
+
|
| 26 |
+
default = tickerTable[default_index]
|
| 27 |
+
|
| 28 |
+
selections = st.multiselect(
|
| 29 |
+
label="Dax Constituents",
|
| 30 |
+
options=list(tickerTable.index),
|
| 31 |
+
format_func=lambda x: tickerTable.at[x, "Company"],
|
| 32 |
+
default=list(default.index),
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
for selection in selections:
|
| 36 |
+
|
| 37 |
+
try:
|
| 38 |
+
|
| 39 |
+
fig_scatter = get_plot(selection, "scatter")
|
| 40 |
+
fig_returns = get_plot(selection, "returns")
|
| 41 |
+
fig_histogram = get_plot(selection, "histogram")
|
| 42 |
+
|
| 43 |
+
st.header(tickerTable.at[selection, "Company"])
|
| 44 |
+
c1, _, c2, _, c3 = st.columns((10, 1, 10, 1, 10))
|
| 45 |
+
|
| 46 |
+
c1.plotly_chart(fig_scatter, use_container_width=True)
|
| 47 |
+
c2.plotly_chart(fig_returns, use_container_width=True)
|
| 48 |
+
c3.plotly_chart(fig_histogram, use_container_width=True)
|
| 49 |
+
|
| 50 |
+
except Exception as e:
|
| 51 |
+
st.header(tickerTable.at[selection, "Company"])
|
| 52 |
+
st.markdown(
|
| 53 |
+
f"Data for {tickerTable.at[selection, 'Company']} not available",
|
| 54 |
+
unsafe_allow_html=False,
|
| 55 |
+
)
|
| 56 |
+
# print(selection)
|
| 57 |
+
# print(e)
|
| 58 |
+
|
| 59 |
+
if __name__ == "__main__":
|
| 60 |
+
print(tickerTable)
|
| 61 |
+
print(tickerTable.index[:3])
|
| 62 |
+
|
| 63 |
+
print(sectors)
|
| 64 |
+
print(tickerTable["Prime Standard Sector"] == sector)
|
| 65 |
+
print(default)
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pandas=="^1.5.3"
|
| 2 |
+
lxml=="^4.9.2"
|
| 3 |
+
pandas-datareader=="^0.10.0"
|
| 4 |
+
environs=="^9.5.0"
|
| 5 |
+
plotly=="^5.13.1"
|
subs/access_backend.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# from subs.orderdict import orderByValue
|
| 2 |
+
import requests
|
| 3 |
+
import json
|
| 4 |
+
import streamlit as st
|
| 5 |
+
import pandas as pd
|
| 6 |
+
|
| 7 |
+
from environs import Env
|
| 8 |
+
|
| 9 |
+
env = Env()
|
| 10 |
+
env.read_env()
|
| 11 |
+
|
| 12 |
+
# @st.cache
|
| 13 |
+
def get_tickerlist():
|
| 14 |
+
|
| 15 |
+
response = requests.get(f"{env('HOST')}/Tickerlist_provider?datatype=tickerlist")
|
| 16 |
+
|
| 17 |
+
response_json = response.json()
|
| 18 |
+
|
| 19 |
+
companyTicker = pd.read_json(response_json["myData"])
|
| 20 |
+
|
| 21 |
+
return companyTicker
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
# @st.cache
|
| 25 |
+
def get_plot(selection: str, plottype: str):
|
| 26 |
+
|
| 27 |
+
assert plottype in ["scatter", "returns", "histogram"]
|
| 28 |
+
|
| 29 |
+
response = requests.get(
|
| 30 |
+
f"{env('HOST')}/Stockticker_provider?plottype={plottype}&selection={selection}"
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
blub = response.json()
|
| 34 |
+
|
| 35 |
+
fig = json.loads(blub["plot"])
|
| 36 |
+
|
| 37 |
+
return fig
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
if __name__ == "__main__":
|
| 41 |
+
print(get_tickerlist())
|
| 42 |
+
|
| 43 |
+
print(get_plot("ADS.DE", "scatter"))
|
toml/config.prod.toml
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Below are all the sections and options you can have in ~/.streamlit/config.toml.
|
| 2 |
+
|
| 3 |
+
[global]
|
| 4 |
+
|
| 5 |
+
# By default, Streamlit checks if the Python watchdog module is available and, if not, prints a warning asking for you to install it. The watchdog module is not required, but highly recommended. It improves Streamlit's ability to detect changes to files in your filesystem.
|
| 6 |
+
# If you'd like to turn off this warning, set this to True.
|
| 7 |
+
# Default: false
|
| 8 |
+
disableWatchdogWarning = false
|
| 9 |
+
|
| 10 |
+
# Configure the ability to share apps to the cloud.
|
| 11 |
+
# Should be set to one of these values: - "off" : turn off sharing. - "s3" : share to S3, based on the settings under the [s3] section of this config file.
|
| 12 |
+
# Default: "off"
|
| 13 |
+
sharingMode = "off"
|
| 14 |
+
|
| 15 |
+
# If True, will show a warning when you run a Streamlit-enabled script via "python my_script.py".
|
| 16 |
+
# Default: true
|
| 17 |
+
showWarningOnDirectExecution = true
|
| 18 |
+
|
| 19 |
+
# Level of logging: 'error', 'warning', 'info', or 'debug'.
|
| 20 |
+
# Default: 'info'
|
| 21 |
+
logLevel = "debug"
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
[client]
|
| 25 |
+
|
| 26 |
+
# Whether to enable st.cache.
|
| 27 |
+
# Default: true
|
| 28 |
+
caching = true
|
| 29 |
+
|
| 30 |
+
# If false, makes your Streamlit script not draw to a Streamlit app.
|
| 31 |
+
# Default: true
|
| 32 |
+
displayEnabled = true
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
[runner]
|
| 36 |
+
|
| 37 |
+
# Allows you to type a variable or string by itself in a single line of Python code to write it to the app.
|
| 38 |
+
# Default: true
|
| 39 |
+
magicEnabled = true
|
| 40 |
+
|
| 41 |
+
# Install a Python tracer to allow you to stop or pause your script at any point and introspect it. As a side-effect, this slows down your script's execution.
|
| 42 |
+
# Default: false
|
| 43 |
+
installTracer = false
|
| 44 |
+
|
| 45 |
+
# Sets the MPLBACKEND environment variable to Agg inside Streamlit to prevent Python crashing.
|
| 46 |
+
# Default: true
|
| 47 |
+
fixMatplotlib = true
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
[server]
|
| 51 |
+
|
| 52 |
+
# List of folders that should not be watched for changes. Relative paths will be taken as relative to the current working directory.
|
| 53 |
+
# Example: ['/home/user1/env', 'relative/path/to/folder']
|
| 54 |
+
# Default: []
|
| 55 |
+
folderWatchBlacklist = ['']
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
# If false, will attempt to open a browser window on start.
|
| 59 |
+
# Default: false unless (1) we are on a Linux box where DISPLAY is unset, or (2) server.liveSave is set.
|
| 60 |
+
headless = true
|
| 61 |
+
|
| 62 |
+
# Immediately share the app in such a way that enables live monitoring, and post-run analysis.
|
| 63 |
+
# Default: false
|
| 64 |
+
liveSave = false
|
| 65 |
+
|
| 66 |
+
# Automatically rerun script when the file is modified on disk.
|
| 67 |
+
# Default: false
|
| 68 |
+
runOnSave = false
|
| 69 |
+
|
| 70 |
+
# The port where the server will listen for client and browser connections.
|
| 71 |
+
# Default: 8501
|
| 72 |
+
port = 8501
|
| 73 |
+
|
| 74 |
+
# Enables support for Cross-Origin Request Sharing, for added security.
|
| 75 |
+
# Default: true
|
| 76 |
+
enableCORS = false
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
[browser]
|
| 80 |
+
|
| 81 |
+
# Internet address of the server server that the browser should connect to. Can be IP address or DNS name.
|
| 82 |
+
# Default: 'env("HOST")'
|
| 83 |
+
serverAddress = "0.0.0.0"
|
| 84 |
+
|
| 85 |
+
# Whether to send usage statistics to Streamlit.
|
| 86 |
+
# Default: true
|
| 87 |
+
gatherUsageStats = true
|
| 88 |
+
|
| 89 |
+
# Port that the browser should use to connect to the server when in liveSave mode.
|
| 90 |
+
# Default: whatever value is set in server.port.
|
| 91 |
+
serverPort = 8501
|
| 92 |
+
|
| 93 |
+
[s3]
|
| 94 |
+
|
| 95 |
+
# Name of the AWS S3 bucket to save apps.
|
| 96 |
+
# Default: (unset)
|
| 97 |
+
#bucket =
|
| 98 |
+
|
| 99 |
+
# URL root for external view of Streamlit apps.
|
| 100 |
+
# Default: (unset)
|
| 101 |
+
#url =
|
| 102 |
+
|
| 103 |
+
# Access key to write to the S3 bucket.
|
| 104 |
+
# Leave unset if you want to use an AWS profile.
|
| 105 |
+
# Default: (unset)
|
| 106 |
+
#accessKeyId =
|
| 107 |
+
|
| 108 |
+
# Secret access key to write to the S3 bucket.
|
| 109 |
+
# Leave unset if you want to use an AWS profile.
|
| 110 |
+
# Default: (unset)
|
| 111 |
+
#secretAccessKey =
|
| 112 |
+
|
| 113 |
+
# The "subdirectory" within the S3 bucket where to save apps.
|
| 114 |
+
# S3 calls paths "keys" which is why the keyPrefix is like a subdirectory. Use "" to mean the root directory.
|
| 115 |
+
# Default: ""
|
| 116 |
+
keyPrefix = ""
|
| 117 |
+
|
| 118 |
+
# AWS region where the bucket is located, e.g. "us-west-2".
|
| 119 |
+
# Default: (unset)
|
| 120 |
+
#region =
|
| 121 |
+
|
| 122 |
+
# AWS credentials profile to use.
|
| 123 |
+
# Leave unset to use your default profile.
|
| 124 |
+
# Default: (unset)
|
| 125 |
+
#profile =
|
toml/credentials.prod.toml
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[general]
|
| 2 |
+
|
| 3 |
+
email=""
|