Simulator Updates / Progress Notes

Discussion in 'eInvesting Trading Simulator' started by Trading Simulator, Feb 3, 2006.

  1. Trading Simulator

    Trading Simulator Member Original Member

    Joined:
    Jul 18, 2005
    Messages:
    73
    Likes Received:
    0
    Trophy Points:
    6
    A test board has been established for eInvesting.com that will allow us to modify and test the code without impacting this "live" board. The initial focus is going to be cleaning up a few loose ends and getting the code "nice and tidy" prior to going forward. Most of this has been done and we are running some test orders through the system later today to make sure everything is working.

    The main visible change for this minor update will be that an invalid stock symbol will no longer lock you out of your portfolio. In the past if you purchased a stock that changed symbols, or an option that expired, you were locked out of your portfolio until an Admin could update the database. That will no longer happen. You will not be allowed to sell this holding until the issue is cleared up, and the line item value will be set to zero (which could impact your total return % until the issue is cleared up) but it will not prevent you from trading other (valid) holdings or buying additional stocks.

    The new calculation process is not included in this minor update. We'll call this update version 1.1. Once we get these code changes in place we'll be working on the more major updates to version 2.0. These include changing the portfolio update process that runs hourly and sets your return, making the same changes to the monthly closing process, and the ability to track MTD (month to date) returns over time.

    Limit orders and options trading will not be in the next major roll-out but are still in the plan as future features.
     
  2. Trading Simulator

    Trading Simulator Member Original Member

    Joined:
    Jul 18, 2005
    Messages:
    73
    Likes Received:
    0
    Trophy Points:
    6
    Here's something to ponder on the portfolio return calculation process.

    The problem with the current process is that it penalizes you for reinvesting capital. Specific example:

    Buy stock X for $10, sell for $15
    Buy stock Y for $15, sell for $20
    Buy stock Z for $20, sell for $30

    The "total" return for those three trades was 200%. The trader turned $10 into $30, for a 200% return. The net result is exactly the same as someone with these trades:

    Buy stock A for $10, sell for $30.

    But with the current calculation process, the second trader will be rewarded with a return of 200%, while the first will not. The first will have:

    Buy stock X for $10, sell for $15 (500 gain on 1000 invested, 50%)
    Buy stock Y for $15, sell for $20 (500 gain on 1500 invested, 25%)
    Buy stock Z for $20, sell for $30 (1000 gain on 2000 invested, 50%)

    total of 2000 gain on 4500 invested, or 44%. That's a big difference from 200%. Clearly this needs to be fixed.

    To fix this we simply need to know the starting and ending values of the portfolios. In the case above, both traders started with $1000 and ended up with $3000, for a $2000 gain or 200%. Sounds like an easy fix, right?

    The problem comes in that we have more than just stock trades going on. Here's a very extreme hypothetical example.

    Starting balance $1000, no stocks
    Buy stock X at $10, goes to $20
    Receives $2500 from "sneak peek"
    Buy stock Y at $25, goes to $20

    In this case, the return on one investment was 100% while the other was a loss of 20%. The total invested is 3500, the total value is 4000, net return is 14% (500 / 3500). In this case, the cash came from a donation, rather than an investment, and should be calculated as part of the return.

    Next case, exactly the same as last case, except the person that got the $2500 "sneak peek" money didn't invest it.
    Starting balance $1000, no stocks
    Buy stock X at $10, goes to $20
    Receives $2500 from "sneak peek"

    In this case, there should not be a penalty for NOT investing the cash, so their return should be 100%. And suppose that they sell the stock at $20 and buy something else that goes to $30, as in the earlier example, but never touch the $2500 extra cash? That $2500 should not be considered as part of their investment capital.

    So the challenge is to figure out when cash is "reinvested" and when cash is "invested", the difference being that during a month an active trader might "reinvest" the same e$ over and over, and should not be penalized, but investing "new" funds like those from donations or posting or sale of property in the Virtual Store should?

    It's all making my head hurt, and I would appreciate any ideas on how to best handle this. :?
     
  3. Trading Simulator

    Trading Simulator Member Original Member

    Joined:
    Jul 18, 2005
    Messages:
    73
    Likes Received:
    0
    Trophy Points:
    6
    FYI, there is a log of donations made via the system, so I can tell if someone made $2500 by a "sneak peek". There is no log for property transactions. There is no log made for individual e$ earned via posting. There is a log of all stock trades.
     
  4. Grimreaper

    Grimreaper Active Member Original Member

    Joined:
    Jun 11, 2005
    Messages:
    5,161
    Likes Received:
    0
    Trophy Points:
    36
    Well, all I know is that the trade sim is still waaaay off on the opening 20 minutes of trading, it appears it "wakes up" at 9:50 EST, for proof in da puddin check my timestamp on me buy of 2000 AEMLW today at the open when it was trading at 7.22, it traded at 3 or 4 other prices before it traded to da price da trade sim actually gave me! :lol: I'm woikin haaad ta try and maintain damage control in bad mawket cundishuns, but yuns guys at da trade sim is makin it tough! :lol:
     
  5. Trading Simulator

    Trading Simulator Member Original Member

    Joined:
    Jul 18, 2005
    Messages:
    73
    Likes Received:
    0
    Trophy Points:
    6
    Grimreaper: the sim does wake up at 9:50. However, not all quotes are delayed 20 minutes, some are delayed only 15. It may be that the stock you chose to sell is one that is delayed only 15 instead of 20, in which case you would miss the first 5 minutes of trading.

    Here is a link to the page on Yahoo!'s financial section that details the quote delay. Because we trade stocks on all exchanges, we had to go with a 20 minute delay as the lowest common denominator. The Nasdaq exchange is delayed 15 minutes... the NYSE is 20.
     
  6. vetelmo

    vetelmo Active Member Original Member

    Joined:
    Sep 21, 2005
    Messages:
    3,801
    Likes Received:
    0
    Trophy Points:
    36
    Location:
    California
    Why does it "wake up" at 9:50 AM EST?
     
  7. Dave Rathbun

    Dave Rathbun Original Creator Original Member

    Joined:
    Apr 10, 2005
    Messages:
    3,386
    Likes Received:
    0
    Trophy Points:
    36
    The market itself opens at 9:30 eastern. Since the opening quotes are not displayed on Yahoo for another 20 minutes, the order queue processor doesn't actually start until 9:50. The market closes at 3:00, and the queue processor stops at 3:20. Since the quotes from Yahoo are delayed 20 minutes it essentially puts the trading system for this site on a 20 minute delay all the way around.

    Note that you can enter trades 24 hours a day. But they are only executed when the market is open.
     
  8. vetelmo

    vetelmo Active Member Original Member

    Joined:
    Sep 21, 2005
    Messages:
    3,801
    Likes Received:
    0
    Trophy Points:
    36
    Location:
    California
    DOH! For some reason I thought the market opened at 8AM.
     
  9. geb9696

    geb9696 Active Member Original Member

    Joined:
    Nov 10, 2005
    Messages:
    1,494
    Likes Received:
    0
    Trophy Points:
    36
    Home Page:
    It's all making my head hurt, and I would appreciate any ideas on how to best handle this.


    I have an idea for this but I doubt most people are going to like it. I suggest that you can only invest the money that is in your account on the first day of the month. That way it will eliminate the probally of having such a complex system to calculate the precent return. After the month is over you should be allowed to add in the funds that you made during the previous month. Not sure if this makes any sense to anybody else but it sounded good in my head.
     
  10. Trading Simulator

    Trading Simulator Member Original Member

    Joined:
    Jul 18, 2005
    Messages:
    73
    Likes Received:
    0
    Trophy Points:
    6
    That has been discussed, and it could be an option. At this time we would rather not consider it. But I do appreciate the comment.
     
  11. Trading Simulator

    Trading Simulator Member Original Member

    Joined:
    Jul 18, 2005
    Messages:
    73
    Likes Received:
    0
    Trophy Points:
    6
    Good news!

    Okay, I have the math working, and I believe that this issue will be put to rest this month. The first few days of the month will continue to use the "old" portfolio return calculation while we finetune the process, but sometime around the middle of the month (at the latest, it could be sooner) we will change to the new algorithm.

    The biggest reason for the delay in implementing this fix was getting hung up on tracking cash (e$) on the board. There are two many variables to solve for. We don't get a log of e$ for posting, and there is no log of e$ going into (or out of) assets from the virtual store. Add to that the fact that people can "donate" money to another person (such as what Dave Rathbun is doing in the e$ Math Challenge topic) and there are e$ flying all over the place. :shock:

    The revelation finally happened today, in fact I got so excited I called Benjamin on the phone. Yes, actual voice communication took place. :lol: I thought I had the perfect solution, but during the conversation a significant issue was discovered, and I spent the afternoon thinking it over. jdunn72 made some suggestions a while back, and in reviewing his input the final piece of the puzzle dropped into place.

    Here it is in a nutshell. If you see any issues, please post them now before too much coding is done.

    At midnight on the first day of a new month we capture the share price of every open holding in your account. More on this in a minute. We also set your t$ (trading dollars) balance to zero. And we capture the month end total portfolio value and store that. That's it for the monthly reset. Notice that we do not capture any information about your e$ balance.

    Suppose during the month you made no trades. Then your portfolio return is simple, take the month ending balance and compare to the month beginning balance, and you have an easy portfolio return.

    Suppose during the month that you sold something. The proceeds from the sale are of course deposited into your e$ account. And the amount of gain for this month is deposited into your t$ account. (You never see this t$ account, it is strictly used to track cash from trading activities.) So if you purchased a stock at $10 during the prior month, and it closed the month at $15, and you sold this month at $20, then you get the total proceeds from the sale put into your e$ account but only the gains ($5 per share) for the month are deposited into your t$ account.

    Now here's the tricky part... when you buy a stock during the month, you of course fund the entire amount from your e$ account. But for the purposes of tracking your portfolio baseline amount the sale is funded as completely as possible from the t$ account. This means that you will be reinvesting your gains, which will compound your return rather than reduce your return as it did previously.

    Any shortfall in your t$ account will be added to your portfolio baseline value. Let me explain this further. For simplicity let's ignore commissions.

    Suppose you start the month with zero holdings. You purchase 100 shares @ e$10. You invested e$1000, and your t$ account was empty, so your portfolio baseline amount (e$0) is increased by e$1000. So you have a portfolio worth e$1000 that costs you, well, e$1000. No surprises so far.

    Later that month you sell that entire holding for e$1500. At this point you have a 50% return (e$500 profit on a e$1000 investment). But you don't stop there. You reinvest e$1000 on another $10 stock. Now you got e$1500 from your first sale, and that went into your t$ account. When you invest another e$1000, your portfolio baseline amount does not increase as you are using the e$1500 from your previous sale to fund your next trade. Suppose that you end the month with that stock at $15. That's another e$500 profit.

    Now the math: your portfolio baseline is e$1000 (e$1000 initial investment). Your increase for the month was e$1000 (two e$500 gains, one realized from a sale, and one still open position). Take e$1000 and divide into e$1000 and you see that you have a 100% return. Hopefully it's obvious as you made e$500 profit from the first closed position, and you have e$500 profit in an open position, and you invested e$1000 at the beginning of the month. Invest e$1000, make e$1000 profit, that's a 100% return.

    Under the old system you would have been penalized for reinvesting during the month. You would have e$1000 in gains divided by e$2000, or 50% return. And the more you traded, the more you diluted your return.

    One more example that should (hopefully) really show the way this will help frequent traders. Again start the month with zero holdings. Along the way we will place 10 trades during the month, but each time the new trade will be completely funded by proceeds from the prior trade.

    Buy 100 @ $10 Portfolio base = e$1000, t$ = 0
    Sell 100 @ $11 Portfolio base = e$1000, t$ = 1100
    Buy 100 @ $11 Portfolio base = e$1000, t$ = 0
    Sell 100 @ $15 Portfolio base = e$1000, t$ = 1500
    Buy 100 @ $14 Portfolio base = e$1000, t$ = 100 (didn't use it all)
    Sell 100 @ $15 Portfolio base = e$1000, t$ = 100 + 1500 = 1600
    Buy 100 @ $16 Portfolio base = e$1000, t$ = 0
    Sell 100 @ $20 Portfolio base = e$1000, t$ = 2000
    Buy 100 @ $20 Portfolio base = e$1000, t$ = 0
    Sell 100 @ $25 Portfolio base = e$1000, t$ = 2500

    What's your return? You have a balance of e$2500 on a starting balance of e$1000, you made e$1500 in gains for the month, so e$1500 / e$1000 = 150% return.

    Under the old system you would have received e$1500 / e$7100 (the sum of all of your trades) for a 21.1% return, which is still respectable, but a far lower number than 150%.

    The t$ left in your account at the end of the month disappear during the next monthly reset. If you make no trades for the following month, your return is calculated strictly on the basis of your portfolio holding changes.

    Back to the original scenario where you had a holding from last month that you sold this month, how is the return calculated? You only get credit this month for the gains this month. Anything else was credited in the prior month, and you don't get credit for the same increase (or decrease) twice.

    Start of month:
    e$1500 portfolio value (one stock at $15, purchase at $10 last month)
    t$ 0

    During month:
    sell @ $20, get e$2000 deposited into your e$ account, and $500 into your t$ account for possible reinvesting

    Portfolio return so far: $500 / $1500 or 33%.

    But 100 @ 10 for e$1000. You only got e$500 in profits from your last transaction, so you are increasing your portfolio baseline by e$500. Your new baseline for return % is e$2000. At that exact moment you have t$ 0, baseline of e$2000, and a profit of e$500. You have diluted your return, it drops from 33% to 25%. This is expected. Why? Because you had to add more cash to your t$ to make the trade.

    Compare this to a scenario where the entire transaction takes place in a single month. You start the month with zero, buy a stock at 15 and sell at 20. Your baseline is 1500, your t$ are 2000. What is your return? 25%. If you reinvest 1000 and the stock is exactly where you purchased it, you still have a 25% return. So the numbers match. But the advantage is that your t$ account is much larger, allowing you to make more trades this month without having to increase your portfolio baseline. In the prior example, you only get credit for the gains for this month towards future purchase.

    I believe this is the correct solution, but I welcome any input.

    Do not quote this entire post and say "I agree" or "this is wrong". If you need to, quote a specific scenario and show where you disagree with my math. That is all, commence arguments. :p
     
  12. nelaina

    nelaina Active Member Original Member

    Joined:
    Nov 17, 2005
    Messages:
    2,076
    Likes Received:
    0
    Trophy Points:
    36
    Location:
    new jersey
    oh my

    adhd, ill wait till tomoorow to read this :lol: :p
     
  13. jdunn72

    jdunn72 Active Member Original Member

    Joined:
    Jan 26, 2006
    Messages:
    1,363
    Likes Received:
    0
    Trophy Points:
    36
    Home Page:
    Re: Good news!

    I appreciate your acknowledgement of my input for this solution but, I was wondering which part of this solution was different from the one I suggested? It seems to be exactly the same. As a programmer/trouble-shooter I was wondering if or what I actually missed in the solution.
     
  14. Trading Simulator

    Trading Simulator Member Original Member

    Joined:
    Jul 18, 2005
    Messages:
    73
    Likes Received:
    0
    Trophy Points:
    6
    Re: Good news!

    Perhaps I didn't read your solution closely enough, but I don't believe you included capturing the monthly close for each individual holding in a portfolio. That's required in order to know how much gain for a sale in this month is attributed to this month's result.
     
  15. Trading Simulator

    Trading Simulator Member Original Member

    Joined:
    Jul 18, 2005
    Messages:
    73
    Likes Received:
    0
    Trophy Points:
    6
    Re: Good news!

    Wrong. I don't know where my head was on this one, but the return is 33%. The baseline is 1500, the gain is 500.

    I believe that the two scenarios I outlined need to balance, or the math doesn't work. I need to rethink some of this a bit more, obviously.
     
  16. jdunn72

    jdunn72 Active Member Original Member

    Joined:
    Jan 26, 2006
    Messages:
    1,363
    Likes Received:
    0
    Trophy Points:
    36
    Home Page:
    Ok, I figured that because a trade not closed is not a monetary gain until sold, but thats just a technicality.
     
  17. jdunn72

    jdunn72 Active Member Original Member

    Joined:
    Jan 26, 2006
    Messages:
    1,363
    Likes Received:
    0
    Trophy Points:
    36
    Home Page:
    Wait, I did state this but, maybe it was different in actuality....


    Positions held and closed would be returned as t$e.


    At the beginning of each month all monies would be update queried as t$e.

    And percentage returned on investment query would only pull t$e and state of current positions relative to the value of t$e reset and recorded at the beginning of the month as some var like begin$e and TotBTA is reset to zero as well at each beginning.
     
  18. jdunn72

    jdunn72 Active Member Original Member

    Joined:
    Jan 26, 2006
    Messages:
    1,363
    Likes Received:
    0
    Trophy Points:
    36
    Home Page:
    I just took a look at the beta board, that is a fantastic idea about going retroactive in the database, and at least we can get a real feel for how well we have done in the past. Good work Dave, I'll be looking forward to the implimentation of your coding? :wink:
     
  19. Trading Simulator

    Trading Simulator Member Original Member

    Joined:
    Jul 18, 2005
    Messages:
    73
    Likes Received:
    0
    Trophy Points:
    6
    No, it's not.

    If I buy stock last month for 10 and it rises to 15 last month then it is very important that the $5 gain per share has zero impact on this month's portfolio return calculation. If the stock stays at 15 the entire month, I have a 0% return. If the stock drops, I have to show a loss. The only way to do that is track what each individual holding was at the end of the month. Without this, I can't track holdings that span more than one month.

    I went back and reread your notes, and the process as I've outlined it is very similar, but I believe simpler. The basic idea of having a second trading currency was excellent, and as I said, it certainly got me on the right track.

    I don't want to / can't track every single e$ transaction that a user does. This solution does not require me to do that. Nor does it require me to change the definition of e$ and maintain two different currency types as outlined in your suggestion. I only need to track / update t$, which is completely behind the scenes and has zero impact on e$ transactions of any kind. There are way too many places that e$ is used (shop, posting rewards, donations) to change how e$ are handled.

    As trades are made, purchases are first applied to proceeds from prior sales (reinvested) and then to new money (investments) and the difference is that new money increases the baseline for your portfolio return calculation this month. That's it. What I have to do is solve the t$ issue that I mentioned in the last post, and check out how t$ transactions would look if the stock is sold at a loss instead of a gain.
     
  20. Trading Simulator

    Trading Simulator Member Original Member

    Joined:
    Jul 18, 2005
    Messages:
    73
    Likes Received:
    0
    Trophy Points:
    6
    But I think that's too complicated. :) And I don't believe it's necessary.

    I have two new variables stored on the user record. The portfolio baseline (which can increase during a month) and t$ (which starts every month at zero and can increase / decrease as trades are made). At the end of the month we get the total portfolio value of current holdings and calculate the gain for each of them this month based on the last month close. Or if the position was opened this month, then the entire gain is used. Any gains from sales that are not reinvested will be denoted as a + balance in the t$ account and treated as a gain as well. Divide that by the portfolio baseline and you have the return %.

    The bottom line is that reinvesting proceeds from sales this month should not reduce your monthly return % as they do now. This solution does that.

    It may very well be that you and I are saying the same thing, and arguing from a different direction.

    I'm signing off now, and going back to the math so I can make 25% = 33% or whatever needs to happen. :lol: