My ultimate goal would be to model mutual funds. In the meantime, I've been using ETFs to simulate mutual funds. I tried plugging VTINX in and it seems to accept it without problems. Does the fact that mutual funds don't have 4 parameters per bar (ie, Open, Hi, Low, and Close) raise any issues? I would very much appreciate a brief summary of the issues concerning the modeling of mutual funds. I did a search, but it seems that most everything dates from 2010 and before. Note: I'm using the Override mode of simulation.
Update: I've tried running simulations with VTSMX and VBMFX mutual funds. I've noticed that I can now buy fractional shares. I'm also now getting lots of 'insufficient simulated capital' errors which I didn't get when simulating ETFs. A little bit of margin solves it, but I'd still like to understand why the difference with mutual funds. I've double checked the code and can't figure out what's causing the error. Here is a code segment that relates to my selling all positions then attempting to buy new positions in the correct ratio from the available capital. The PrintDebug statements shown below always show equity available to be slightly greater than equity invested. Could commission fees be the difference? It is true that the amount available is now much closer to the amount invested given the fractional shares.
CODE:
Please log in to see this code.
with the getEquity() routine here:
CODE:
Please log in to see this code.
Finally, is there a way on the forum to get notified via email when a response is posted to my posting? Thanks
Size:
Color:
Keep in mind that for BuyAtClose(bar+1), the basis price is calculated off the closing price of signal bar i.e. "bar+0".
A side note: in
getEquity(), drop the call to
SetContext(). It is absolutely not required there and is costly in terms of performance, may only cause slowdown on large backtests.
QUOTE:
Finally, is there a way on the forum to get notified via email when a response is posted to my posting? Thanks
Options > Bookmark topic > "Yes" to get notified by email.
Size:
Color:
Thanks Eugene. When I commented out the SetContext() call, the amount returned was much different. I think that's because I use one symbol (.SPX) as my trigger symbol, but I trade two other signals (eg, VTSMX and VBMFX). I wish to know the equity of the two traded symbols, not the trigger signal. With reference to the above code segment, the 'reference' variable is based on .SPX, but the GetEquity calls are based on either stksym or bndsym.
Size:
Color:
QUOTE:
When I commented out the SetContext() call, the amount returned was much different.
That's because you overlooked inserting RestoreContext, and your code could execute on an imappropriate symbol.
Size:
Color:
Now I'm confused. My understanding is that RestoreContext returns the context to the primary symbol which in my case is .SPX. Calls to GetEquity() need to be based on the two traded symbols ie, stksym and bndsym. When I comment out the SetContext() call it acts upon the primary symbol, .SPX.
Size:
Color:
Oops. GetEquity
should be symbol agnostic but in fact it's not. To fix:
CODE:
Please log in to see this code.
After making this change, SetContext should not be affecting the calculation and can be removed.
Size:
Color:
Thanks. It works great!
Size:
Color: