Preview:
def out_of_conf(x, y):
btc = [5.0] + [np.nan] * (len(dff)-1)
cash = [0] + [np.nan] * (len(dff)-1)
prediction = list(dff['Predictions'])
price = list(dff['Price'])
for i in range(1, len(dff)):
for j in range(0, 2):
if (prediction[i] * (1.0 - (y/100.0))) > price[i]:
if cash[i-1] > price[i]:
btc[i] = btc[i-1] + 1
cash[i] = cash[i-1] - price[i]
elif price[i] > cash[i-1] > 0.0:
btc[i] = btc[i-1] + (cash[i-1] / price[i])
cash[i] = 0.0
else:
btc[i] = btc[i - 1]
cash[i] = cash[i - 1]
elif price[i] > (prediction[i] * (1.0 + (x/100.0))):
if btc[i-1] >= 1.0:
btc[i] = btc[i-1] - 1
cash[i] = cash[i-1] + price[i]
elif 1.0 > btc[i-1] > 0.0:
btc[i] = 0
cash[i] = cash[i-1] + (price[i] * btc[i-1])
else:
btc[i] = btc[i - 1]
cash[i] = cash[i - 1]
else:
btc[i] = btc[i-1]
cash[i] = cash[i-1]
dff['BTC'] = btc
dff['Cash'] = cash
dff['Strategy'] = dff['Price'] * dff['BTC'] + dff['Cash']
dff['BuyNHold'] = 5.0 * dff['Price']
dff['St_VS_BnH_N'] = dff['Strategy'] - dff['BuyNHold']
dff['St_VS_BnH_P'] = ((dff['Strategy'] - dff['BuyNHold']) / dff['BuyNHold']) * 100.0
dff['BnH_Vol'] = (dff['BuyNHold'].pct_change() * 100.0).rolling(30).std(ddof=0)
dff['Strategy_Vol'] = (dff['Strategy'].pct_change() * 100.0).rolling(30).std(ddof=0)
print "Strategy vs BuyNHold:", (dff['Strategy'][len(dff)-1] - dff['BuyNHold'][len(dff)-1])
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter