0

So id like to make varibles from my function input

So basically, the if statement should check if the varible is True or not. And i want to use the function input + ”-outcome” to check.

Function-outcome = True
Function2-outcome = False
c
def a(B):
 Global c
 If f’{B}-outcome’ == True:
  Print(”yes”)
 Else:
  Print(”no”)
a(”function”)
a(”function2”)

Here is an example, to make you understand my problem better!

I’ve tried to find a solution but don’t find it anywhere

Thanks!

1 Answers1

0
import yfinance as yf
from datetime import date
import pandas as pd

d_start = '2022-01-01'
d_end = date.today().strftime('%Y-%m-%d')

#top50 S&P to create a list, if you will use a variable from an API you will just need to declare it as a string
#you can create a list of your fav ones and it will work the same, I grabbed from this site because it was the top 50 easy to get
tl = pd.read_html('https://dailypik.com/top-50-companies-sp-500/')[0]['Symbol'].to_list()

def main(l, d_start, d_end):

#I used the download function here, you will use the one that will fulfill your aim, analysis, actions, balance_sheet
#for isntance df = yf.earnings
df = yf.download(str(l), start=d_start, end=d_end)
#you can't assign a variable with a fstring, the work around is name the df opening opportunities later on
df.name = l

return df

df_list = [main(k, d_start, d_end) for k in tl]
di_ticks = {k:v for k,v in zip([df_list[i].name for i in range(0, len(df_list))], df_list)}
#here you can pass any tick that you have in the tl(tick list)
di_ticks['MSFT']

MSFT

ReinholdN
  • 526
  • 5
  • 22
  • Not exactly , i understand the syntxaes well, I’ve built a bot using yahoo finance, so every f string contains the symbol+openos like f’{a}openpos. So basically i want to se if that ticker is openpos == true or openpos== false. I can put every ticker in manually, but it would be easier if the f string could use the input from the function to se what ticker and then look at the variables to se if openpos==true or false. Say apple for example, then it would check If AAPLopenpos==True or false. But i use over 20 tickers so i have varibles for all of them. If you understand what i mean – Simon Olsson Nov 12 '22 at 02:01
  • In this case you create a list from teh tick column and pass use == with pandas. I still think that you like some basics, doing a bot or not. – ReinholdN Nov 12 '22 at 02:09
  • what format you get from what you are looking to compare? Do you use pandas, or an API? – ReinholdN Nov 12 '22 at 02:12
  • I can upload some of the code later to make it more clear. Basically i have a main function that runs with alot of tickers for example main(“aapl”). I also have a variable called aaplopen, so i run main(“aapl”) then if aaplopen==True, do this else do this. I do all this in a while loop for every ticker so i do While True: main(“aapl”) main(“meta”) and so on with alot of tickers in an infinite loop. I hope i am clear, maybe not, but i can upload more code tomorrow, sorry that I’m bad at explaining :) – Simon Olsson Nov 12 '22 at 02:18
  • Right now im using yahoos api to get the data, i dont store the data in a df – Simon Olsson Nov 12 '22 at 02:19
  • No I got it. If you share the code I surely can help you out, I have done a lot of ETLs and they pretty much follow the same logic. Is it Flask you are using? – ReinholdN Nov 12 '22 at 02:21
  • Will do that! Thanks alot!:) – Simon Olsson Nov 12 '22 at 02:32
  • Hello! Just sent it in for approval – Simon Olsson Nov 13 '22 at 19:55
  • @SimonOlsson Lets get into the same page. I need to get your intent here to help you out `Aktie_A = yf.Ticker(ta)` here you load the ticker that I could check the `type(Aktie_A)` is yfinance.ticker.Ticker, then you make a comparison with an integer here if `Aktie_A < 20` that alone will throw you an error. What is the 20? The position in the stock, the value of OPEN value, the dividends, earning? Then you pass this `f'{ta}openpos' == False`, you are asking if this string is equal to a boolean Once you are explain that I can work the logic from my own perspective and give you a solution for it – ReinholdN Nov 13 '22 at 23:08
  • Yeah, its the last thingu said about the fstring, this is not the code we use its just an example code, basically i want to use the f string or f'{ta}openpos' == False to check if an variabel is true or false, is there any eay to do this instead of writing AAPLopenpos==false – Simon Olsson Nov 14 '22 at 04:47
  • Like instead of putting every ticker in one by one i want to use the function input to locate a varible outside the function, is that possible – Simon Olsson Nov 14 '22 at 04:48
  • @SimonOlsson I got it. I will work on it and get back to you in a bit – ReinholdN Nov 14 '22 at 19:44
  • @SimonOlsson no bother dude! I hope this works out, you can implement if well to fit your needs, just dont forget to mark the answer please. – ReinholdN Nov 14 '22 at 21:14