Niklaus

Alpha strategy - simple version

This Strategy goes long when Sharpe Ratio is > 1 and Alpha against the S&P500 is generated. It exits when conditions break away. en.wikipedia.org/wiki/Alpha_(finance). Use on daily or 5min.
Скрипт с открытым кодом

В истинном духе TradingView автор этого скрипта опубликовал его с открытым исходным кодом, чтобы трейдеры могли понять, как он работает, и проверить на практике. Вы можете воспользоваться им бесплатно, но повторное использование этого кода в публикации регулируется Правилами поведения. Вы можете добавить этот скрипт в избранное и использовать его на графике.

Отказ от ответственности

Все виды контента, которые вы можете увидеть на TradingView, не являются финансовыми, инвестиционными, торговыми или любыми другими рекомендациями. Мы не предоставляем советы по покупке и продаже активов. Подробнее — в Условиях использования TradingView.

Хотите использовать этот скрипт на графике?
//@version=2
strategy("Alpha strategy - simple version", overlay=true)

//by NIKLAUS
//USE ON DAILY TIMEFRAME TO DETECT MOMO STOCKS & ETFs AND TRADE THEM
//USE ON 5MIN CHART FOR INTRADAY USAGE
//examples to try this on: GER30, NAS100, JPN225, AAPL, IBB, TSLA, FB, etc.

//This Strategy goes long when Sharpe Ratio is > 1 and Alpha against the S&P500 is generated. It exits when conditions break away.

//https://en.wikipedia.org/wiki/Alpha_(finance)
//------------------------------------------------------------------------------------------------------------------------------------
//Alpha is a measure of the active return on an investment, the performance of that investment compared to a suitable market index. 
//An alpha of 1% means the investment's return on investment over a selected period of time was 1% better than the market during that same period, 
//an alpha of -1 means the investment underperformed the market. 
//Alpha is one of the five key measures in modern portfolio theory: alpha, beta, standard deviation, R-squared and the Sharpe ratio.


//simplified sharpe
src = ohlc4, len = input(180, title = "Sharpe/Alpha/Beta Period")
pc = ((src - src[len])/src)
std = stdev(src,len)
stdaspercent = std/src
sharpe = pc/stdaspercent


//alpha
sym = "SPX500", res=period, src2 = close
ovr = security(sym, res, src2)

ret = ((close - close[1])/close)
retb = ((ovr - ovr[1])/ovr)
secd = stdev(ret, len), mktd = stdev(retb, len)
Beta = correlation(ret, retb, len) * secd / mktd

ret2 = ((close - close[len])/close)
retb2 = ((ovr - ovr[len])/ovr)

alpha = ret2 - retb2*Beta
//plot(Beta, color=green, style=area, transp=40)


smatrig = input(title="Sensitivity", type=integer, defval=2, minval=1, maxval=3) 
bgcolor (sma(sharpe,len/smatrig) > 1 and sma(alpha,len/smatrig) > 0 ? green : red, transp=70)

if (close > open) and (sma(sharpe,len/smatrig) > 1) and (sma(alpha,len/smatrig) > 0)
    strategy.entry("Alpha", strategy.long)
strategy.close("Alpha", when = (sma(sharpe,len/smatrig) < 1) or (sma(alpha,len/smatrig) < 0))