Ralph Vince's Java app (UI)

174 views
Skip to first unread message

mohitbgupta

unread,
Nov 2, 2014, 2:06:54 PM11/2/14
to leverage-sp...@googlegroups.com
Hello,

Could someone please let me know from where can i download Ralph's java app that calculates the "Joint Prob Table" and the Optimal F?
If you could also please let me know how to use the jar file or the exe to calcluate these values, some/any documentation is greatly appreciated.

I tried Joshua's R code but i do not get same Joint Prob Table as described by Ralph in his book "

The Leverage Space Trading Model"


Any help is greatly appreciated.

Regards,
mohit



Joshua Ulrich

unread,
Nov 12, 2014, 6:32:26 PM11/12/14
to leverage-sp...@googlegroups.com
Hi Mohit,

I wouldn't expect them to be the same.  The LSPM::jointProbTable() function applies the same function to each bin in order to calculate the value for that bin.  IIRC, Ralph's code uses different calculations for the max/min/remaining bins: the max/min bin gets the max/min value of all the observations in the max/min bin, while the rest of the bins get the median value of all observations in each bin.

Best,
Josh

--
You received this message because you are subscribed to the Google Groups "Leverage Space Trading" group.
To unsubscribe from this group and stop receiving emails from it, send an email to leverage-space-tr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Joshua Ulrich  |  about.me/joshuaulrich
FOSS Trading  |  www.fosstrading.com

Mohit Gupta

unread,
Nov 12, 2014, 11:55:39 PM11/12/14
to leverage-sp...@googlegroups.com
Hello Josh,
It was pleasantly surprised to have received your email, frankly i wasn't expecting any email.
Josh, i had a related question. Attached is a file that has the trades from a strategy that i am testing. I am testing the strategy on SPX.
The PnL is for a quantity (column C in the excel file) of "one" SPX (unit = one).

After running Ralph's formula for a single instrument in a portfolio i get the "optimal f" value of 0.92 for these trades (the strategy).
The max drawdown for this strategy is -260 so the dollar value for optimal f is $283.00

My question is how much cash should i dedicate/commit to trade one SPX.

For simplicity lets assume that SPX is trading at 1800.00, so as per Ralph i can trade /bet $1.00 for every $283.00 so does this mean i have to commit $509,400.00 (283 * 1800) to trade one SPX, this does not seem right. I wonder what am i doing wrong, any help would be greatly appreciated.

I am a software engineer and have worked in the finance industry for about 10 yrs, I believe if we could work together we could come up with some interesting strategies, please let me know if you think we could work together on something.
(l learned R in about a weeks time to understand your LSPM code, i thank you for sharing your code with all of us).

Regards,
Mohit


SPX_Trades.xlsx

Brady Preston

unread,
Nov 13, 2014, 2:42:05 AM11/13/14
to leverage-sp...@googlegroups.com
Hi mohit, 

The 283 would be the fdollar. Units = account size/ fdollar

Brady Preston 

Mohit Gupta

unread,
Nov 13, 2014, 10:07:44 AM11/13/14
to leverage-sp...@googlegroups.com
Brady,
That does not seem right either because the price of the SPX is $1800.00, but you are saying that i could commit 283 for each trade, i can't buy a SPX for $283 unless you are saying i need to use margin?

Could someone please clarify.

Your help is much appreciated.
Thanks,
Mohit


Brady Preston

unread,
Nov 13, 2014, 10:13:45 AM11/13/14
to leverage-sp...@googlegroups.com
You are buying 1 unit for every 283 in the account. Margin will limit you to the optimal value. 

Brady Preston

unread,
Nov 13, 2014, 10:21:45 AM11/13/14
to leverage-sp...@googlegroups.com
It depends on what you are using to trade the spx

I would also look at your drawdown level 260 seems a little low. Instead of using 260. You could use the close as your largest expected loss. So equity * .92 / close. This would then mean a 92% allocation to the spx.

The optimal value is not always the best place to be. This would mean a max drawdown would put you at 92% down.

Also are you sure the optimal f value is correct?

Mohit Gupta

unread,
Nov 13, 2014, 10:35:20 AM11/13/14
to leverage-sp...@googlegroups.com
Brady,
Thanks again, i had come to the same conclusion, that is to use 0.92% of my equity, but when i run the strategy with this allocation i do not see improved performance. In fact 100% allocation gives better results, so i really wonder if this thing even is worth or just some theory like many others. I guess that's why the book does not have real trading examples, i think that's why the LSPM based funds do not do all that well, its all theory.

I am very sure that the code is correct because I have used/applied it to the samples in the book and my results match.
here is the code just in case....

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            //double[] arrayPnL = new double[9] { 9, 18, 7, 1, 10, -5, -3, -17, -7 };
            //double[] arrayPnL = new double[98] { 1000.1, 2422.1, 1002.1, -595.9, -62.9, 1101.1, -519.9, -1246.9, 93.1, -128.9, -261.9, -220.9, 177.1, -91.9, -239.9, 2051.1, -196.9, -1133.9, -211.9, 166.1, -3196.9, -432.9, -988.9, 3873.1, 381.1, -355.9, 1250.1, 985.1, -2617.9, 254.1, 2690.1, -464.9, -1442.9, -645.9, 337.1, -10.9, -343.9, 2338.1, 839.1, 683.1, 168.1, -322.9, 4800.1, -1504.9, -541.9, -803.9, -1074.9, -1982.9, 2529.1, -975.9, -666.9, 4696.1, 1507.1, -81.9, -105.9, -402.9, 55.1, -16.9, -1325.9, 1604.1, 702.1, -1532.9, -501.9, 2175.1, 550.1, -4855.9, 7629.1, 1963.1, 219.1, 457.1, 724.1, 346.1, -1395.9, -4128.9, 1858.1, -995.9, -104.9, 4.1, -414.9, 2625.1, 318.1, 2392.1, -452.9, 346.1, 1358.1, -62.9, -82.9, -69.9, -357.9, 134.1, -530.9, 193.1, -1128.9, -98.9, 339.1, -342.9, 245.1, -1920.9 };
            //double[] arrayPnL = new double[35] { 4.8, 19.45, -2.58, 6.55, 12.52, 4.15, 10.9, 3.67, 3.67, 17.85, -0.61, -29.13, -14.74, 4.7, 4.93, 9.18, 9.4, 3.3, 6.24, 12.12, 2.26, -0.67, 29.08, 5.23, 9.76, -1.09, 9.78, 15.23, 6.3, 7.65, 1.41, 9.22, 3.52, 11.46, 2.2 };
            double[] arrayPnL = new double[38] {46.38, 44.47, 26.17, 56.93, 14.13, 19.95, -3.55, -10.28, 1.86, -5.9, 26.44, 52.94, 37.85, 29.27, 38.87, 29.78, -6.47, -23.87, 22.71, 60.17, 30.33, 43.6, 93.84, 70.72, 9.04, 61.88, 108.13, 36.6, 31.96, 6.11, 37.12, 50.59, 94.28, 10.42, 28.12, 25.16, 35.81, 33.94};
            double dblMaxDrawDown = 0;
            var sortedPnL = arrayPnL.OrderBy(x => x);
            Double f = 0.01, dblTWR = 1, dblTWRprev = -99999999;

            foreach (int x2 in sortedPnL)
            {
                dblMaxDrawDown = x2;
                break;
            }

            while (f <= 1.00)
            {
                for (int j = 0; j < arrayPnL.Count(); j++)
                {
                    //Console.WriteLine("Current value of n is {0}", n);
                    dblTWR = dblTWR * (1 + f * ((-arrayPnL[j]) / dblMaxDrawDown));
                }
                if (f > 0.01 && dblTWRprev > dblTWR) break;
                dblTWRprev = dblTWR;
                dblTWR = 1;
                f = f + 0.01;

            }

            //string ss = "";
        }
    }
}


Mohit

Brady Preston

unread,
Nov 13, 2014, 10:37:17 AM11/13/14
to leverage-sp...@googlegroups.com

I think you are missing something. How are you trading the SPX?

Mohit Gupta

unread,
Nov 13, 2014, 10:40:40 AM11/13/14
to leverage-sp...@googlegroups.com
Trading SPX with cash, hypothetically say 100K in the account, so 0.92 would mean allocating 92K to trading.

Brady Preston

unread,
Nov 13, 2014, 10:41:13 AM11/13/14
to leverage-sp...@googlegroups.com

Just buy and hold?

Mohit Gupta

unread,
Nov 13, 2014, 10:42:13 AM11/13/14
to leverage-sp...@googlegroups.com
Ofcourse not, based on the buy and sell signals from the strategy.

Brady Preston

unread,
Nov 13, 2014, 10:43:35 AM11/13/14
to leverage-sp...@googlegroups.com

The SPX is just an index. You can’t actually buy it. LSP is telling you to use margin

Mohit Gupta

unread,
Nov 13, 2014, 10:47:16 AM11/13/14
to leverage-sp...@googlegroups.com
I can buy SPY, that 1/10 of the Index. everything else would be levered down in the same ratio. Just assume that i could trade SPX. being able or not being able to trade is not even the issue at this time, we are discussing the validity of the whole thing assuming that i could buy SPX.

Brady Preston

unread,
Nov 13, 2014, 10:49:56 AM11/13/14
to leverage-sp...@googlegroups.com

Then of course 100% allocation will be optimal because you cannot trade 353 on 100k without leverage. Have you tried it with leverage?

Mohit Gupta

unread,
Nov 13, 2014, 10:52:34 AM11/13/14
to leverage-sp...@googlegroups.com
No, i have not tried with leverage, because i am always afraid of blowing things up, so i'd rather use cash.
To me the optimal f thing seems theoretical unless i see a real example. I would be very thankful if someone could post a real example so it makes things a little more clear. This could be valid for betting but not for trading.

Brady Preston

unread,
Nov 13, 2014, 10:59:40 AM11/13/14
to leverage-sp...@googlegroups.com

Optimalf is not a theory it is the optimal value given a set of data.

 

Compare these

 

Dow jones 30 vs LSP 30

 

Dow Jones 30 vs LSP XL 12

 

image001.png
image002.png

V Rao Bhamidipati

unread,
Nov 13, 2014, 11:43:26 AM11/13/14
to leverage-sp...@googlegroups.com
I had not recently looked at LSP (and probably forgot much of what I read earlier = time for reread).. but 
(a) you can buy SPX or options on it.. try ThinkorSwim or such. 
(b) options give you some or much of the leverage, as long as you understand everything else around options. 
(c) Almost ANY methodology will be better than top heavy indices like SPY, DOW30 etc.. (witness equal weighted funds like RSP etc..).  A more pragmatic comparison, if you are putting your real cash down for the trade, would be relative to these funds.  And when you do compare to these, you need to look at not only performance but also max. draw-down etc. to get a good idea of where LSP will or not help in your actual account balance.

V Rao Bhamidipati
 

sfclimbers

unread,
Nov 13, 2014, 10:20:42 PM11/13/14
to leverage-sp...@googlegroups.com
Mohit,

I'm assuming that you calculated your Optimal f over some history of trades (e.g. last 2 years of signals) and that you then tested it on a different set of trades (e.g. last 3 weeks of signals) or on trades not used in the original f calculation.

That being the case, keep in mind that Optimal f is the fraction that optimizes growth assuming that you continue to trade forever and that the returns continue to follow the same distribution as your analysis. So, running your strategy over one time period is just one combination of results out of an enormous number of possibilities, and is just one set of trades out of an infinite stream. Optimal f will not be best for every finite sequence of trades. Your 100% allocation might have been best for this sequence of trades. But, how would it do on the next sequence of trades, or the sequence of trades after that?

Optimal f is the fraction that is optimal for the infinite stream. Other fractions will perform better during some periods, but will under perform in other periods, to the point of being sub optimal for the combined periods. The fraction that is optimal across all periods is Optimal f. Since you do not know what combination of trades will come next, you're growth maximization is to trade at Optimal f.

Finally, were the sequence of trades tested compatible with the probability distribution of the trades used to calculation f? If not, you would need to re-optimize. The probabilities of our trading strategies are continuously changing as the market inefficiency exploited gradually disappears. Therefore, we optimize, trade for some number of periods, then optimize again to see whether f has changed. There are formulas for determining whether a sample (i.e. current signals) comes from the same population (i.e. signals used to calculate optimal f). If the current signals are found to not be from the same population, then your f is no longer accurate.
Reply all
Reply to author
Forward
0 new messages