braverock / FactorAnalytics

67 stars 63 forks source link

Examples removed from fmXXDecomp.R manual pages, and saved for future replacement #58

Open martinrd3D opened 3 years ago

martinrd3D commented 3 years ago

Manual page examples to be removed from factor model risk decomposition functions for now, due to removal of data sets for the examples, and saved here for adding back once new data sets are provided for these examples

fmSdDecomp.R:

Statistical Factor Model:

data(StockReturns) sfm.pca.fit <- fitSfm(r.M, k=2) decomp <- fmSdDecomp(sfm.pca.fit) decomp$pcSd

fmVaRDecomp.R:

Statistical Factor Model:

data(StockReturns) sfm.pca.fit <- fitSfm(r.M, k=2) VaR.decomp <- fmVaRDecomp(sfm.pca.fit, type="normal") VaR.decomp$cVaR

Fundamental Factor Model:

data(Stocks.df) exposure.vars <- c("BOOK2MARKET", "LOG.MARKETCAP") fit <- fitFfm(data=stock, asset.var="TICKER", ret.var="RETURN", date.var="DATE", exposure.vars=exposure.vars) VaR.decomp <- fmVaRDecomp(fit, type="normal") VaR.decomp$cVaR

fmESDecomp.R:

Statistical Factor Model:

data(StockReturns) sfm.pca.fit <- fitSfm(r.M, k=2) ES.decomp <- fmEsDecomp(sfm.pca.fit, type="normal") ES.decomp$cES

Fundamental Factor Model:

data(Stocks.df) exposure.vars <- c("BOOK2MARKET", "LOG.MARKETCAP") fit <- fitFfm(data=stock, asset.var="TICKER", ret.var="RETURN", date.var="DATE", exposure.vars=exposure.vars) ES.decomp <- fmEsDecomp(fit, type="normal") head(ES.decomp$cES)

fmCov.R

Statistical Factor Model:

data(StockReturns) sfm.pca.fit <- fitSfm(r.M, k=2) fmCov(sfm.pca.fit)

Fundamental factor Model:

data(Stocks.df) exposure.vars <- c("BOOK2MARKET", "LOG.MARKETCAP", "GICS.SECTOR") fit2 <- fitFfm(data=stock, asset.var="TICKER", ret.var="RETURN", date.var="DATE", exposure.vars=exposure.vars) fmCov(fit2)

summary.ffm

' data(Stocks.df)

' exposure.vars <- c("BOOK2MARKET", "LOG.MARKETCAP", "GICS.SECTOR")

' fit2 <- fitFfm(data=stock, asset.var="TICKER", ret.var="RETURN",

' date.var="DATE", exposure.vars=exposure.vars)

'

' # summary of factor returns estimated in each time period

' summary(fit2)

'

' # summary of lm fit for a single period

' summary(fit2$factor.fit[[1]])

JustinMShea commented 3 years ago

@martinrd3D we could replace the stocks.df and other legacy data sets with something like this:

data("stocksCRSP")
data("scoresSPGMI")

CRSP_SPGMI <- merge(x = stocksCRSP,  y = scoresSPGMI, 
                    by = intersect(names(stocksCRSP), names(scoresSPGMI)) 
                    )

Let me know what you think

martinrd3D commented 3 years ago

On Sun, Sep 12, 2021 at 5:27 PM Justin M. Shea @.***> wrote:

@martinrd3D https://github.com/martinrd3D we could replace the stocks.df and other legacy data sets with something like this:

data("stocksCRSP") data("scoresSPGMI")

CRSP_SPGMI <- merge(stocksCRSP, scoresSPGMI, by = intersect( names(stocksCRSP), names(scoresSPGMI) ) )

Let me know what you think

Justin,

Conceptually, it makes sense, keeping in mind that stocks.df is 447 stocks by 8 years, whereas stocksCRSP is 300 stocks by 20 years, See Sangeetha's fitFfm vignette, which in case you don't have it handy, I have attached. But the more relevant point is that we are quite unlikely to bother with that vignette in view of the broader and deeper one we have that uses fitFfmDT.

The more relevant place where we could use stocksCRSP is for the StockReturns object monthly stock returns r.M and weekly stock returns r.W for fitSfm, as in Sangeetha's fitSfm vignette, and we definitely want to resurrect that later.

Doug

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/braverock/FactorAnalytics/issues/58#issuecomment-917744116, or unsubscribe https://github.com/notifications/unsubscribe-auth/AP575Y472OMPZLDMDWKX76DUBVAPBANCNFSM5DJKDTMQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

-- R. Douglas Martin Professor Emeritus in Applied Mathematics and Statistics University of Washington

martinrd3D commented 2 years ago

It is not a good idea to remove current examples because the example may be fine with a data replacement and/or code replacement, but still illustrating the same thing. If I don't have the example, then I have to create one with no idea what the original example was trying to show.

On Wed, Dec 22, 2021 at 1:02 AM Justin M. Shea @.***> wrote:

Assigned #58 https://github.com/braverock/FactorAnalytics/issues/58 to @martinrd3D https://github.com/martinrd3D.

— Reply to this email directly, view it on GitHub https://github.com/braverock/FactorAnalytics/issues/58#event-5803487380, or unsubscribe https://github.com/notifications/unsubscribe-auth/AP575YY4QXFX6PPQIKOHANLUSGH37ANCNFSM5DJKDTMQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you were assigned.Message ID: @.***>

-- R. Douglas Martin Professor Emeritus in Applied Mathematics and Statistics University of Washington

martinrd3D commented 2 years ago

Where are they saved? In sandbox? In sandbox subfolder?

On Wed, Dec 22, 2021 at 1:02 AM Justin M. Shea @.***> wrote:

Assigned #58 https://github.com/braverock/FactorAnalytics/issues/58 to @martinrd3D https://github.com/martinrd3D.

— Reply to this email directly, view it on GitHub https://github.com/braverock/FactorAnalytics/issues/58#event-5803487380, or unsubscribe https://github.com/notifications/unsubscribe-auth/AP575YY4QXFX6PPQIKOHANLUSGH37ANCNFSM5DJKDTMQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you were assigned.Message ID: @.***>

-- R. Douglas Martin Professor Emeritus in Applied Mathematics and Statistics University of Washington