Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,7 +13,7 @@ import hvplot.pandas
|
|
| 13 |
|
| 14 |
import yfinance as yf
|
| 15 |
|
| 16 |
-
|
| 17 |
# from datasets import load_dataset
|
| 18 |
|
| 19 |
from utils import upload_to_hf_dataset, download_from_hf_dataset, load_hf_dataset
|
|
@@ -68,7 +68,7 @@ def get_text(df):
|
|
| 68 |
|
| 69 |
|
| 70 |
# Load environment variables from .env file
|
| 71 |
-
|
| 72 |
|
| 73 |
# Get the Hugging Face API token from the environment; either set in .env file or in the environment directly in GitHub
|
| 74 |
HF_TOKEN = os.getenv('HF_TOKEN')
|
|
@@ -97,7 +97,7 @@ def get_marketbeat(current_datetime):
|
|
| 97 |
@pn.cache()
|
| 98 |
def get_gurufocus(current_datetime):
|
| 99 |
#Rading gurufocus from github action pipeline
|
| 100 |
-
# daily_gurufocus_csvfile = f"https://raw.githubusercontent.com
|
| 101 |
# daily_gurufocus_DF = pd.read_csv(daily_gurufocus_csvfile)
|
| 102 |
# daily_gurufocus_DF = load_dataset(dataset_name_GuruFocus_output , data_files="GuruFocus_merged.csv", split="train" , token=HF_TOKEN ).to_pandas()
|
| 103 |
return load_hf_dataset("GuruFocus_merged.csv", HF_TOKEN, dataset_name_GuruFocus_input)
|
|
@@ -114,6 +114,7 @@ def get_tipranks(current_datetime):
|
|
| 114 |
#Reading gurufocus,finviz from local crawling pipeline; Need to update github action to merge gurufocus daily with monthly tiprank
|
| 115 |
daily_gurufocus_DF = get_gurufocus(current_datetime)
|
| 116 |
daily_finviz_DF = get_finviz(current_datetime)
|
|
|
|
| 117 |
monthly_tiprank_DF = get_tipranks(current_datetime)
|
| 118 |
monthly_tiprank_DF = monthly_tiprank_DF[['Ticker','SmartScore','Market Capitalization','Sector','Industry']]
|
| 119 |
|
|
@@ -130,6 +131,15 @@ DFmerge_tipranks_gurufocus = DFgurufocus.merge(monthly_tiprank_DF)
|
|
| 130 |
#Merging Finviz with Merged last one
|
| 131 |
DFmerge_tipranks_gurufocus = DFmerge_tipranks_gurufocus.merge(daily_finviz_DF_filtered)
|
| 132 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
if 'Price' in DFmerge_tipranks_gurufocus.columns and 'GFValue' in DFmerge_tipranks_gurufocus.columns:
|
| 134 |
DFmerge_tipranks_gurufocus['GFValuepercent'] = 100* ( DFmerge_tipranks_gurufocus['GFValue'] - DFmerge_tipranks_gurufocus['Price']) / DFmerge_tipranks_gurufocus['Price']
|
| 135 |
DFmerge_tipranks_gurufocus['GFValuepercent'] = DFmerge_tipranks_gurufocus['GFValuepercent'].round(2)
|
|
@@ -143,33 +153,52 @@ if 'Price' in DFmerge_tipranks_gurufocus.columns and 'GFValue' in DFmerge_tipran
|
|
| 143 |
ticker = pn.widgets.AutocompleteInput(name='Ticker', options=list(DFmerge_tipranks_gurufocus.Ticker) , placeholder='Write Ticker here همین جا',value='ALL', restrict=False)
|
| 144 |
SmartScore = pn.widgets.EditableRangeSlider(name='Smart Score', start=0, end=10, value=(9, 10), step=1)
|
| 145 |
Industry = pn.widgets.CheckBoxGroup( name='Select Industry', value=list(set(DFmerge_tipranks_gurufocus.Industry)), options=list(set(DFmerge_tipranks_gurufocus.Industry)), inline=True)
|
| 146 |
-
Sector = pn.widgets.
|
| 147 |
GFValuepercent = pn.widgets.FloatSlider(name='GF Value %', start=-100, end=100, step=1, value=12.0)
|
| 148 |
FinVizTargetpercent = pn.widgets.FloatSlider(name='FinViz Target %', start=-100, end=100, step=1, value=12.0)
|
| 149 |
MarketCap = pn.widgets.FloatSlider(name='Market Capital (B$)', start=0, end=1000, step=1, value=10)
|
|
|
|
|
|
|
| 150 |
# Create a file download link
|
| 151 |
download_button_GuruFocus = pn.widgets.FileDownload(
|
| 152 |
filename=f'GuruFocus_merged_{current_datetime}.csv',
|
| 153 |
callback=pn.bind(get_csv,daily_gurufocus_DF),
|
| 154 |
button_type='primary',
|
| 155 |
-
label='Download GuruFocus'
|
| 156 |
)
|
| 157 |
|
| 158 |
download_button_FinViz = pn.widgets.FileDownload(
|
| 159 |
filename=f'FinViz_{current_datetime}.csv',
|
| 160 |
callback=pn.bind(get_csv,daily_finviz_DF),
|
| 161 |
button_type='primary',
|
| 162 |
-
label='Download FinViz'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
)
|
| 164 |
|
| 165 |
png_pane = pn.pane.GIF('https://tuozi.vip/shqu/wordpress/wp-content/themes/CorePress/static/img/loading.gif', width=200) #, height=150)
|
| 166 |
-
def get_DF(DF,ticker,SmartScore,GFValuepercent, FinVizTargetpercent, Sector,MarketCap):
|
| 167 |
if ticker and ticker!="ALL":
|
| 168 |
table1 = pn.widgets.Tabulator(DF.query("Ticker == @ticker"), height=200, widths=200, show_index=False)
|
| 169 |
chart1 = make_candle_stick(ticker)
|
| 170 |
return pn.Column(table1,chart1)
|
| 171 |
else:
|
| 172 |
-
|
|
|
|
|
|
|
|
|
|
| 173 |
|
| 174 |
def get_DF_filter(DF,ticker,SmartScore,GFValuepercent, FinVizTargetpercent, Sector,MarketCap):
|
| 175 |
return DF.query("SmartScore>=@SmartScore[0] & SmartScore <= @SmartScore[1] & GFValuepercent>=@GFValuepercent & FinVizTargetpercent>@FinVizTargetpercent & Sector in @Sector & MarketCap>@MarketCap")
|
|
@@ -178,17 +207,18 @@ download_button_Filter = pn.widgets.FileDownload(
|
|
| 178 |
filename=f'Filter_{current_datetime}.csv',
|
| 179 |
callback=pn.bind(get_csv,pn.bind(get_DF_filter, DF=DFmerge_tipranks_gurufocus,ticker=ticker,SmartScore=SmartScore,GFValuepercent=GFValuepercent, FinVizTargetpercent=FinVizTargetpercent, Sector=Sector ,MarketCap=MarketCap) ),
|
| 180 |
button_type='danger',
|
| 181 |
-
label='Download your Filter'
|
|
|
|
| 182 |
)
|
| 183 |
|
| 184 |
download_button_watchlist = pn.widgets.FileDownload(
|
| 185 |
filename=f'watchlist_{current_datetime}.txt',
|
| 186 |
callback=pn.bind(get_text,pn.bind(get_DF_filter, DF=DFmerge_tipranks_gurufocus,ticker=ticker,SmartScore=SmartScore,GFValuepercent=GFValuepercent, FinVizTargetpercent=FinVizTargetpercent, Sector=Sector ,MarketCap=MarketCap) ),
|
| 187 |
button_type='success',
|
| 188 |
-
label='Download Watchlist'
|
| 189 |
)
|
| 190 |
|
| 191 |
pn.extension('tabulator')
|
| 192 |
-
bound_plot = pn.bind(get_DF, DF=DFmerge_tipranks_gurufocus,ticker=ticker,SmartScore=SmartScore,GFValuepercent=GFValuepercent, FinVizTargetpercent=FinVizTargetpercent, Sector=Sector ,MarketCap=MarketCap)
|
| 193 |
|
| 194 |
-
pn.Column(pn.Row(pn.Column(ticker,SmartScore,GFValuepercent, FinVizTargetpercent, MarketCap,
|
|
|
|
| 13 |
|
| 14 |
import yfinance as yf
|
| 15 |
|
| 16 |
+
from dotenv import load_dotenv
|
| 17 |
# from datasets import load_dataset
|
| 18 |
|
| 19 |
from utils import upload_to_hf_dataset, download_from_hf_dataset, load_hf_dataset
|
|
|
|
| 68 |
|
| 69 |
|
| 70 |
# Load environment variables from .env file
|
| 71 |
+
load_dotenv()
|
| 72 |
|
| 73 |
# Get the Hugging Face API token from the environment; either set in .env file or in the environment directly in GitHub
|
| 74 |
HF_TOKEN = os.getenv('HF_TOKEN')
|
|
|
|
| 97 |
@pn.cache()
|
| 98 |
def get_gurufocus(current_datetime):
|
| 99 |
#Rading gurufocus from github action pipeline
|
| 100 |
+
# daily_gurufocus_csvfile = f"https://raw.githubusercontent.com/alirezax2/GurusFocusCrawl/main/gurufocusuruFocus_merged_{current_datetime}.csv"
|
| 101 |
# daily_gurufocus_DF = pd.read_csv(daily_gurufocus_csvfile)
|
| 102 |
# daily_gurufocus_DF = load_dataset(dataset_name_GuruFocus_output , data_files="GuruFocus_merged.csv", split="train" , token=HF_TOKEN ).to_pandas()
|
| 103 |
return load_hf_dataset("GuruFocus_merged.csv", HF_TOKEN, dataset_name_GuruFocus_input)
|
|
|
|
| 114 |
#Reading gurufocus,finviz from local crawling pipeline; Need to update github action to merge gurufocus daily with monthly tiprank
|
| 115 |
daily_gurufocus_DF = get_gurufocus(current_datetime)
|
| 116 |
daily_finviz_DF = get_finviz(current_datetime)
|
| 117 |
+
daily_marketbeat = get_marketbeat(current_datetime)
|
| 118 |
monthly_tiprank_DF = get_tipranks(current_datetime)
|
| 119 |
monthly_tiprank_DF = monthly_tiprank_DF[['Ticker','SmartScore','Market Capitalization','Sector','Industry']]
|
| 120 |
|
|
|
|
| 131 |
#Merging Finviz with Merged last one
|
| 132 |
DFmerge_tipranks_gurufocus = DFmerge_tipranks_gurufocus.merge(daily_finviz_DF_filtered)
|
| 133 |
|
| 134 |
+
print(daily_marketbeat.columns)
|
| 135 |
+
# ['Ticker', 'AverageTarget', 'MaxTarget', 'LowTarget', 'CurrentPrice']
|
| 136 |
+
daily_marketbeat['AllTargetsAbovePrice'] = ((daily_marketbeat['MaxTarget'] > daily_marketbeat['CurrentPrice']) &
|
| 137 |
+
(daily_marketbeat['LowTarget'] > daily_marketbeat['CurrentPrice']) &
|
| 138 |
+
(daily_marketbeat['AverageTarget'] > daily_marketbeat['CurrentPrice'])).astype(int)
|
| 139 |
+
|
| 140 |
+
#Merging daily_marketbeat with Merged last one
|
| 141 |
+
DFmerge_tipranks_gurufocus = DFmerge_tipranks_gurufocus.merge(daily_marketbeat)
|
| 142 |
+
|
| 143 |
if 'Price' in DFmerge_tipranks_gurufocus.columns and 'GFValue' in DFmerge_tipranks_gurufocus.columns:
|
| 144 |
DFmerge_tipranks_gurufocus['GFValuepercent'] = 100* ( DFmerge_tipranks_gurufocus['GFValue'] - DFmerge_tipranks_gurufocus['Price']) / DFmerge_tipranks_gurufocus['Price']
|
| 145 |
DFmerge_tipranks_gurufocus['GFValuepercent'] = DFmerge_tipranks_gurufocus['GFValuepercent'].round(2)
|
|
|
|
| 153 |
ticker = pn.widgets.AutocompleteInput(name='Ticker', options=list(DFmerge_tipranks_gurufocus.Ticker) , placeholder='Write Ticker here همین جا',value='ALL', restrict=False)
|
| 154 |
SmartScore = pn.widgets.EditableRangeSlider(name='Smart Score', start=0, end=10, value=(9, 10), step=1)
|
| 155 |
Industry = pn.widgets.CheckBoxGroup( name='Select Industry', value=list(set(DFmerge_tipranks_gurufocus.Industry)), options=list(set(DFmerge_tipranks_gurufocus.Industry)), inline=True)
|
| 156 |
+
Sector = pn.widgets.MultiSelect( name='Select Sector', value=list(set(DFmerge_tipranks_gurufocus.Sector)), options=list(set(DFmerge_tipranks_gurufocus.Sector)) )#, inline=False)
|
| 157 |
GFValuepercent = pn.widgets.FloatSlider(name='GF Value %', start=-100, end=100, step=1, value=12.0)
|
| 158 |
FinVizTargetpercent = pn.widgets.FloatSlider(name='FinViz Target %', start=-100, end=100, step=1, value=12.0)
|
| 159 |
MarketCap = pn.widgets.FloatSlider(name='Market Capital (B$)', start=0, end=1000, step=1, value=10)
|
| 160 |
+
MarketBeat_radio_group = pn.widgets.RadioButtonGroup(name='MarketBeat', options=['Default', 'Above all Targets'], button_type='success')
|
| 161 |
+
|
| 162 |
# Create a file download link
|
| 163 |
download_button_GuruFocus = pn.widgets.FileDownload(
|
| 164 |
filename=f'GuruFocus_merged_{current_datetime}.csv',
|
| 165 |
callback=pn.bind(get_csv,daily_gurufocus_DF),
|
| 166 |
button_type='primary',
|
| 167 |
+
label='Download GuruFocus', width=250
|
| 168 |
)
|
| 169 |
|
| 170 |
download_button_FinViz = pn.widgets.FileDownload(
|
| 171 |
filename=f'FinViz_{current_datetime}.csv',
|
| 172 |
callback=pn.bind(get_csv,daily_finviz_DF),
|
| 173 |
button_type='primary',
|
| 174 |
+
label='Download FinViz', width=250
|
| 175 |
+
)
|
| 176 |
+
|
| 177 |
+
download_button_MarketBeat = pn.widgets.FileDownload(
|
| 178 |
+
filename=f'MarketBeat_{current_datetime}.csv',
|
| 179 |
+
callback=pn.bind(get_csv,daily_marketbeat),
|
| 180 |
+
button_type='warning',
|
| 181 |
+
label='Download MarketBeat', width=250
|
| 182 |
+
)
|
| 183 |
+
|
| 184 |
+
download_button_TipRanks = pn.widgets.FileDownload(
|
| 185 |
+
filename=f'TipRanks_{current_datetime}.csv',
|
| 186 |
+
callback=pn.bind(get_csv,monthly_tiprank_DF),
|
| 187 |
+
button_type='warning',
|
| 188 |
+
label='Download TipRanks', width=250
|
| 189 |
)
|
| 190 |
|
| 191 |
png_pane = pn.pane.GIF('https://tuozi.vip/shqu/wordpress/wp-content/themes/CorePress/static/img/loading.gif', width=200) #, height=150)
|
| 192 |
+
def get_DF(DF,ticker,SmartScore,GFValuepercent, FinVizTargetpercent, Sector,MarketCap,MarketBeat):
|
| 193 |
if ticker and ticker!="ALL":
|
| 194 |
table1 = pn.widgets.Tabulator(DF.query("Ticker == @ticker"), height=200, widths=200, show_index=False)
|
| 195 |
chart1 = make_candle_stick(ticker)
|
| 196 |
return pn.Column(table1,chart1)
|
| 197 |
else:
|
| 198 |
+
if MarketBeat == 0:
|
| 199 |
+
return pn.widgets.Tabulator( DF.query("SmartScore>=@SmartScore[0] & SmartScore <= @SmartScore[1] & GFValuepercent>=@GFValuepercent & FinVizTargetpercent>@FinVizTargetpercent & Sector in @Sector & MarketCap>@MarketCap & AllTargetsAbovePrice==1"), height=800, widths=200, show_index=False ,theme='modern')
|
| 200 |
+
else:
|
| 201 |
+
return pn.widgets.Tabulator( DF.query("SmartScore>=@SmartScore[0] & SmartScore <= @SmartScore[1] & GFValuepercent>=@GFValuepercent & FinVizTargetpercent>@FinVizTargetpercent & Sector in @Sector & MarketCap>@MarketCap"), height=800, widths=200, show_index=False ,theme='modern')
|
| 202 |
|
| 203 |
def get_DF_filter(DF,ticker,SmartScore,GFValuepercent, FinVizTargetpercent, Sector,MarketCap):
|
| 204 |
return DF.query("SmartScore>=@SmartScore[0] & SmartScore <= @SmartScore[1] & GFValuepercent>=@GFValuepercent & FinVizTargetpercent>@FinVizTargetpercent & Sector in @Sector & MarketCap>@MarketCap")
|
|
|
|
| 207 |
filename=f'Filter_{current_datetime}.csv',
|
| 208 |
callback=pn.bind(get_csv,pn.bind(get_DF_filter, DF=DFmerge_tipranks_gurufocus,ticker=ticker,SmartScore=SmartScore,GFValuepercent=GFValuepercent, FinVizTargetpercent=FinVizTargetpercent, Sector=Sector ,MarketCap=MarketCap) ),
|
| 209 |
button_type='danger',
|
| 210 |
+
label='Download your Filter', width=250
|
| 211 |
+
|
| 212 |
)
|
| 213 |
|
| 214 |
download_button_watchlist = pn.widgets.FileDownload(
|
| 215 |
filename=f'watchlist_{current_datetime}.txt',
|
| 216 |
callback=pn.bind(get_text,pn.bind(get_DF_filter, DF=DFmerge_tipranks_gurufocus,ticker=ticker,SmartScore=SmartScore,GFValuepercent=GFValuepercent, FinVizTargetpercent=FinVizTargetpercent, Sector=Sector ,MarketCap=MarketCap) ),
|
| 217 |
button_type='success',
|
| 218 |
+
label='Download Watchlist', width=250
|
| 219 |
)
|
| 220 |
|
| 221 |
pn.extension('tabulator')
|
| 222 |
+
bound_plot = pn.bind(get_DF, DF=DFmerge_tipranks_gurufocus,ticker=ticker,SmartScore=SmartScore,GFValuepercent=GFValuepercent, FinVizTargetpercent=FinVizTargetpercent, Sector=Sector ,MarketCap=MarketCap,MarketBeat=MarketBeat_radio_group)
|
| 223 |
|
| 224 |
+
pn.Column(pn.Row(pn.Column(ticker,SmartScore,GFValuepercent, FinVizTargetpercent, MarketCap, MarketBeat_radio_group, png_pane, download_button_GuruFocus,download_button_FinViz , download_button_MarketBeat, download_button_TipRanks, download_button_Filter, download_button_watchlist),bound_plot)).servable(title="Fair Value Ranking - Merged Gurufocus & Tipranks & FinViz & MorningStars")
|