0

apologies I know this probably a simple question but I'm new to this! I made all these calculations from a csv file and now I'm trying to make the same calculation through every file for the whole month. In the first class,def get_holdings_info(d):, I'm working through my calculations. In the second class, def get_holdings_info_array(): I'm trying to pass the first class through every day of the month. I think my code is just about right, but for some reason I'm getting a return of 0's. Thanks in advance if you can help!

holdings_darray = ['01-03-2020','01-06-2020','01-07-2020','01-08-2020','01-09-2020','01-11-2020','01-14-2020','01-15-2020','01-17-2020','01-21-2020','01-22-2020','01-23-2020',
                   '01-24-2020','01-27-2020','01-28-2020','01-29-2020','01-30-2020','01-31-2020','02-04-2020']
account_names = ["CATALYST EXCEED DEFINED SHIELD FUND", "SCA/IB FBO CAT EXCEED DEF SHIELD FD"]
bond_name = ["Bond Paying Periodic Income"]
money_market_name = ["Money Market Fund"]
mutual_fund_name = ["Mutual Fund"]


def get_holdings_info(d):


    sbhmv = 0
    sbhbv = 0
    sbhs = 0

    setfhmv = 0
    setthbv = 0
    setfhs = 0

    smmhmv = 0
    smmhbv = 0
    smmhs = 0
    holdings_file = 'holdings/Holdings As Of ' + d + '.csv'
    df = pd.read_csv(holdings_file, header=1)
    account_names = ["Fund_1", "Fund_1"]
    bond_name = ["Bond Paying Periodic Income"]
    money_market_name = ["Money Market Fund"]
    mutual_fund_name = ["Mutual Fund"]
    sbh = df[df["Account Name"].isin(account_names) & df["Security Type Name"].isin(bond_name)]

    sbhmv = sbh['Market Value'].sum()
    sbhbv = sbh['Book Value'].sum()
    sbhs = sbh['Shares'].sum()
    setfh = df[df["Account Name"].isin(account_names) & df["Security Type Name"].isin(mutual_fund_name)]

    setfhmv = setfh['Market Value'].sum()
    setthbv = setfh['Book Value'].sum()
    setfhs = setfh['Shares'].sum()
    smmh = df[df["Account Name"].isin(account_names) & df["Security Type Name"].isin(money_market_name)]

    smmhmv = smmh['Market Value'].sum()
    smmhbv = smmh['Book Value'].sum()
    smmhs = smmh['Shares'].sum()


    return sbhmv, sbhbv, sbhs, setfhmv, setthbv, setfhs, smmhmv, smmhbv, smmhs

def get_holdings_info_array():
    c = []
    for f in holdings_darray:
        c.append(get_holdings_info(f))
    return(c)

print(get_holdings_info_array())

[(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0), (0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0), (0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0), (0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0), (0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0), (0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0), (0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0), (0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0), (0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0), (0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0), (0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0), (0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0), (0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0), (0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0), (0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0), (0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0), (0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0), (0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0), (0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)]
  • Does this answer your question? [How do I return multiple values from a function?](https://stackoverflow.com/questions/354883/how-do-i-return-multiple-values-from-a-function) – fedest Sep 01 '20 at 21:42

1 Answers1

1

What you are in need here, is of tuples. This SO question and it's answers pretty much cover every variable.

Your code, while syntactically correct, semantically is wrong. A python function finishes it's execution after encountering a return statement. Your function get_holdings_info finishes after reaching this line

return sbhmv

and never executes the rest.

If you want to return all those values you can refer to the question I mention for all possibilities, but the simpler option would be to do:

return sbhmv, sbhbv, sbhs, setfh, setfhmv, setthbv, setfhs, smmh, smmhmv, smmhbv, smmhs

In which you return a tuple with all the values you need.

fedest
  • 1,190
  • 3
  • 15
  • 35
  • This worked. But now I'm getting a 0 for all of my tuples =( – anon1234345 Sep 01 '20 at 22:41
  • The probably is because the logic of your program is incorrect. Check that by your own account or create a new question with what you want to ask – fedest Sep 01 '20 at 23:12