Volatility sizing based on current capital

Hello everyone and thank you in advance,

I do not end up getting my purpose after many tests. I will tell you, my goal is to achieve an annualized volatility of 20%. To do this, I multiply the initial capital by 0.2 and divide it by 16, which is the square root of 252 (the trading sessions in a year).

For example, if I have $100,000, I should have a daily volatility in dollars of $100,000 * 0.2 / 16 = $1250, to achieve my goal of 20% annualized volatility.

Then I calculate how much an asset moves on average in dollars (assetVolatility in the code) and divide my daily volatility target calculated above by that number and it tells me the number of securities. The problem is that I don't know how to update the current capital to recalculate my daily volatility target:

//DESVIACION STANDARD EXPONENCIAL    
assetVolatility= sqrt( EMA( ( C-Ref(C,-1) )^2, 36 ) ) ;  
ObjVolat = Equity()*0.2/16;  //HERE IS MY DOUBT

//CAPITAL INICIAL Y COMISIONES//  
SetOption("maxopenpositions",6);  
SetOption( "initialequity", 100000 );
SetOption("CommissionMode", 2);
SetOption("commissionamount",50);     /
PositionSize = Ref( round( Nz(ObjVolat/(desv_carver*PointValue) ) ),-1);   

TL,TR: My doubt is in the second line of code to update the equity.

How could I do it, is it ok like this?

Did you check Knowledge Base:

Thank you Tomasz, but my question is not exactly where the examples in the "knowledge base" always start from wanting to risk a fixed percentage of capital as in the examples that say 1% or 3% (I know it could be any amount). Instead, I don't know what percentage of my equity the position will be, but I will buy more or less depending on how volatile it is. For example: If a stock moves 3 dollars daily, and my daily volatility target is 3000 dollars, I will buy 1000 shares. Where the daily volatility target is a function of my total equity (which varies as we operate), multiplied by my annual volatility target (for example 20%) and divided by 16 (square root of 252, trading days). Therefore, what appears in the knowledge base seems to not quite fit what I am explaining because there is always a fixed percentage to risk and I do not have a fixed percentage. My formula assumes that we have already determined our daily volatility target and our daily price volatility, and that we are willing to risk a fixed amount of money in a day. But if our equity changes, we will need to recalculate the position size using the updated equity amount, which is never a fixed percentage

Thank you for your response to my previous question. However, I am sorry to say that it was not satisfactory for me. I appreciate that you took the time to answer my question, but I do not believe that your response addressed my concern. I am sorry if I have caused any inconvenience and I apologize if my previous question was not clear. I would be grateful if you could provide more information or clarification on the matter. Thank you for considering my request.

If I correctly understand your goal, you need to express your position size as percentage of of equity, which is described in he link provided above by Tomasz.
For this case you can calculate this percentage in phase 1 (no need for CBT).

Setpositionsize((0.0125*MarginDeposit)/(assetvolatility*PointValue),spsPercentOfEquity);

In this way, the % of equity changes with the assetvolatility.

1 Like

Thanks!!!!!! Thats it