InvestorsHub Logo
icon url

Toofuzzy

10/24/15 9:45 PM

#261 RE: neko #260

Just pretend you yave more shares


Toofuzzy
icon url

PraveenP

10/28/15 1:47 AM

#263 RE: neko #260

Hi Neko,

Below is the modified awk script.

Notice I added a "vcontrol" and "vshares" to track virtual shares. I defaulted to twice the control, but you can change it to any amount ( a multiple of control or an absolute number like "vcontrol = 1300").

It calculates the new virtual shares and then adds or subtracts actual shares based on the change to virtual shares. (it uses oshares and ovshares to store the old value).

So if virtual shares go up by 300, then you would buy 300 shares.



BEGIN {
control = 2000
vcontrol = 2 * control
cash = control
orig = control
}

{
price = $1
value = shares * price + cash
ovshares = vshares
oshares = shares
vshares = int(vcontrol / price)

if (vshares > ovshares)
shares = oshares + (vshares - ovshares)
else
shares = oshares - (ovshares - vshares)

if (shares < 0)
shares = 0

cash = value - shares * price
if (cash < 0)
{
value += -1*cash
orig += -1*cash
cash = 0
}
print price" "shares" "cash" "value" "orig
}
icon url

PraveenP

10/28/15 2:16 AM

#264 RE: neko #260

I had to modify the script again, so that on the first price (when ovshares is 0) we calculate shares based on control (not vcontrol).

So here is the correct script:

BEGIN {
control = 2000
vcontrol = 2 * control
cash = control
orig = control
}

{
price = $1
value = shares * price + cash
ovshares = vshares
oshares = shares
vshares = int(vcontrol / price)

if (ovshares == 0)
shares = int(control / price)
else
if (vshares > ovshares)
shares = oshares + (vshares - ovshares)
else
shares = oshares - (ovshares - vshares)

if (shares < 0)
shares = 0

cash = value - shares * price
if (cash < 0)
{
value += -1*cash
orig += -1*cash
cash = 0
}
print price" "shares" "cash" "value" "orig
}