Download app.py from quantit/finter: direct link, hf CLI and curl.
- Browser
- Download file 1.89 kB
-
https://huggingface.co/spaces/quantit/finter/resolve/main/app.py
- Command line
-
hf download hf://spaces/quantit/finter/app.py
-
curl -L -o app.py https://huggingface.co/spaces/quantit/finter/resolve/main/app.py
1.89 kB
| import dotenv | |
| import gradio as gr | |
| import pandas as pd | |
| import plotly.express as px | |
| from finter.data import ModelData | |
| from finter.framework_model import BaseAlpha | |
| # .env ํ์ผ์์ ํ๊ฒฝ ๋ณ์ ๋ก๋ | |
| dotenv.load_dotenv(dotenv.find_dotenv()) | |
| END = 20240401 | |
| def plot_sector_area_chart(model_name): | |
| df = ModelData.load(model_name) | |
| df.columns = df.columns.astype(int) | |
| sector = BaseAlpha.get_cm( | |
| "content.handa.dataguide.company.krx-spot-sector.1d" | |
| ).get_df(20190101, END) | |
| sector_list = set(sector.unstack().dropna()) | |
| def get_sector(sector_name): | |
| return (df[sector == sector_name]).sum(axis=1).rename(sector_name) | |
| weight = pd.concat([get_sector(sector_name) for sector_name in sector_list], axis=1) | |
| weight = pd.concat( | |
| [ | |
| weight, | |
| df[sector.reindex(columns=df.columns).isna()].sum(axis=1).rename("Etc"), | |
| ], | |
| axis=1, | |
| ) | |
| df_long = weight.reset_index().melt( | |
| id_vars="index", var_name="Category", value_name="Value" | |
| ) | |
| df_long.rename(columns={"index": "Date"}, inplace=True) | |
| fig = px.area( | |
| df_long, | |
| x="Date", | |
| y="Value", | |
| color="Category", | |
| title="Time Series Area Chart for Industry Sectors", | |
| ) | |
| return fig | |
| if __name__ == "__main__": | |
| with gr.Blocks() as app: | |
| gr.Markdown( | |
| "**Explore the Source Code: [Click Here!](https://quantit.gitbook.io/finter/v/cook-book)**" | |
| ) | |
| with gr.Row(): | |
| model_input = gr.Textbox( | |
| value="alpha.krx.krx.stock.ldh0127.div_2", label="Enter model name" | |
| ) | |
| submit_button = gr.Button("Plot Chart") | |
| chart_output = gr.Plot() | |
| submit_button.click( | |
| fn=plot_sector_area_chart, inputs=model_input, outputs=chart_output | |
| ) | |
| app.launch(server_name="0.0.0.0", server_port=7860) | |