Is there a way to adjust the number of shares automatically?
Author: wbzhang
Creation Date: 10/7/2010 12:32 AM
profile picture

wbzhang

#1
During backtesting, usually there are some trades are rejected because of insufficient cash. But can we make the system to automatically adjust the number of shares to make the trade performed? Actually even I make the transaction cost as 0 and calculate the number of shares very carefully, I still get some rejected trades. That's too bad....

For example, I want to buy N shares of stock A, but the trade will be rejected because of insufficient cash. Instead of being rejected, I prefer to buy N' shares (N' is smaller than N, and it is the maximum number of shares I can buy with my current cash at this point). Is that feasible to do? or any suggestions?
profile picture

Eugene

#2
Automatically adjust the number of shares to work around the difference of basis price vs. next open is exactly what the Position Options possizer is trying to do. See description of the "Skipped trade solution".
profile picture

emskiphoto

#3
Hello Eugene,

As a 'Graybox' trader I manually input trades following alerts from daily runs of a set of WLP strategies. I size all of my positions so that I am risking a maximum of 1% of total equity per position. I don't comprehend how to leverage the PosSizer feature to link my manual trading method with the real time balance of my 401k account. So, each year I'll use the same maximum risk amount on each position and calculate the number of shares to hold as: Max Risk / % Stop loss = # of shares.

I'm about 80% of the way to my objective with the code below, but for some reason the "Quantity of Shares to buy...." does not change as I change the default value of slider6 from 300 to 200 or 400 or etc. The quantity of shares that Displays in the DrawLabel(PricePane..... remains constant and seems to ignore the values of slider6. If I manually input a number in place of the TotalRisk variable the math updates as desired. Please help.

CODE:
Please log in to see this code.
profile picture

Eugene

#4
Hello Matt,

Your code works correctly. However, you shouldn't expect DrawLabel() to change the value by dragging the slider after running a multi-symbol portfolio backtest. This is by design. Re-run the code on any single symbol by clicking Go or Execute - note that it's not equivalent to simply clicking on a symbol after running an MSB.

P.S. In addition to printing the size, your Strategy can drive the Wealth-Lab position size. The code has to be adjusted to instruct Wealth-Lab to do so. Please read the User Guide > Reference > Data Panel > Position Size Control > Portfolio Simulation Mode > Max Percent Risk and the QuickRef > Position object > RiskStopLevel Property, then follow the code example precisely. Placement of RiskStopLevel does matter so the call should be placed on top of this block:
CODE:
Please log in to see this code.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).