• Australian (ASX) Stock Market Forum

Hello and welcome to Aussie Stock Forums!

To gain full access you must register. Registration is free and takes only a few seconds to complete.

Already a member? Log in here.

Position size AFL help needed

Discussion in 'Software and Data' started by deVille1, Jul 26, 2017.

  1. deVille1

    deVille1

    Posts:
    2
    Likes Received:
    0
    Joined:
    Jul 26, 2017
    The system I am testing opens random number of positions every day (Long only), and closes at the end of the day (yesterday bought 4 stocks, today bought 10 stocks, etc.). I am trying to allocate the same % of equity to each position, but since the number of positions is different every day I am not sure how to do it.

    I used:
    SetPositionSize(10,spsPercentOfEquity)

    - but it didn't solve the problem as it always allocates 10% of equity to each position, no matter how many positions it is going to open.
    What I need is (for example):

    - when the system buys 4 stocks it should assign 25% of equity to each stock
    - when it buys 10 tocks it should assign 10% of equity to each stok
    - when it opens 20 positions it should assign 5% of equity to each stock, etc.

    Is there any way to code it?

    Thank you in advance
    Daniel
     
  2. Quant

    Quant

    Posts:
    492
    Likes Received:
    142
    Joined:
    Dec 13, 2015
    I don't use AFL so I'm clueless on exact code but you need to make the 10 a variable and have that variable calculated as 100 divided by the number of stocks in your scan/whatever defines that number if that data is available to your software , if it isn't that's the next solution you require

    make 10 (a)

    make number of stocks in scan (b)

    a = 100/b
     
  3. deVille1

    deVille1

    Posts:
    2
    Likes Received:
    0
    Joined:
    Jul 26, 2017
    I am not an expert in afl too, and this is actually my biggest issue, what afl function retrieves the number of positions?
     
  4. captain black

    captain black

    Posts:
    1,281
    Likes Received:
    745
    Joined:
    Oct 24, 2005
Loading...

Share This Page