Maybe something like this (can be simplified, but I am on a phone, so
that’s painful):

M=: +/ % #

   (M@:>:&0([ - -.@[ % (%|)/@\:~@(M/.~) @])])2 _1

0.25


Thanks,


—

Raul

On Thursday, July 12, 2018, Devon McCormick <[email protected]> wrote:

> Working with an article on implementing the Kelly Criterion in Python (
> http://quantfiction.com/2018/05/06/position-sizing-for-
> practitioners-part-1-beyond-kelly/
> ), I first, lazily, translated some Python code like this:
> kellyFraction=: 3 : 0
>    returns=. y
>    losses=. }.losses [ 'losses wins'=. (0,returns>0) </. 0,returns
>    R=. ((+/%#) wins) % |(+/%#) losses [ W=. (#wins) % #returns
>    W-(1-W)%R
> )
>    kellyFraction 2 _1
> 0.25
>
> Reworking the code to be more J-like, I came up with this version:
> kellyFraction=: 3 : 0
>    'losses wins'=. }.&.>(0 1,y>0) </. 0 0,y
>    ((#wins) % #y) ([-] %~ [: -.[) ((+/%#) wins) % |(+/%#) losses
> )
>
> The partitioning of losses and wins seems a bit awkward.  Part of the
> awkwardness is the prepending I do (0 1,... and 0 0,...) to force the
> losses and wins to be in the expected order.  However, it also seems that
> there may be some way to apply the dyadic, tacit expression on the last
> line using "key" (/.) directly but I don't see how.
>
> Am I expecting too much here?
>
> --
>
> Devon McCormick, CFA
>
> Quantitative Consultant
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to