Capital Asset Pricing Model (CAPM) [Loxx]Capital Asset Pricing Model (CAPM) demonstrates how to calculate the Cost of Equity for an underlying asset using Pine Script. This script will only work on the monthly timeframe. While you can change the default inputs, you should study what CAPM is and how this works before doing so. This indicator pulls various types of data from SPY from various timeframes to calculate risk-free rates, market premiums, and log returns. Alpha and Beta are computed using the regression between underlying asset and SPY. This indicator only calculates on the most recent data. If you wish to change this, you'll have to save the script and make adjustments. A few examples where CAPM is used:
Used as the mu factor Geometric Brownian Motion models for options pricing and forecasting price ranges and decay
Calculating the Weighted Average Cost of Capital
Asset pricing
Efficient frontier
Risk and diversification
Security market line
Discounted Cashflow Analysis
Investment bankers use CAPM to value deals
Account firms use CAPM to verify asset prices and assumptions
Real estate firms use variations of CAPM to value properties
... and more
Details of the calculations used here
Rm is calculated using yearly simple returns data from SPY, typically this is just hard coded as 10%.
Rf is pulled from US 10 year bond yields
Beta and Alpha are pulled form monthly returns data of the asset and SPY
In the past, typically this data is purchased from investments banks whose research arms produce values for beta, alpha, risk free rate, and risk premiums. In 2022 ,you can find free estimates for each parameter but these values might not reflect the most current data or research.
History
The CAPM was introduced by Jack Treynor (1961, 1962), William F. Sharpe (1964), John Lintner (1965) and Jan Mossin (1966) independently, building on the earlier work of Harry Markowitz on diversification and modern portfolio theory. Sharpe, Markowitz and Merton Miller jointly received the 1990 Nobel Memorial Prize in Economics for this contribution to the field of financial economics. Fischer Black (1972) developed another version of CAPM, called Black CAPM or zero-beta CAPM, that does not assume the existence of a riskless asset. This version was more robust against empirical testing and was influential in the widespread adoption of the CAPM.
Usage
The CAPM is used to calculate the amount of return that investors need to realize to compensate for a particular level of risk. It subtracts the risk-free rate from the expected rate and weighs it with a factor – beta – to get the risk premium. It then adds the risk premium to the risk-free rate of return to get the rate of return an investor expects as compensation for the risk. The CAPM formula is expressed as follows:
r = Rf + beta (Rm – Rf) + Alpha
Therefore,
Alpha = R – Rf – beta (Rm-Rf)
Where:
R represents the portfolio return
Rf represents the risk-free rate of return
Beta represents the systematic risk of a portfolio
Rm represents the market return, per a benchmark
For example, assuming that the actual return of the fund is 30, the risk-free rate is 8%, beta is 1.1, and the benchmark index return is 20%, alpha is calculated as:
Alpha = (0.30-0.08) – 1.1 (0.20-0.08) = 0.088 or 8.8%
The result shows that the investment in this example outperformed the benchmark index by 8.8%.
The alpha of a portfolio is the excess return it produces compared to a benchmark index. Investors in mutual funds or ETFs often look for a fund with a high alpha in hopes of getting a superior return on investment (ROI).
The alpha ratio is often used along with the beta coefficient, which is a measure of the volatility of an investment. The two ratios are both used in the Capital Assets Pricing Model (CAPM) to analyze a portfolio of investments and assess its theoretical performance.
To see CAPM in action in terms of calculate WACC, see here for an example: finbox.com
Further reading
en.wikipedia.org
P-value
Blockchain Fundamentals - Active Address Sentiment Osc. [CR]Blockchain Fundamentals: Active Address Sentiment Oscillator AASO
Back with another script today, this one is a useful tool in helping to determine bitcoins value. We are looking at 2 data sources: the daily active addresses on the BTC blockchain, and the daily returns of BTC.
THIS INDICATOR WILL ONLY GIVE YOU THE CORRECT RESULTS ON THE DAILY TIMEFRAME
There is an interesting relationship that you can see by comparing the two timeseries. But for us to create a good indicator we first need to normalize the data. So we look at the percent change over the past 28 days for each metric (DAA and price).
THIS INDICATOR WILL ONLY GIVE YOU THE CORRECT RESULTS ON THE DAILY TIMEFRAME
We then calculate standard deviation bands around the DAA metric. We finalize them by averaging the bands over a 28 day period.
When the Price series (yellow line) is higher than the SD bands BTC is considered overvalued or price is overheated. A pullback could be expected soon. When the Price series is below the SD bands BTC is considered undervalued or price is oversold.
THIS INDICATOR WILL ONLY GIVE YOU THE CORRECT RESULTS ON THE DAILY TIMEFRAME
This tool doesnt give signals on the one minute chart or tell you exactly when to buy or sell. BUT what it does do is act as a convenient macro sentiment indicator that is not based completely upon price.
In an attempt to narrow down the really juicy areas, if you seen the background color highlights with white, that means its likely a top or bottom. At the very least on a local sense and many times in a cyclical macro sense as well. It also narrows down the signal to a generally more profitable area.
This indicator is not meant to be used on timeframes other than daily (did I mention that already?). I am lazy and did not code the calculations to be MTF (which is why you have to use on the daily chart). If you want to code this, please forward it on to me and I will post an update with a heartfelt credit to you.
Blockchain Fundamentals: Electricity Cost of BTC [CR] Blockchain Fundamentals: Electricity Cost of BTC
After a hiatus, now a return to publishing tools and scripts for the community. This is my first script in over and year, and I have a number more coming soon as well! (so Stay Tuned!)
This is a simple calculator to estimate the cost of Bitcoin miners to mine one bitcoin. It works on all timeframes (doesnt have to be on daily).
By entering the inputs of total TH's, kWh used, cost of electricity per kWh (in USD cents) we can generate the electricity cost.
But miners also have other costs of operation including HVAC, maintenance, rent, etc. In light of that we include a multiplier that accounts for these extra costs. First, type in what percent of your total operating costs come from the electricity. Then check the enable total cost plot option and you will also see total costs in addition to electricity costs.
Its a simple model and gives anyone curious a starting point for their own testing and research.
Close Combination Lock Style - Visual AppealThis creates a combination style closing price change on each tick.
It has two theme options, one as silver dials for Dark Theme and the other as black dials for White Theme.
We get fixated to watching closing prices on charts and it gets visually daunting. This creates a combination style price change which updates on each tick, which is quite pleasing to the eye.
When new price is above current center line, it shift the above prices showing ▲ arrow, and if new price is lower, it will shift the bottom prices showing ▼ arrow. If there is no change in price between the ticks, it will show =.
Outlier Detector with N-Sigma Confidence IntervalsA detrended series that oscilates around zero is obtained after first differencing a time series (i.e. subtracting the closing price for a candle from the one immediately before, for example). Hypothetically, assuming that every detrended closing price is independent of each other (what might not be true!), these values will follow a normal distribution with mean zero and unknown variance sigma squared (assuming equal variance, what is also probably not true as volatility changes over time for different pairs). After studentizing, they follow a Student's t-distribution, but as the sample size increases (back periods > 30, at least), they follow a standard normal distribution.
This script was developed for personal use and the idea is spotting candles that are at least 99% bigger than average (using N = 3) as they will cross the upper and lower confidence interval limits. N = 2 would roughly provide a 95% confidence interval.
Stock Value Display//This study is designed to plot estimates for a stock's value:
//1) the Price to earnings ratio (PE) value based on the trailing twelve months of data
//2) the PE value based future data
//3) the Benjamin Graham value based trailing data
//4) the Dividend Discount value based on trailing data
You can adjust the period of data used to calculate the value between Fiscal Quarter "FQ" and Fiscal Year "FY."
The values displayed on the chart are subject to the financial information provided to TradingView. This is intended to be used as a quick reference and should be viewed in context with other analysis prior to making any transaction decisions.
As always, happy trading!
Compound Value @ annual rateBy studying historical data we can know the compounded growth rate of an investment from the inception date. For example if we know that an investment has grown at the rate of 6% in the past and if we expect similar growth in the future also, We can plot this graph to understand whether the current price is underpriced or overpriced as per projected return.
In this graph, it takes the initial close price as a principle and rate from the input and calculates the compound amount at each interval.
Intrinsic value calculation Intrinsic value calculator based on Warren Buffet's and Ben Graham's work
In value investing determing the true value of a COMPANY instead of a stock price is crucial.
This little indicator shows the "Intrinsic value" of the choosen stock meaning the value of the stock in 10 years time. Calculation is based on historical book value's average annual growth rate and dividends paid.
Since this is about long therm investing, use monthly charts.
"Intrinsic value can be defined simply: It is the discounted value of the cash that can be taken out of a business during its remaining life.”
– Warren Buffett
One way to calculate that is by the growth in per share book value and dividends taken in the forseeable future (10 years) than discount it with the prevailing 10 year note's rate.
In the inputs you have to set 2 variables:
1. How many years back you have the first data for book value per share available?
2. What was the per share book value that year?
(Bookvalue is ploted in olive colour and you can get the oldest one if you move your cursor over the latest data on the left)
CAUTION! You have to reenter it for every stock you analyse as this is stock-specific data!
After setting the input data, you will see the "Intrinsic Value"'s pink curve ploted over the price chart.
If the price is well below the pink line, the company is undervalued and can be a possible applicant for long therm investment.
Margin of safety: when the current price is 50% below the intrinsic value that means a 10% yearly growth potential (100% growth in 10 years) or a 100% margin of safety.
I am a beginer in Pine so please excuse my coding...
If anybody knows hot to extract historical data from 15 years ago, please share it with me, so I can automate the whole calculation without inputs necessary.
Volume ValueInstead of the Volume this plots the closure price times volume, hence the Value.
Useful in study of long term phenomenons.
Current Price Label by Westy_A simple Indicator to display the current price of the asset above the current bar. It shows a green label if the close is equal or greater than the open, red otherwise.
NVT Signal with RMA and thresholds [alertable]NVT Signal, or NVTS, is an indicator that compares the market cap of Bitcoin to the aggregate USD value of daily transactions on the Bitcoin blockchain. It is a value indicator that shows a multiple of Bitcoin price against the actual usage of its blockchain. When the NVTS is low, it suggests Bitcoin price is low relative to the amount of utility the network provides, and vice versa.
For more information on NVTS, visit medium.com
This indicator aims to provide the following:
1. An open-source implementation of NVTS on Tradingview, as the most popular one currently is closed-source.
2. To provide two simple ways to define and visualize "overbought" or "oversold" conditions using the NVTS. Here, we have absolute value of NVTS & deviation from a long-term moving average.
3. Crude integration into Tradingview's alert system.
What this indicator CANNOT do:
1. Timeframes below 1d.
2. Signals based on statistical analyses, such as seen in Bollinger Bands et al. (However, with the appropriate type of account, you can add BBands on top of this indicator.)
I would like to express my gratitude to Willy Woo, Chris Burniske and Dimitry Kalichkin for their work on NVT Ratio and NVT Signal, without which my indicator would not have been created.
Feel free to fork & improve, or experiment with settings. I hope this indicator will be useful to someone.
BitMEX ETHUSD contract value (USD)The ETHUSD Quanto Swap contract on BitMEX allows you to trade ETHUSD with Bitcoin put forward as collateral. However this means that 1 contract is not equal to 1 USD or 1 ETH, but instead varies according to the price of ETHUSD.
You can see the contract specs here www.bitmex.com and find more information here blog.bitmex.com
My advice is always to make sure you fully understand a derivative product before you trade it, however many of us may not have the acumen to actually understand how a quanto swap works. Nevertheless, we have to be aware that the value in USD of each contract depends on the price of Ethereum and also the price of Bitcoin at each point in time.
This tool will show you the value of a single ETHUSD contract in USD, but it solely for indicative purposes only. Your trade, your risk. I do not ask for any donations from your gains and I am not liable for any of your losses.
Source code is provided.
Note in the example image that the price of ETHUSD is plotted on a logarithmic scale but the indicative contract value is linear.
Chiki-Poki BFXLS Longs Shorts Abs Normalized Volume Pro by RRBChiki-Poki BFXLS Longs vs Shorts Absolute Normalized Volume Value Pro by RagingRocketBull 2018
Version 1.0
This indicator displays Longs vs Shorts in a side by side graph, shows volume's absolute price value and normalized volume of Longs/Shorts for the current asset. This allows for more accurate L/S comparisons (like a log scale for volume) since volume on spot exchanges (Bitstamp, Bitfinex, Coinbase etc) is measured in coins traded, not USD traded. Similarly, L/S is usually the amount of coins in open L/S positions, not their total USD value. On Bitmex and other futures exchanges volume is measured in USD traded, so you don't need to apply the Volume Absolute Price Value checkbox to compare L/S. You should always check first whether your source is measured in coins or USD.
Chiki-Poki BFXLS primarily uses *SHORTS/LONGS feeds from Bitfinex for the current crypto asset, but you can specify custom L/S source tickers instead.
This 2-in-1 works both in the Main Chart and in the indicator pane below. You can switch between Main/Sub Window panes using RMB on the indicator's name and selecting Move To/Pane Above/Below.
This indicator doesn't use volume of the current asset. It uses L/S ticker's OHLC as a source for SHORTS/LONGS volumes instead. Essentially L/S => L/S Volume == L/S
Features:
- Display Longs vs Shorts side by side graph for the current crypto asset, i.e. for BTCUSD - BTCUSDLONGS/BTCUSDSHORTS, for ETHUSD - ETHUSDLONGS/ETHUSDSHORTS etc.
- Use custom OHLC ticker sources for Longs/Shorts from different exchanges/crypto assets with/without exchange prefix.
- Plot Longs/Shorts as lines or candles
- Show/Hide L/S, Diff, MAs, ATH/ATL
- Use Longs/Shorts Volume Absolute Price Value (Price * L/S Volume) instead of Coins Traded in open L/S positions to compare total L/S value/capitalization
- Normalize L/S Volume using Price / Price MA / L/S Volume MA
- Supports any existing type of MA: SMA, EMA, WMA, HMA etc
- Volume Absolute Price Value / Normalize also works on candles
- Oscillator mode with negative axis (works in both Main Chart/Subwindow panes).
- Highlight L/S Volume spikes above L/S MAs in both lines/oscillator.
- Change L/S MA color based on a number of last rising/falling L/S bars, colorize candles
- Display L/S volume as 1000s, mlns, or blns using alpha multiplier
1. based on BFXLS Longs vs Shorts and Compare Style, uses plot*, security and custom hma functions
2. swma has a fixed length = 4, alma and linreg have additional offset and smoothing params
Notes:
- Make sure that Left Price Scale shows up with Auto Fit Data enabled. You can reattach indicator to a different scale in Style.
- It is not recommended to switch modes multiple times due to TradingView's scale reattachment bugs. You should switch between Main Chart and Sub Window only once.
- When the USD price of an asset is lower you can trade more coins but capitalization value won't be as significant as when there are less coins for a higher price. Same goes for Shorts/Longs.
Current ATH in shorts doesn't trigger a squeeze because its total value is now far less than before and we are in a bear market where it's normal to have a higher number of shorts.
- You should always subtract Hedged L/S from L/S because hedged positions are temporary - used to preserve the value of the main position in the opposite direction and should be disregarded as such.
- Low margin rates increase the probability of a move in an underlying direction because it is cheaper. High margin rates => the market is anticipating a move in this direction, thus a more expensive rate. Sudden 5-10x rate raises imply a possible reversal soon. high - 0.1%, avg - 0.01-0.02%, low - 0.001-0.005%
You can also check out:
- BFXLS Longs/Shorts on BFXData
- Bitfinex L/S margin rates and Hedged L/S on datamish
- Bitmex L/S on Coinfarm.online
Session min/max pointsMinimum and maximum points in a day trading session. It may help you spot the range which min and max occur in a session.
In day trading, for example, at securities like GBPNZD, minimum happens between 02:00-05:00 ET and maximum between 08:00-14:00 ET. This indicator can help you test this hypothesis.
Happy trading!
Function - Integral PriceFunction to convert floating numeric price to its *integral* value, ex: 1.2345 --> 12345.
integral might not be the right name, so pardon my engrish :p.
Rate Of Change - Absolute ValueMeasures the period's change in terms of the instrument's value (e.g. pip, dollar, etc) instead of as a percentage. I generally use it on a daily time frame with a period=1 to see how the current day's move compares with prior days' moves in order to gain a perspective into how this move ranks historically.
Simple Horizontal Value and Offsets [Auto Shift]Original (Simple Horizontal Value and Offsets/SHV) Requested by @TAFA94
Description:
Simple adjustable incremented horizontal offset lines extending up and down from a Median point.
Set full value for manual Median point control, or set an incremental rounding value for auto Median adjustment.
Source and look-back period inputs for fine tuning auto adjust.
Auto adjust on by default - can be toggled off for straight manual control.
**NOTE**
All values will likely need to be changed immediately on applying this script, in order to properly fit your charts specific price/value range and/or time resolution.
Cheers!
Simple Horizontal Value and OffsetsRequested by @TAFA94
Simple horizontal values extending up and down from a median value.
Set Median Value, and set offset values. Simples!
UCS_Extreme Snap Back (TVI)I am calling it a SNAP BACK indicator.
Utilizing the TVI (Transactional Value Index - Link below for indicator / setups)
You can pretty much guess when any instrument could slow down, last stand in a pullback and the last few candles before losing its strong trend.
It varies per person, a short term trader can use this, Long term traders can hedge with options.
A great tool for my trading. Thought I will share this.
This utilizes TVI indicator, currently the TVI is manipulated manually, I have automated a version for future release.
Embrace trading - keep the money flowing.
UCSgears_Transaction Valuation IndexHere is the Version 2 of the TVI indicator posted earlier.
This is inspired from the Value Charts Indicator.
Version 1
Value Chart [TMC]*** April 20, 2015 - NEW UPDATE ***
Added classic color scheme and additional lines. Updated source: pastebin.com
April 10, 2015 - Updated version of Value Chart - candles draw correctly now.
Requires cover layer to be set as same color as your background. (white in default)
I hope you will enjoy it. :)
UCS_Transactional Valuation Index-Version 2Version 1 -
Updates include
Better Optimization on the levels.
Plotting only the important Highs and Lows
The extremes can be an important pivot levels.
Over and Undervalue - Gray (Column - close) (Histogram - High/Low)
Extreme conditions - Red
Extreme Alerts and Overlay will be added later.
UCSgears_Transaction Valuation IndexThis is an indicator, That works great in a wip-saw market range. Would not use this to trade in a breakout.
I am calling it the "Transaction Value Index (UCS_TVI)", The reason is because, it measure where the price currently from the mean trade value.
The cross represents the highest trade value on that day, circle represents the lowest trade value.
In other words, Top and bottom of the candle wicks, in relation to the mean trade value (MTV).
Watchout for Further Updates on Optimizing this indicator.
DO NOT CONFUSE IT WITH FUNDAMENTAL VALUATION, THIS IS PURELY TECHNICAL VALUATION TECHNIQUE
As Usual, Good Luck
List of All my Indicators - www.tradingview.com