1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Execution of Python Code with slow results

Discussão em 'Python' iniciado por Stack, Setembro 8, 2025.

  1. Stack

    Stack Membro Participativo

    I have the following code:

    account = [('A1',1, 'asset',1, 'stock'),('A1',1, 'asset',2, 'etf'), ('A2',2 'equity',2, None), ('A3', 3, 'income', 1, 'tax'),... ]
    balance =[('2025-01-07', 1, 4, 5), ('2025-02-07', 2, 7, 8), ('2025-04-08', 3, 5, 9)
    currency = [('2025-01-05', 1.5), ('2025-02-04', 1.7)
    periods = ['2025-01', '2025-02', '2025-03', '2025-04'...]

    def totalling(account, balance, currency, periods):
    runQ = 0; runVal = 0; bline = 0

    atype=acct[2]

    for p in periods:
    curCurrency=1
    pbal = [line for line in balance if str(line[0][0:7])==str(p[0:7])]

    if len(prdTrans)!=0:
    runQ = pbal[len(pbal)-1][1] # should be prdTrans[-1][5] #/930397/
    runVal= pbal[len(pbal)-1][2] # should be prdTrans[-1][6] #/930397/

    if atype in ['asset', 'liability', 'equity']:
    if acct[4] in ['mutual fund', 'stock','etf']:
    # return a date and float for the max date
    # for a period eg. 2025-01-28 from a database:
    D, F = getPrice(acct[1], p)
    line = round(runQ * F, 2)
    else:
    line = round(runVal, 2)

    if atype in['income', 'expense']:
    line = sum([b[4] for b inpbal])

    if (int(account[3])==2):
    curC=[c[1] for c in currency if c[0]==period][0]

    plist.append([acct[0], str(p), ibline*curC, atype, acct[4], runQ, acct[1]])

    return plist


    It executes correctly, but I am finding that with the amount of data I have that it is rather slow in executing. Can someone please tell me where I can make it more efficient. I've tried various changes, but this is the best I can come up with.

    I have all the dates in the 4 lists stored in a database (stored in unixtime) and am guessing recoding to do a integer date comparison would speed up the code, but comparing the periods as year-month strings is easier for me to understand.

    Can anyone make any suggestions on how to increase the efficiency. I realize this is not the best of questions and may not be appropriate for SO.

    I'm guessing I'll have to learn and code it in C to make a real difference! Thank you. John

    Continue reading...

Compartilhe esta Página