Not logged in
Viewing 15 posts - 1 through 15 (of 16 total)

Forums>Quant Analyzer (formerly named EA Analyzer)>Extending the program>create Portfolio with strategies lot size propotional to portfolio balance

  • #114508 |
    Customer
    9 Posts

    Hello,

     

    I’d like to know whether it’s possible to modify the individual strategies lot size when building a portfolio so that they are proportional to the portfolio balance evolution.

    Indeed I have individual strategies for which lot size are propotional to the current account balane (or free margin). So when merging several such strategies, the impact of each individual strategy is not correct.

    Let say I start with 10.000 EUR for start1 and for that balance, lot size is 0.1.

    After 10% balance increase lot size is 0.11

    Now I have a second strategy on same account. So start balance is identical 10.000 EUR. Same start lot size of 0.1.

    But this strategy looses 10% during the same period. So lot size for individual strategy 2 will be 0.9

    Now If I merge, start1 + strat2. I should be around 0 benefit so end balance 10.000 EUR, but start1 lots at 0.11 and strat2 lots at 0.9.

    In reality both strats on same account at balance 10.000 EUR means 0.1 used for each.

     

    If during portfolio creation, the lot size (+ commission, P/L, …) is (are) adjusted to the running account balance then the impact of mixing both stratégies together will be closer to reality.

     

    Is there a way to do it by extension? Can you explain how to do it and get me started?

     

    Could be an option to add in further versions of the product. Eventually Monte Carlo Analysis should also be adapted the same way to get statistics closer to portfolio/strategy reality. Indeed if the strategy analyzed with Monte Carlo uses lot sizes proportional to account balance, simply shuffling trades does not give a correct approximation of drown downs.

     

    By the way I just bought the pro licence and I love the product. Another thing I’d like to see modify but is less important is to have the number of days for MonteCarlo prediction be a parameter that can be changed.

     

    Best regards.

    #135301
    Customer
    9 Posts

    I’m upset about the behavior of support. This is not a open source software, and I have paid the software pro licence. I posted that question almost 3 months ago and got no answer. How not professionnal.

    #135316
    Participant
    118 Posts

    Perhaps not replied to because the application is far beyond the scope of the program at present.

     

    I well know what you want, but the program would require a complete rewrite to accommodate your requests.

     

    I have studied this for many months….. and pondered what is required..  It may actually demand so much memory that it would be too large for many users.

     

    I wonder if you should be looking to do it yourself in excel and the reason I mention that is, there is no quick way to incorporate all of these features, it is like a separate application.

    #135318
    Administrator
    3147 Posts

    sorry for not replying sooner.

     

    I think I understand what you want to achieve, but the problem is that it is not possible to compute real running account balance in QuantAnalyzer, because it can see only the final result of the trade, not the progress.

    You have to realize that QuantAnalyzer doesn’t perform the actual backtest of the strategies, only a simulation using list of closed trades.

     

    The problem is in overlapping trades – when one trade starts before some other is finished then the program doesn’t know what is the running account balance at the time this second trade is opening.

    It would work only if there would be no overlapping trades, but that is not the usual case.

    Mark
    StrategyQuant architect

    #135811
    Customer
    9 Posts

    It is possible and not so complex as you think. You have to create a list of trades events with trade entries and trade closure. Not just one line per trade.

    If you do that just like in the simulation reports, you don’t have any problem of overlapping trades anymore. You have an event timestamp that you can use to sort and calculate running balances and the different ratios.

     

    We don’t need to know the evolution of currency rates, because balances are only modified by trade closure. If the money management was based on free margin or equity, that would not be possible without curreny rates. But with account balance we have all information we need.

     

    Please answer a bit more quicly this time.

    #135824
    Administrator
    3147 Posts

    yes, this approach would work if you are interested in open account balance, not on account equity (which is account balance + open profit/loss) 

     

    I was mistaken that we use account equity in Money management, while in reality we use account balance. But this is already implemented in Money Management feature of QuantAnalyzer. You can load your portfolio and recompute money management there and it works just like you described it.

     

    When you are combining strategies to a portfolio it doesn’t recompute their sizes by default, it “only” combines its orders. So use Money management for what you want to achieve.

    Mark
    StrategyQuant architect

    #135828
    Customer
    9 Posts

    Thank you for your fast answer. But that is not the answer to my question. What I want is to mix 2 strategies and see the impact on an account that would have the 2 strategies applied to it.

     

    What you propose is just to transform a fixed lot strategy into a proportional lot and see the impact on that strategy. This is completely different and it doesn’t help to analyse the impact of 2 strategies put into a portfolio.

    Let’s take my example. 1 strategy has a loss of 50% starting from 10.000. The second strategy has a benefit of 50% starting from 10.000. If the loss happen first and then the gain. In the current portfolio creation you end-up with 10.000. But in reality your account evolves as the following: 10.000 -> 5.000 -> 7.500.

     

    Please take the time to consider or even do some quick tests and you’ll realize what you propose is not the answer. Whithout that feature, portfolio buidling is just wrong if your individual simulated strategies are not fixed lot based.

    #135844
    Administrator
    3147 Posts

    sorry, I dont understand why this aproach wouldn’t work. 

    What you want is to recompute trade sizes, and this is possible only by applying money management.

    The program doesn’t know which money management you used when you mix two strategies into a portfolio.

     

    Create portfolio from your two strategies, then use Money management to re-run the position sizing and it will do exactly what you want – it will compute the new trading sizes depending on the running account balance.

     

    If the problem is that you use some special money management type you can create a snippet that computes it.

    Mark
    StrategyQuant architect

    #135848
    Customer
    9 Posts

    The program does not need to know about the money management. Money management is part of each individual strategy. When you build a portfolio, each strategy is influenced by the result of the previous one. With the method you propose there is no influence between strategies. Let’s take an example:

    Strat1:

    01/01 -> bal: 10.000

    02/01 -> trade: 1 lot -> P&L: -5.000 -> bal: 5.000

    Start2:

    01/01 -> bal: 10.000

    03/01 -> trade: 2 lots -> P&L: 5.000 -> bal: 15.000

     

    portfolio:

    01/01 -> bal:10.000

    02/01 -> trade: 1 lot -> P&L: -5.000 -> bal: 5.000

    03/01 -> trade: 2 lots -> P&L: 5.000 -> bal: 10.000

     

    appy MM 5%, 1.0 lots

    01/01 -> bal: 10.000

    02/01 -> trade: 0.50 lot -> P&L: -2.500 -> bal: 7.500

    03/01 -> trade: 0.37 lot -> P&L: 925 -> bal: 8.425

     

    In reality If you mix both stratégies together on 1 account the result is:

    01/01 -> bal: 10.000

    02/01 -> trade: 1 lot -> P&L: -5.000 ->bal: 5.000

    03/01 -> trade: 1 lot (2 lots * 5.000 / 10.000) -> P&L: 2.500 -> bal: 7.500

     

    In reality MM is applied by each strategy individually and a good approximation is a proportion of account balance (should be free margin or equity but that is not possible to simulate).

     

    Can you see the difference?

    I took a quick look at the extensions, it looks like a createPortfolio method would need to be overloaded. Is it possible? Can you provide a skeleton or even the original code for the implementation so that I give a try to the modification I need?

    #135850
    Administrator
    3147 Posts

    ok, I got you now. So you have different MM for every strategy, that’s why you cannot use Money Management to recompute it for portfolio as a whole.

     

    sorry, createPortfolio() method is not public, we might make ti public in new version, but right now it is too complicated.

     

    But there is another possibility, that I believe is easier.

     

    If you have some way to distinguish between the strategies – for example using their comments or symbols they trade on, then you can write a custom Money Management snippet that will apply the correct money management formula depending on the strategy.

    This way you can simulate it exactly.

     

    But I got your idea about proportionally recalculating sizes in when combining strategies into portfolio, I think we’ll add it in one of the next updates.

    Mark
    StrategyQuant architect

    #135851
    Customer
    9 Posts

    I’m looking forward for such feature in the near future.

     

    But your proposal will work for me indeed. I have EAs that integrate several algo already. Each algo has a different money management. So with the EA I can see the dependencies of different algos on the same currency pair. Now I’d like to see the dependencies on different currency pairs but MT4 does not support simulation on several currencies.

     

    I’ll keep track of the running balance for each currency pair and compute ratios with current portfolio balance. I took a look at some money management samples. There is a mention of equity, but I guess this is really the account balance, am I right?

    #136950
    Customer
    29 Posts

    ok, I got you now. So you have different MM for every strategy, that’s why you cannot use Money Management to recompute it for portfolio as a whole.

     

    sorry, createPortfolio() method is not public, we might make ti public in new version, but right now it is too complicated.

     

    But there is another possibility, that I believe is easier.

     

    If you have some way to distinguish between the strategies – for example using their comments or symbols they trade on, then you can write a custom Money Management snippet that will apply the correct money management formula depending on the strategy.

    This way you can simulate it exactly.

     

    But I got your idea about proportionally recalculating sizes in when combining strategies into portfolio, I think we’ll add it in one of the next updates.

    Hi Mark, I ran into this same situation when combining two strategies in QA using Fixed % MM as it isn’t proportionally recalculating the sizes when combining the strategies into one portfolio.  This doesn’t allow me to properly analyse my portfolio at all.  A dangerous limitation that I’m glad I was able to identify upfront. What solution if any will you provide to this issue so traders who want to use a Fixed % Money Management strategy with multiple strategies trading as 1 portfolio will have the necessarily tools to properly analyze their portfolio prior to live testing.

    #137036
    Administrator
    3147 Posts

    the only way to handle this is to add proportional recomputation of sizes when combining strategies into portfolio.

     

    We’ll add it in one of teh next updates, but I cannot promise when exactly it will be released.

     

    But I think this process could also work:

    1. convert all strategies to fixed size money management

    2. combine them to portfolio

    3. use MM simulation on the portfolio to simulate Fixed % MM 

     

    If I’m not mistaken this should create portfolio with the trades that are proportional.

    Mark
    StrategyQuant architect

    #137042
    Customer
    436 Posts

    the only way to handle this is to add proportional recomputation of sizes when combining strategies into portfolio.

     

    We’ll add it in one of teh next updates, but I cannot promise when exactly it will be released.

     

    But I think this process could also work:

    1. convert all strategies to fixed size money management

    2. combine them to portfolio

    3. use MM simulation on the portfolio to simulate Fixed % MM 

     

    If I’m not mistaken this should create portfolio with the trades that are proportional.

     

     

    Hi all,

     

    If I am understanding you correctly, I overcame the proportional issue by writing the following QA snippet so 

    1. combine strategies to portfolio

    2. use MM simulation on the portfolio and use the balance per lot.

     

    This works for the way I trade so I hope you can make use of it.

    package com.strategyquant.extend.MoneyManagementTypes;
    
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    
    import com.strategyquant.futurelib.backtester.SymbolInfo;
    import com.strategyquant.futurelib.backtester.SymbolsTable;
    import com.strategyquant.lib.computers.OrderPLComputer;
    import com.strategyquant.lib.language.L;
    import com.strategyquant.lib.results.SQOrder;
    import com.strategyquant.lib.results.SQOrderList;
    import com.strategyquant.lib.snippets.MoneyManagementSim.MoneyManagementType;
    import com.strategyquant.lib.utils.SQUtils;
    
    public class BalancePerLot extends MoneyManagementType {
    	public static final Logger Log = LoggerFactory.getLogger("BalancePerLot");
    	
    	private double mmBalance = -1;
    	private double mmMaxLots;
    
    	private int mmLots;
    
    	public BalancePerLot() {
    		setName("Balance per lot");
    		setNote(L.tHtml("Balance per lot"));
    		
    		addDoubleParameter("Balance", "Balance in $", 50000d, 1d, 1000000d, 10d, L.t("How much balance the system/portfolio must have in order to trade 1 whole lot?"));
    		addDoubleParameter("Lots", "Lots if no MM", 1d, 0.01d, 1000000d, 0.1d, L.t("How many lots should be traded if we disable or cannot use Money Management - for example when computed trade size is 0"));
    		addDoubleParameter("MaxLots", "Maximum lots", 5d, 0.01d, 1000000d, 0.1d, L.t("The biggest lot size allowed"));
    		
    		setFormatedName("${Balance} per whole lot");
    	}
    
    	@Override
    	public void init(SQOrderList originalOrderList, SymbolsTable symbolsTable) throws Exception {
    		mmBalance = this.getDoubleParameterValue("Balance");
    		mmLots = this.getIntParameterValue("Lots");
    		mmMaxLots = this.getDoubleParameterValue("MaxLots");
    	}
    
    	@Override
    	public double computeTradeSize(SQOrder order, double tickSize, double pointValue) throws Exception {
    		if(mmBalance < 0) {
    			throw new Exception("Money management wasn't properly initialized. Call init() method before computing trade size!");
    		}
    		
    		double tradeSize = 0;
    		double orderSL;
    		
          tradeSize = equity / mmBalance ; 
    
    		Log.info("trade size computed to: "+tradeSize);
    
    		// round computed trade size to give decimal points and cap it by maximum lots
    		tradeSize = SQUtils.roundDown(tradeSize, getDecimals());
    		if(tradeSize  mmMaxLots) {
    			tradeSize = mmMaxLots;
    		}
    		
    		return tradeSize;
    	}
    }
    
    #137067
    Customer
    29 Posts

    Hi Mark,

     

    Thank you for responding to my message and with a work around to solve the problem. Notch Thanks for the QA snippet

Viewing 15 posts - 1 through 15 (of 16 total)

You must be logged in to reply to this topic.