Title: | A Package for Fitting Stock Price Distributions |
---|---|
Description: | The `StockDistFit` package provides functions for fitting probability distributions to stock price data. The package uses maximum likelihood estimation to find the best-fitting distribution for a given stock. It also offers a function to fit several distributions to one or more assets and compare the distribution with the Akaike Information Criterion (AIC) and then pick the best distribution. |
Authors: | Brian Njuguna [aut, cre] , Stanely Sayianka [ctb] |
Maintainer: | Brian Njuguna <[email protected]> |
License: | GPL (>= 3) |
Version: | 1.0.0 |
Built: | 2024-11-17 04:40:23 UTC |
Source: | https://github.com/wagathu/stockdistfit |
This dataset contains the daily stock prices of Apple Inc. (AAPL) from January 2, 2013 to April 30, 2023. The data includes the open, high, low, and close prices, as well as the volume and adjusted close price. ~~
data("AAPL")
data("AAPL")
A data frame with 2599 observations on the following 7 variables.
Date
a character vector
Open
a numeric vector
High
a numeric vector
Low
a numeric vector
Close
a numeric vector
Volume
a numeric vector
Adjusted
a numeric vector
Data source: Yahoo Finance
data(AAPL) str(AAPL) ; plot(AAPL)
data(AAPL) str(AAPL) ; plot(AAPL)
This dataset contains the daily stock prices of Amazon.com Inc. (AMZN) from January 2, 2013 to April 30, 2023. The data includes the open, high, low, and close prices, as well as the volume and adjusted close price. ~~
data("AMZN")
data("AMZN")
A data frame with 2599 observations on the following 7 variables.
Date
a character vector
Open
a numeric vector
High
a numeric vector
Low
a numeric vector
Close
a numeric vector
Volume
a numeric vector
Adjusted
a numeric vector
Data source: Yahoo Finance
data(AMZN) str(AMZN) ; plot(AMZN)
data(AMZN) str(AMZN) ; plot(AMZN)
This function takes a vector of asset returns and computes annual returns.
annual_return(vec)
annual_return(vec)
vec |
a numeric vector of asset returns as an xts object with dates as rownames. |
A numeric vector of annual returns.
## Not run: # Compute annual returns of an asset vector require(xts) asset_returns_xts <- xts(c(0.05, -0.03, 0.02, -0.01, 0.04, -0.02, 0.01), order.by = as.Date(c("2023-05-01", "2023-05-02", "2023-05-03", "2023-05-04", "2023-05-05", "2023-05-06", "2023-05-07"))) annual_return(asset_returns_xts) ## End(Not run)
## Not run: # Compute annual returns of an asset vector require(xts) asset_returns_xts <- xts(c(0.05, -0.03, 0.02, -0.01, 0.04, -0.02, 0.01), order.by = as.Date(c("2023-05-01", "2023-05-02", "2023-05-03", "2023-05-04", "2023-05-05", "2023-05-06", "2023-05-07"))) annual_return(asset_returns_xts) ## End(Not run)
This function reads in asset data stored in .csv format and returns a time-series object of the asset data.
asset_loader(data_path, assets, price_col)
asset_loader(data_path, assets, price_col)
data_path |
The path to the directory containing the .csv files. |
assets |
A vector of asset names to be loaded. |
price_col |
The name of the price column to be selected (e.g. Open, Close, Low, High). |
An xts object with asset data.
The Date
column in the files should be of the format "%m/%d/%y", that is 01/14/13 with
01 implying the month, 14 the date and 13 the year
The data to be loaded must be in .csv type and also must have the Date, Open, Low, High and Close Prices of the assest or assests to be loaded.
## Not run: asset_data <- asset_loader("path/to/data/folder", c("AAPL", "MSFT"), "Close") ## End(Not run)
## Not run: asset_data <- asset_loader("path/to/data/folder", c("AAPL", "MSFT"), "Close") ## End(Not run)
This function takes in a data frame of AIC values for different distributions and a vector of distribution names, and returns a data frame with the best distribution for each row based on the minimum AIC value. #' You can also write the distribution as "norm" or "cauchy" provided they follow the order in the data frame.
best_dist(aic_df, dist_names)
best_dist(aic_df, dist_names)
aic_df |
A data frame containing AIC values for different distributions |
dist_names |
A vector of distribution names corresponding to the AIC values |
A data frame with the best distribution for each row based on the minimum AIC value
This function takes the data frame obtained from fit_multiple_dist
function
## Not run: data = asset_loader("path/to/data", c("asset1", "asset2"), "Close") df = fit_multiple_dist(c("norm_fit", "cauchy_fit"), data) best_dist(df, c("norm_fit", "cauchy_fit")) ## End(Not run)
## Not run: data = asset_loader("path/to/data", c("asset1", "asset2"), "Close") df = fit_multiple_dist(c("norm_fit", "cauchy_fit"), data) best_dist(df, c("norm_fit", "cauchy_fit")) ## End(Not run)
This function fits the Cauchy distribution to a given data vector using the fitdist function from the fitdistrplus package. It returns the estimated parameters along with the AIC and BIC values for the fitted distribution.
cauchy_fit(vec)
cauchy_fit(vec)
vec |
a numeric vector containing the data to be fitted. |
a list containing the following elements:
a numeric vector of length 2 containing the estimated values for the parameters of the fitted distribution: lambda (location) and alpha (scale).
the Akaike information criterion (AIC) value for the fitted distribution.
the Bayesian information criterion (BIC) value for the fitted distribution.
norm_fit
, t_fit
, ghd_fit
, hd_fit
,
sym.ghd_fit
, sym.hd_fit
, vg_fit
, sym.vg_fit
,
nig_fit
, ged_fit
, skew.t_fit
, skew.normal_fit
,
skew.ged_fit
## Not run: stock_prices <- c(10, 11, 12, 13, 14) returns <- diff(log(stock_prices)) cauchy_fit(returns) ## End(Not run)
## Not run: stock_prices <- c(10, 11, 12, 13, 14) returns <- diff(log(stock_prices)) cauchy_fit(returns) ## End(Not run)
This function takes a vector of asset returns and computes the cumulative wealth
generated over time, assuming that the initial wealth was initial_eq
.
data.cumret(df_ret, initial_eq)
data.cumret(df_ret, initial_eq)
df_ret |
an xts object of asset returns, with dates as rownames. |
initial_eq |
a numeric value representing the initial wealth. |
An xts object of wealth generated over time.
weekly_return
, monthly_return
, annual_return
## Not run: # Compute cumulative returns of an asset vector library(quantmod) asset_returns_xts <- xts(c(0.05, -0.03, 0.02, -0.01, 0.04, -0.02, 0.01), order.by = as.Date(c("2023-05-01", "2023-05-02", "2023-05-03", "2023-05-04", "2023-05-05", "2023-05-06", "2023-05-07"))) data.cumret(asset_returns_xts, initial_eq = 100) ## End(Not run)
## Not run: # Compute cumulative returns of an asset vector library(quantmod) asset_returns_xts <- xts(c(0.05, -0.03, 0.02, -0.01, 0.04, -0.02, 0.01), order.by = as.Date(c("2023-05-01", "2023-05-02", "2023-05-03", "2023-05-04", "2023-05-05", "2023-05-06", "2023-05-07"))) data.cumret(asset_returns_xts, initial_eq = 100) ## End(Not run)
This function fits multiple probability distributions to a dataframe and calculates the Akaike Information Criterion (AIC) and Bayesian Information Criterion (BIC) for each distribution and then returns a data frame of the AIC values for each asset where the column names are the names of the fitted distributions.
fit_multiple_dist(dist_names, dataframe)
fit_multiple_dist(dist_names, dataframe)
dist_names |
a character vector of distribution names to be fitted. |
dataframe |
a dataframe containing the data to be fitted. |
Note that the available distributions are norm_fit - Normal distribution
t_fit - Student's t-distribution
cauchy_fit - Cauchy distribution
ghd_fit - Generalized hyperbolic distribution
hd_fit - Hyperbolic distribution
sym.ghd_fit - Symmetric generalized hyperbolic distribution
sym.hd_fit - Symmetric hyperbolic distribution
vg_fit - Variance-gamma distribution
sym.vg_fit - Symmetric variance-gamma distribution
nig_fit - Normal-inverse Gaussian distribution
ged_fit - Generalized error distribution
skew.t_fit - Skew Student's t-distribution
skew.normal_fit - Skew normal distribution
skew.ged_fit - Skew generalized error distribution
Also note that the distribution to be fitted from the above list must include the '_fit'. The function can also fit one distribution to one asset.
A list of distributions and their corresponding AIC and BIC values.
## Not run: data = asset_loader("path/to/data/folder", c("asset1", "asset2"), "Close") fit_multiple_dist(c("norm_fit", "cauchy_fit"), data) ## End(Not run)
## Not run: data = asset_loader("path/to/data/folder", c("asset1", "asset2"), "Close") fit_multiple_dist(c("norm_fit", "cauchy_fit"), data) ## End(Not run)
This function fits the Generalized Error Distribution (GED) to a given data vector using the ged_fit
function from
the fGarch
package. It returns the estimated parameters along with the AIC and BIC values for the fitted
distribution.
ged_fit(vec)
ged_fit(vec)
vec |
A numeric vector of data. |
A list with the following elements:
A numeric vector of length 3 containing the fitted GED parameters: shape, scale, and location.
The Akaike Information Criterion (AIC) for the fitted model.
The Bayesian Information Criterion (BIC) for the fitted model.
norm_fit
, t_fit
, cauchy_fit
, ghd_fit
, hd_fit
,
sym.ghd_fit
, sym.hd_fit
, vg_fit
, nig_fit
,
sym.vg_fit
, skew.t_fit
, skew.normal_fit
, skew.ged_fit
stock_prices <- c(10, 11, 12, 13, 14) returns <- diff(log(stock_prices)) ged_fit(returns)
stock_prices <- c(10, 11, 12, 13, 14) returns <- diff(log(stock_prices)) ged_fit(returns)
This function fits the Generalized Hyperbolic (GH) distribution to a given data vector using the
fit.ghypuv
function from the ghyp
package. It returns the estimated parameters along with
the AIC and BIC values for the fitted distribution.
ghd_fit(vec)
ghd_fit(vec)
vec |
a numeric vector containing the data to be fitted. |
a list containing the following elements:
a numeric vector of length 5 containing the estimated values for the parameters of the fitted distribution: lambda (location), alpha (scale), mu (degrees of freedom), sigma (standard deviation), and gamma (skewness).
the Akaike information criterion (AIC) value for the fitted distribution.
the Bayesian information criterion (BIC) value for the fitted distribution.
norm_fit
, t_fit
, cauchy_fit
, hd_fit
,
sym.ghd_fit
, sym.hd_fit
, vg_fit
, sym.vg_fit
,
nig_fit
, ged_fit
, skew.t_fit
, skew.normal_fit
,
skew.ged_fit
## Not run: stock_prices <- c(10, 11, 12, 13, 14) returns <- diff(log(stock_prices)) ghd_fit(returns) ## End(Not run)
## Not run: stock_prices <- c(10, 11, 12, 13, 14) returns <- diff(log(stock_prices)) ghd_fit(returns) ## End(Not run)
This dataset contains the daily stock prices of Alphabet Inc. (GOOG) from January 2, 2013 to April 30, 2023. The data includes the open, high, low, and close prices, as well as the volume and adjusted close price. ~~
data("GOOG")
data("GOOG")
A data frame with 2599 observations on the following 7 variables.
Open
a numeric vector
High
a numeric vector
Low
a numeric vector
Close
a numeric vector
Volume
a numeric vector
Adjusted
a numeric vector
Date
a character vector
Data source: Yahoo Finance
data(GOOG) str(GOOG) ; plot(GOOG)
data(GOOG) str(GOOG) ; plot(GOOG)
This function fits the Hyperbolic distribution to a given data vector using the fit.hypuv
function from the ghyp
package. It returns the estimated parameters along with the AIC and
BIC values for the fitted distribution.
hd_fit(vec)
hd_fit(vec)
vec |
a numeric vector containing the data to be fitted. |
a list containing the following elements:
a numeric vector of length 4 containing the estimated values for the parameters of the fitted distribution: alpha (scale), mu (location), sigma (standard deviation), and gamma (skewness).
the Akaike information criterion (AIC) value for the fitted distribution.
the Bayesian information criterion (BIC) value for the fitted distribution.
norm_fit
, sym.ghd_fit
, ghd_fit
, cauchy_fit
,
t_fit
, sym.hd_fit
, vg_fit
, sym.vg_fit
,
nig_fit
, ged_fit
, skew.t_fit
, skew.normal_fit
,
skew.ged_fit
## Not run: stock_prices <- c(10, 11, 12, 13, 14) returns <- diff(log(stock_prices)) hd_fit(returns) ## End(Not run)
## Not run: stock_prices <- c(10, 11, 12, 13, 14) returns <- diff(log(stock_prices)) hd_fit(returns) ## End(Not run)
This function takes a numeric vector of asset returns and computes monthly returns.
monthly_return(vec)
monthly_return(vec)
vec |
a numeric vector of asset returns. |
A numeric vector of monthly returns.
The input data must be an xts object with dates as rownames.
## Not run: # Compute monthly returns of an asset vector require(xts) asset_returns_xts <- xts(c(0.05, -0.03, 0.02, -0.01, 0.04, -0.02, 0.01), order.by = as.Date(c("2023-05-01", "2023-05-02", "2023-05-03", "2023-05-04", "2023-05-05", "2023-05-06", "2023-05-07"))) monthly_return(asset_returns_xts) ## End(Not run)
## Not run: # Compute monthly returns of an asset vector require(xts) asset_returns_xts <- xts(c(0.05, -0.03, 0.02, -0.01, 0.04, -0.02, 0.01), order.by = as.Date(c("2023-05-01", "2023-05-02", "2023-05-03", "2023-05-04", "2023-05-05", "2023-05-06", "2023-05-07"))) monthly_return(asset_returns_xts) ## End(Not run)
This function fits the Normal Inverse Gaussian (NIG) Distribution to a given data vector using the nig_fit
function from
the fBasics
package. It returns the estimated parameters along with the AIC and BIC values for the fitted
distribution.
nig_fit(vec)
nig_fit(vec)
vec |
A numeric vector of data. |
A list with the following elements:
The estimated parameters of the NIG distribution: location, scale, skewness, and shape.
The Akaike Information Criterion (AIC) for the NIG distribution fit.
The Bayesian Information Criterion (BIC) for the NIG distribution fit.
norm_fit
, t_fit
, cauchy_fit
, ghd_fit
, hd_fit
,
sym.ghd_fit
, sym.hd_fit
, vg_fit
, sym.vg_fit
ged_fit
, skew.t_fit
, skew.normal_fit
, skew.ged_fit
stock_prices <- c(10, 11, 12, 13, 14) returns <- diff(log(stock_prices)) nig_fit(returns)
stock_prices <- c(10, 11, 12, 13, 14) returns <- diff(log(stock_prices)) nig_fit(returns)
This function takes a numeric vector and fits a normal distribution to it using the fitdist function from the fitdistrplus package. It returns a list with the mean and standard deviation parameters of the fitted normal distribution, as well as the AIC and BIC values of the fitted distribution.
norm_fit(vec)
norm_fit(vec)
vec |
a numeric vector to be fitted with a normal distribution. |
A list with the following components:
a numeric vector with the estimated mean and standard deviation parameters of the fitted normal distribution.
a numeric value representing the Akaike information criterion (AIC) of the fitted distribution.
a numeric value representing the Bayesian information criterion (BIC) of the fitted distribution.
t_fit
, cauchy_fit
, ghd_fit
, hd_fit
,
sym.ghd_fit
, sym.hd_fit
, vg_fit
, sym.vg_fit
,
nig_fit
, ged_fit
, skew.t_fit
, skew.normal_fit
,
skew.ged_fit
## Not run: # Fit a normal distribution to a vector of returns stock_prices <- c(10, 11, 12, 13, 14) returns <- diff(log(stock_prices)) norm_fit(returns) ## End(Not run)
## Not run: # Fit a normal distribution to a vector of returns stock_prices <- c(10, 11, 12, 13, 14) returns <- diff(log(stock_prices)) norm_fit(returns) ## End(Not run)
This function fits the Skewed Generalized Error Distribution to a given data vector using the skew.ged_fit
function from
the fGarch
package. It returns the estimated parameters along with the AIC and BIC values for the fitted
distribution.
skew.ged_fit(vec)
skew.ged_fit(vec)
vec |
A numeric vector of data. |
A list with the following elements:
A numeric vector of length 4 containing the fitted SGED parameters: shape, scale, location, and skewness.
The Akaike Information Criterion (AIC) for the fitted model.
The Bayesian Information Criterion (BIC) for the fitted model.
norm_fit
, t_fit
, cauchy_fit
, ghd_fit
, hd_fit
,
sym.ghd_fit
, sym.hd_fit
, vg_fit
, sym.vg_fit
,
nig_fit
, ged_fit
, skew.t_fit
,
skew.normal_fit
## Not run: stock_prices <- c(10, 11, 12, 13, 14) returns <- diff(log(stock_prices)) skew.ged_fit(returns) ## End(Not run)
## Not run: stock_prices <- c(10, 11, 12, 13, 14) returns <- diff(log(stock_prices)) skew.ged_fit(returns) ## End(Not run)
This function fits the Skew Normal distribution to a given data vector using the snormFit
function from
the fGarch
package. It returns the estimated parameters along with the AIC and BIC values for the fitted
distribution.
skew.normal_fit(vec)
skew.normal_fit(vec)
vec |
a numeric vector containing the data to be fitted. |
a list containing the following elements:
a numeric vector of length 3 containing the estimated values for the parameters of the fitted distribution: location (mu), scale (sigma), and skewness (alpha).
the Akaike information criterion (AIC) value for the fitted distribution.
the Bayesian information criterion (BIC) value for the fitted distribution.
norm_fit
, t_fit
, cauchy_fit
, ghd_fit
, hd_fit
,
sym.ghd_fit
, sym.hd_fit
, vg_fit
, sym.vg_fit
,
nig_fit
, ged_fit
, skew.t_fit
,
skew.ged_fit
## Not run: stock_prices <- c(10, 11, 12, 13, 14) returns <- diff(log(stock_prices)) skew.normal_fit(returns) ## End(Not run)
## Not run: stock_prices <- c(10, 11, 12, 13, 14) returns <- diff(log(stock_prices)) skew.normal_fit(returns) ## End(Not run)
This function fits the Skewed Student-t Distribution to a given data vector using the skew.t_fit
function from
the fGarch
package. It returns the estimated parameters along with the AIC and BIC values for the fitted
distribution.
skew.t_fit(vec)
skew.t_fit(vec)
vec |
A numeric vector of data. |
A list with the following elements:
A numeric vector of length 4 containing the fitted Skewed Student-t parameters: degrees of freedom, skewness, scale, and location.
The Akaike Information Criterion (AIC) for the fitted model.
The Bayesian Information Criterion (BIC) for the fitted model.
norm_fit
, t_fit
, cauchy_fit
, ghd_fit
, hd_fit
,
sym.ghd_fit
, sym.hd_fit
, vg_fit
, nig_fit
,
sym.vg_fit
, ged_fit
, skew.normal_fit
, skew.ged_fit
stock_prices <- c(10, 11, 12, 13, 14) returns <- diff(log(stock_prices)) skew.t_fit(returns)
stock_prices <- c(10, 11, 12, 13, 14) returns <- diff(log(stock_prices)) skew.t_fit(returns)
This function fits the Symmetric Generalized Hyperbolic (sGH) distribution to a given data vector using
the fit.ghypuv
function from the ghyp
package. It returns the estimated parameters along with
the AIC and BIC values for the fitted distribution.
sym.ghd_fit(vec)
sym.ghd_fit(vec)
vec |
a numeric vector containing the data to be fitted. |
a list containing the following elements:
a numeric vector of length 5 containing the estimated values for the parameters of the fitted distribution: lambda (location), alpha (scale), mu (degrees of freedom), sigma (standard deviation), and gamma (skewness).
the Akaike information criterion (AIC) value for the fitted distribution.
the Bayesian information criterion (BIC) value for the fitted distribution.
norm_fit
, t_fit
, cauchy_fit
, ghd_fit
, hd_fit
,
sym.hd_fit
, vg_fit
, sym.vg_fit
,
nig_fit
, ged_fit
, skew.t_fit
, skew.normal_fit
,
skew.ged_fit
## Not run: stock_prices <- c(10, 11, 12, 13, 14) returns <- diff(log(stock_prices)) sym.ghd_fit(returns) ## End(Not run)
## Not run: stock_prices <- c(10, 11, 12, 13, 14) returns <- diff(log(stock_prices)) sym.ghd_fit(returns) ## End(Not run)
This function fits a Symmetric Hyperbolic distribution to a data vector using the
fit.hypuv
function from the ghyp
package. It returns the estimated parameters along with
the AIC and BIC values for the fitted distribution.
sym.hd_fit(vec)
sym.hd_fit(vec)
vec |
a numeric vector containing the symmetric data to be fitted. |
a list containing the following elements:
a numeric vector of length 4 containing the estimated values for the parameters of the fitted distribution: alpha (scale), mu (degrees of freedom), sigma (standard deviation), and gamma (skewness).
the Akaike information criterion (AIC) value for the fitted distribution.
the Bayesian information criterion (BIC) value for the fitted distribution.
norm_fit
, t_fit
, cauchy_fit
, ghd_fit
, hd_fit
,
sym.ghd_fit
, vg_fit
, sym.vg_fit
, nig_fit
,
ged_fit
, skew.t_fit
, skew.normal_fit
, skew.ged_fit
## Not run: stock_prices <- c(10, 11, 12, 13, 14) returns <- diff(log(stock_prices)) sym.hd_fit(returns) ## End(Not run)
## Not run: stock_prices <- c(10, 11, 12, 13, 14) returns <- diff(log(stock_prices)) sym.hd_fit(returns) ## End(Not run)
This function fits the Symmetric Variance Gamma (sVG) distribution to a given data vector using the
fit.VGuv
function from the ghyp
package. It returns the estimated parameters along with
the AIC and BIC values for the fitted distribution.
sym.vg_fit(vec)
sym.vg_fit(vec)
vec |
a numeric vector containing the data to be fitted. |
a list containing the following elements:
a numeric vector of length 4 containing the estimated values for the parameters of the fitted distribution: lambda (scale), mu (location), sigma (volatility), and gamma (skewness).
the Akaike information criterion (AIC) value for the fitted distribution.
the Bayesian information criterion (BIC) value for the fitted distribution.
norm_fit
, t_fit
, cauchy_fit
, ghd_fit
, hd_fit
,
sym.ghd_fit
, sym.hd_fit
, vg_fit
, nig_fit
,
ged_fit
, skew.t_fit
, skew.normal_fit
, skew.ged_fit
## Not run: stock_prices <- c(10, 11, 12, 13, 14) returns <- diff(log(stock_prices)) sym.vg_fit(returns) ## End(Not run)
## Not run: stock_prices <- c(10, 11, 12, 13, 14) returns <- diff(log(stock_prices)) sym.vg_fit(returns) ## End(Not run)
This function fits the Student's t distribution to a given data vector using the fit.tuv
function
from the ghyp
package. It returns the estimated parameters along with the AIC and BIC
values for the fitted distribution.
t_fit(vec)
t_fit(vec)
vec |
a numeric vector containing the data to be fitted. |
a list containing the following elements:
a numeric vector of length 5 containing the estimated values for the parameters of the fitted distribution: lambda (location), alpha (scale), mu (degrees of freedom), sigma (standard deviation), and gamma (skewness).
the Akaike information criterion (AIC) value for the fitted distribution.
the Bayesian information criterion (BIC) value for the fitted distribution.
norm_fit
, cauchy_fit
, ghd_fit
, hd_fit
,
sym.ghd_fit
, sym.hd_fit
, vg_fit
, sym.vg_fit
,
nig_fit
, ged_fit
, skew.t_fit
, skew.normal_fit
,
skew.ged_fit
## Not run: stock_prices <- c(10, 11, 12, 13, 14) returns <- diff(log(stock_prices)) t_fit(returns) ## End(Not run)
## Not run: stock_prices <- c(10, 11, 12, 13, 14) returns <- diff(log(stock_prices)) t_fit(returns) ## End(Not run)
This dataset contains the daily stock prices of Tesla, Inc. (TSLA) from January 2, 2013 to May 6, 2023. The data includes the open, high, low, and close prices, as well as the volume and adjusted close price. ~~
data("TSLA")
data("TSLA")
A data frame with 2599 observations on the following 7 variables.
Open
a numeric vector
High
a numeric vector
Low
a numeric vector
Close
a numeric vector
Volume
a numeric vector
Adjusted
a numeric vector
Date
a character vector
Data source: Yahoo Finance
data(TSLA) str(TSLA) ; plot(TSLA)
data(TSLA) str(TSLA) ; plot(TSLA)
This function fits the Variance Gamma (VG) distribution to a given data vector using the
fit.VGuv
function from the ghyp
package. It returns the estimated parameters along with
the AIC and BIC values for the fitted distribution.
vg_fit(vec)
vg_fit(vec)
vec |
a numeric vector containing the data to be fitted. |
a list containing the following elements:
a numeric vector of length 4 containing the estimated values for the parameters of the fitted distribution: lambda (location), mu (scale), sigma (shape), and gamma (skewness).
the Akaike information criterion (AIC) value for the fitted distribution.
the Bayesian information criterion (BIC) value for the fitted distribution.
norm_fit
, t_fit
, cauchy_fit
, ghd_fit
, hd_fit
,
sym.ghd_fit
, sym.hd_fit
, sym.vg_fit
,
nig_fit
, ged_fit
, skew.t_fit
, skew.normal_fit
,
skew.ged_fit
## Not run: stock_prices <- c(10, 11, 12, 13, 14) returns <- diff(log(stock_prices)) vg_fit(returns) ## End(Not run)
## Not run: stock_prices <- c(10, 11, 12, 13, 14) returns <- diff(log(stock_prices)) vg_fit(returns) ## End(Not run)
This function takes a numeric vector of asset returns and computes weekly returns.
weekly_return(vec)
weekly_return(vec)
vec |
a numeric vector of asset returns. |
A numeric vector of weekly returns.
The input data must be an xts object with dates as rownames.
## Not run: # Compute weekly returns of an asset vector require(xts) asset_returns_xts <- xts(c(0.05, -0.03, 0.02, -0.01, 0.04, -0.02, 0.01), order.by = as.Date(c("2023-05-01", "2023-05-02", "2023-05-03", "2023-05-04", "2023-05-05", "2023-05-06", "2023-05-07"))) weekly_return(asset_returns_xts) ## End(Not run)
## Not run: # Compute weekly returns of an asset vector require(xts) asset_returns_xts <- xts(c(0.05, -0.03, 0.02, -0.01, 0.04, -0.02, 0.01), order.by = as.Date(c("2023-05-01", "2023-05-02", "2023-05-03", "2023-05-04", "2023-05-05", "2023-05-06", "2023-05-07"))) weekly_return(asset_returns_xts) ## End(Not run)