Search code examples
portfoliostocksalgorithmic-trading

What is the best way to graph a portfolio of stock transactions?


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.


Solution

  • 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.