Python Forum
Stock Return calculation problem
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Stock Return calculation problem
#5
(Sep-23-2022, 06:46 PM)LFin Wrote: I totally understand and I did it, exactly what you wrote in the first time but as I am going to use different weights (w1, w2...) for each assets and The computation of my last formula (Base * (1 + return1*w1 + return2*w2...) I think I need to separate them...

Maybe you should try it again. I can't see any advantages of having separate variables/names compared to list/tuple/dictionary approach. You can access both by name and in container they become iterable in case you need to access them dynamically:

>>> weights = (0.2, 0.3, 0.4)
>>> weights[0]
0.2
>>> for weight in weights: 
...     print(weight)
...
0.2
0.3
0.4
>>> weights = {1: 0.2, 2: 0.3, 4: 0.4}
>>> weights[2]
0.3
You should also think about future self. If you return to your code in two days/weeks/months do you remember what tickers_3 / return_3 were? Was it AMZN or APPL?
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Messages In This Thread
Stock Return calculation problem - by LFin - Sep-22-2022, 02:13 PM
RE: Stock Return calculation problem - by ibreeden - Sep-23-2022, 08:57 AM
RE: Stock Return calculation problem - by perfringo - Sep-23-2022, 11:23 AM
RE: Stock Return calculation problem - by LFin - Sep-23-2022, 06:46 PM
RE: Stock Return calculation problem - by perfringo - Sep-24-2022, 08:14 AM
RE: Stock Return calculation problem - by LFin - Sep-26-2022, 01:52 PM
RE: Stock Return calculation problem - by LFin - Sep-26-2022, 01:59 PM
RE: Stock Return calculation problem - by LFin - Sep-26-2022, 03:36 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Dataframe mean calculation problem: do we have to loop? sparkt 1 2,248 Aug-28-2020, 02:41 PM
Last Post: sparkt
  Any suggestions to improve BuySell stock problem efficiency? mrapple2020 0 1,427 May-13-2020, 06:19 PM
Last Post: mrapple2020
  Problem with simple 3D Vektor calculation Pythocodras 0 1,761 Dec-11-2019, 07:18 PM
Last Post: Pythocodras
  Matrix Calculation Problem arshad 4 2,777 Nov-04-2019, 03:48 PM
Last Post: baquerik
  Pass variable script return twice output problem Faruk 8 4,616 Dec-26-2018, 11:57 AM
Last Post: Faruk
  problem with function return value ujjwalrathod007 9 24,106 Sep-23-2016, 03:02 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020