How do we implement fixed fractional position sizing (as described by Ralph Vince) in version 7?
I looked at the possibility of creating my own but I need access to the RiskStopLevel variable which appears to be missing from v7 too.
Thanks
I looked at the possibility of creating my own but I need access to the RiskStopLevel variable which appears to be missing from v7 too.
Thanks
Rename
How did you implement it in v6?
When I was writing Quantacula Studio from the ground up, it was meant as a completely different product line than WL, but it eventually morphed into WL7. So there will be differences. One if the things I decided not to include was risk-based position sizing, because I didn't like the way it was handled in WL6, I felt it was too clumsy. If there's sufficient demand we could get it back into the product in some fashion, the first step would be to submit a topic tagged with #FeatureRequest.
Thank you Glitch. I think it's an important position sizing method, so I will add a feature request.
Eugene, I haven't used v6 but from reading the documentation, it looks like it would've been easy to add a custom fixed fractional position sizer with the RiskStopLevel variable available. Similar to this:-
https://www2.wealth-lab.com/wl5wiki/psConstantRisk.ashx
Eugene, I haven't used v6 but from reading the documentation, it looks like it would've been easy to add a custom fixed fractional position sizer with the RiskStopLevel variable available. Similar to this:-
https://www2.wealth-lab.com/wl5wiki/psConstantRisk.ashx
Just realised I can set the Tag property of the transaction and it will carry over to my custom position sizer. This should allow me to create my own fixed fractional model.
Technically, it's possible now in a coded Strategy, since you have access to the bar by bar equity, cash, etc, and you can manually set the quantity of a Transaction. I'll try and mock up a quick example later today.
Thank you, that would be great.
Here's the mock up, if you run it on a single stock you can see the output in the debug log, and play around with some of the variable settings.
The basis strategy is a simple RSI4 overbought/oversold, which places a stop level at 4 times the ATR4.
The basis strategy is a simple RSI4 overbought/oversold, which places a stop level at 4 times the ATR4.
CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Indicators; using System.Drawing; using System.Collections.Generic; namespace WealthScript1 { public class MyStrategy : UserStrategyBase { //Initialize public override void Initialize(BarHistory bars) { rsi4 = RSI.Series(bars.Close, 4); PlotIndicator(rsi4); atr4 = ATR.Series(bars, 4); PlotIndicator(atr4); PlotStopsAndLimits(); } //Execute public override void Execute(BarHistory bars, int idx) { if (OpenPositions.Count == 0) { if (rsi4[idx] < 35.0) { //establish limit entry price double entryPrice = bars.Close[idx]; //establish stop loss price stopPrice = entryPrice - atr4[idx] * 4; //calculate the percentage loss if we hit the stop loss level double stopLossLevel = (1 - (stopPrice / entryPrice)) * 100; //calculate a % of equity position size such that if we hit our stop loss, we lose only our max risk double posSizePct = maxRiskPct * 100 / stopLossLevel; //limit it to the current margin factor (give some wiggle room if we max out) if (posSizePct > Backtester.PositionSize.MarginFactor * 100) posSizePct = Backtester.PositionSize.MarginFactor * 100 - 5; //calculate position size based on current equity, position size % double posSizeRaw = CurrentEquity * (posSizePct / 100); //calculate quantity double qty = posSizeRaw / entryPrice; //make the purchase Transaction t = PlaceTrade(bars, TransactionType.Buy, OrderType.Limit, entryPrice, posSizePct.ToString()); t.Quantity = qty; WriteToDebugLog(idx + ", entryPrice=" + entryPrice.ToString("N2") + ", stopPrice=" + stopPrice.ToString("N2") + ", stopLossLevel=" + stopLossLevel.ToString("N2") + ", posSizePct=" + posSizePct.ToString("N2") + ", posSizeRaw=" + posSizeRaw.ToString("n2") + ", qty=" + qty.ToString("N0")); } } else { PlaceTrade(bars, TransactionType.Sell, OrderType.Stop, stopPrice, "Stop"); if (rsi4[idx] > 65) PlaceTrade(bars, TransactionType.Sell, OrderType.Market, 0, "Market"); } } //private members private ATR atr4; private RSI rsi4; private double maxRiskPct = 20; private double stopPrice; } }
Your Response
Post
Edit Post
Login is required