Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User specific mean and variance for alpha and beta in Regression #54

Closed
sourish-cmi opened this issue Oct 6, 2022 · 3 comments · Fixed by #59
Closed

User specific mean and variance for alpha and beta in Regression #54

sourish-cmi opened this issue Oct 6, 2022 · 3 comments · Fixed by #59
Assignees
Labels
enhancement New feature or request

Comments

@sourish-cmi
Copy link
Collaborator

User-specific mean and variance for alpha and beta in Regression

@sourish-cmi sourish-cmi added the enhancement New feature or request label Oct 6, 2022
@sourish-cmi sourish-cmi added this to the Package Completeness milestone Oct 6, 2022
@sourish-cmi sourish-cmi self-assigned this Oct 6, 2022
@sourish-cmi
Copy link
Collaborator Author

Design requirement

fit( formula::FormulaTerm, data::DataFrame,modelClass::LinearRegression
,prior::Prior_Ridge,alpha_prior_mean::Float64 = 0.0, beta_prior_mean::Float64
,alpha_prior_sd::Float64,beta_prior_sd::Vector{Float64}
,sim_size::Int64 = 1000,h::Float64 = 0.01)

@sourish-cmi
Copy link
Collaborator Author

sourish-cmi commented Oct 6, 2022

Example

fit(rt_tcs ~ rt_nifty, data_frame, LinearRegression(), Prior_Gauss(), alpha_prior_mean  = 0.0, beta_prior_mean = 1.0,alpha_prior_sd=0.2, beta_prior_sd=0.6, sim_size=5000)

@ajaynshah please confirm - if that what you want?

@sourish-cmi sourish-cmi linked a pull request Oct 11, 2022 that will close this issue
@sourish-cmi
Copy link
Collaborator Author

Here is the implementation:

using Dates
using MarketData
using Impute
using DataFrames
using TSx
using CRRao
using StatsModels

startdate = DateTime(2012, 10, 1)
options = YahooOpt(period1 = startdate)

infy = MarketData.yahoo("INFY.NS", options) |> DataFrame
nifty = MarketData.yahoo("^NSEI", options) |> DataFrame

# Closing prices with filled in missing values
infy_close = TS(infy[:, [:timestamp, :AdjClose]])
nifty_close = TS(nifty[:, [:timestamp, :AdjClose]])

data = join(infy_close, nifty_close, JoinBoth)
TSx.rename!(data, [:infy, :nifty])

data = TS(data.coredata |> Impute.locf())

weekly = data[endpoints(data, Week(1))]
weekly_returns = diff(log(weekly))
# weekly_matrix = Matrix(weekly_returns)
df = dropmissing(weekly_returns.coredata)

classical = fit(@formula(infy_log ~ nifty_log), df, LinearRegression())

julia> classical = fit(@formula(infy_log ~ nifty_log), df, LinearRegression())
Model Class: Linear Regression
Likelihood Mode: Gauss
Link Function: Identity
Computing Method: Optimization
──────────────────────────────────────────────────────────────────────────────
                  Coef.  Std. Error      t  Pr(>|t|)     Lower 95%   Upper 95%
──────────────────────────────────────────────────────────────────────────────
(Intercept)  0.00201197  0.00144211   1.40    0.1636  -0.000821097  0.00484505
nifty_log    0.661467    0.0630299   10.49    <1e-22   0.537643     0.78529
──────────────────────────────────────────────────────────────────────────────

## Bayesian prior
## alpha ~ N(0,1)
## beta ~ N(1,1)
bayesian = fit(@formula(infy_log ~ nifty_log), df, LinearRegression(),Prior_Gauss(),0.0,1.0,[1.0],[1.0])


┌ Info: Found initial step size
└   ϵ = 0.025
Chains MCMC chain (1000×15×1 Array{Float64, 3}):

Iterations        = 501:1:1500
Number of chains  = 1
Samples per chain = 1000
Wall duration     = 0.64 seconds
Compute duration  = 0.64 seconds
parameters        = σ, α, β[1]
internals         = lp, n_steps, is_accept, acceptance_rate, log_density, hamiltonian_energy, hamiltonian_energy_error, max_hamiltonian_energy_error, tree_depth, numerical_error, step_size, nom_step_size

Summary Statistics
  parameters      mean       std   naive_se      mcse        ess      rhat   ess_per_sec
      Symbol   Float64   Float64    Float64   Float64    Float64   Float64       Float64

           σ    0.0330    0.0011     0.0000    0.0000   557.1259    0.9992      866.4478
           α    0.0020    0.0014     0.0000    0.0000   960.0706    0.9993     1493.1113
        β[1]    0.6671    0.0643     0.0020    0.0029   456.0534    0.9997      709.2587

Quantiles
  parameters      2.5%     25.0%     50.0%     75.0%     97.5%
      Symbol   Float64   Float64   Float64   Float64   Float64

           σ    0.0308    0.0322    0.0330    0.0337    0.0350
           α   -0.0007    0.0011    0.0020    0.0030    0.0048
        β[1]    0.5389    0.6218    0.6679    0.7123    0.7949

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant