Code Monkey home page Code Monkey logo

barunik / distributionalforecasts.jl Goto Github PK

View Code? Open in Web Editor NEW
7.0 1.0 8.0 357 KB

Code accompanying the Anatolyev, S. and Baruník, J., (2019). Forecasting dynamic return distributions based on ordered binary choice. International Journal of Forecasting, 35(3), pp.823-835

Home Page: https://doi.org/10.1016/j.ijforecast.2019.01.005

License: MIT License

Julia 55.70% Jupyter Notebook 44.30%
forecasting-models distributions stock-analysis logistic-regression finance econometrics

distributionalforecasts.jl's Introduction

DistributionalForecasts.jl

GitHub

The code has been developed in Julia 0.6.4. version, as a code accompanying the Anatolyev and Barunik (2019) paper, and provides an estimation and inference for a model forecasting conditional probability distributions of asset returns (henceforth AB model). For further details, see

Anatolyev, S. and Baruník, J., (2019): Forecasting dynamic return distributions based on ordered binary choice, International Journal of Forecasting, 35(3), pp.823-835. DOI, manuscript available here for download (Jan 2019)

Software requirements

Julia together with few packages needs to be installed

Pkg.add("DataFrames")
Pkg.add("CSV")
Pkg.add("GLM")
Pkg.add("Optim")

Example: Forecasting dynamic return distributions

Note the full example is available as an interactive IJulia notebook here

Load required packages

using DataFrames, CSV, GLM, Optim 

# load main functions
include("DistributionalForecasts.jl");

Load example data (returns of XOM)

data = CSV.read("data_30stocks_returns.txt");
tdim, rdim = size(data)

Choose number of cutoff levels and order of polynomials

# no. of quantiles
js = 37;

# choice of polynomial order
p1=2;
p2=3;

Parameter Estimation

Obtain fast parameter estimates of AB without inference. A vector of $js+p1+p2+2$ parameters is returned:

$$\delta_{0,1},\delta_{0,2},...,\delta_{0,js},\kappa_{0,1},...\kappa_{p1+1,1},\kappa_{0,2},...\kappa_{p2+1,2}$$

par=OrderedLogitparameters(data[:,30].*1.0,js,p1,p2)
par'
1×44 RowVector{Float64,Array{Float64,1}}:
 -2.87124  -2.48832  -2.2352  -2.0323  …  -17.5198  -16.8475  25.976

Inference

Estimate the AB model and obtain full inference and evaluation of fit

est=OrderedLogit(data[:,30].*1.0, js,p1,p2);

Estimates of intercepts $\delta_{0,1},\delta_{0,2},...,\delta_{0,js}$

est[1][1:js]'
1×37 RowVector{Float64,Array{Float64,1}}:
 -2.87124  -2.48832  -2.2352  -2.0323  …  2.10511  2.47381  2.57944  3.04193

Estimates of $\kappa_{0,1},...\kappa_{p1+1,1},\kappa_{0,2},...\kappa_{p2+1,2}$

est[1][(js+1):(js+p1+p2+2)]'
1×7 RowVector{Float64,Array{Float64,1}}:
 -0.0528382  -0.116755  0.0523652  0.108634  -17.5198  -16.8475  25.976

standard errors for all coefficients

est[2]'
1×44 RowVector{Float64,Array{Float64,1}}:
 0.117504  0.101611  0.0915005  …  8.10445  5.70739  7.8312  9.23371

T-stats

est[3]'
1×44 RowVector{Float64,Array{Float64,1}}:
 -24.4352  -24.4886  -24.4283  -23.1584  …  -3.06967  -2.15133  2.81317

Log Likelihood

est[4]
10285.797921780777

Information criteria (AIC/BIC)

est[5:6]
2-element Array{Any,1}:
 -20482.2
 -20222.0

Recover Probabilities Predicted by the AB model

Obtain forecast of return distribution for time $t+1$ based on the in-sample window

window=500
INS=data[1:window,30].*1
OOS=data[window:(window+1),30].*1

probs=forecastProbs(INS,OOS,js,p1,p2)
1×37 Array{Float64,2}:
 0.0670917  0.0868857  0.108024  0.124577  …  0.928052  0.928632  0.951298

Statistical Evaluation

A number of statistical tests from Gneiting and Raftery (2007), and Gonzalez-Rivera and Sun (2015) are implemented in the DistributionalForecasts.jl file.

TBD

Gonzalez-Rivera, G. and Y. Sun (2015). Generalized autocontours: Evaluation of multivari- ate density models. International Journal of Forecasting 31(3), 799–814.

Gneiting, T. and A. Raftery (2007). Strictly proper scoring rules, prediction, and estimation. Journal of American Statistical Association 102 (477), 359–378.

distributionalforecasts.jl's People

Contributors

barunik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.