Class: FinModeling::CAPM::Beta
- Inherits:
-
Object
- Object
- FinModeling::CAPM::Beta
- Defined in:
- lib/finmodeling/capm.rb
Class Method Summary collapse
-
.from_ticker(company_ticker, num_days = 6*365, index_ticker = "SPY") ⇒ Object
Possible index tickers: “Spy” -> S&P 500 “^IXIC” -> Nasdaq.
Class Method Details
.from_ticker(company_ticker, num_days = 6*365, index_ticker = "SPY") ⇒ Object
Possible index tickers: “Spy” -> S&P 500 “^IXIC” -> Nasdaq
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/finmodeling/capm.rb', line 30 def self.from_ticker(company_ticker, num_days=6*365, index_ticker="SPY") index_quotes = FamaFrench::EquityHistoricalData.new(index_ticker, num_days) company_quotes = FamaFrench::EquityHistoricalData.new(company_ticker, num_days) common_dates = index_quotes .year_and_month_strings & company_quotes.year_and_month_strings index_quotes .filter_by_date!(common_dates) company_quotes.filter_by_date!(common_dates) index_div_hist = NasdaqQuery::DividendHistory.for_symbol(index_ticker) company_div_hist = NasdaqQuery::DividendHistory.for_symbol(company_ticker) index_monthly_returns = index_quotes .monthly_returns(index_div_hist) company_monthly_returns = company_quotes.monthly_returns(company_div_hist) x = GSL::Vector.alloc(index_monthly_returns) y = GSL::Vector.alloc(company_monthly_returns) intercept, slope, cov00, cov01, cov11, chisq, status = GSL::Fit::linear(x, y) # FIXME: evaluate [intercept - Rf*(1-beta)]. It tells how much better/worse than expected (given its risk) the stock did. [per time period] # FIXME: subtracting/adding one standard error of the beta gives a 95% confidence interval. That could be used to give a confidence interval # for the resulting valuation. beta = slope end |