1

I want to graph a portfolio of stock trades over a period of say one year.

I will have many trades with many different stocks. The question becomes, what is the best way to calculate the value of the profile over the year.

1) Query for all transactions before or on the start of the period.
2) Calculate their price and totals on that day.

Now, what would be the best method?

Do I loop through each day in the period selected, then find and sum all transactions on a stock before that day.

Loop through all the stocks, sum, store and then do it again for the next day?

How do the pros do this? Curious.

user3666197
  • 1
  • 6
  • 50
  • 92
jimijon
  • 2,046
  • 1
  • 20
  • 39

1 Answers1

1

Similarly to what happens in reality, you should go day by day. You move to the next day only after you summed all the transactions on all stocks at a certain day. This will allow you to impose portfolio-level restrictions and allocation. Some examples:

  • You trade 30 stocks. Capital is equally shared between all stocks. If one stock goes below $5, you don't trade it. Then, you allocate all the capital to the other 29 stocks.
  • You observe the correlation between the stocks. If 5 stocks are highly correlated, you allocated less capital to each.
  • You have 30 stocks in your symbol universe, but you only trade up to 10 stocks in parallel, according to relative performance of trades you took on each stock.

This kind of management will be possible only when you calculate all transactions per day before moving to the next.

IamTheWalrus
  • 594
  • 5
  • 14
  • 1
    Yes. I wound up setting up my date array of days, then looped through that and added all transactions up to that day, got the price for that day, and moved on. Works well for my needs. Sounds like you know trading. Maybe you can help me with my tracker for crypto coins to include some "smarts" – jimijon Oct 25 '17 at 16:32
  • @jimijon sure, if I can :) – IamTheWalrus Oct 25 '17 at 16:53
  • don't know how to contact you. I am thinking ML with Apples new chip to suggest trades – jimijon Oct 27 '17 at 20:34