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. اقرأ المزيد في شروط الاستخدام.

هل تريد استخدام هذا النص البرمجي على الرسم البياني؟
//@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))