PerformanceAnalytics | PerformanceAnalytics provides an R package | Data Visualization library
kandi X-RAY | PerformanceAnalytics Summary
kandi X-RAY | PerformanceAnalytics Summary
PerformanceAnalytics provides an R package of econometric functions for performance and risk analysis of financial instruments or portfolios. This package aims to aid practitioners and researchers in using the latest research for analysis of both normally and non-normally distributed return streams. We created this package to include functionality that has been appearing in the academic literature on performance analysis and risk over the past several years, but had no functional equivalent in R. In doing so, we also found it valuable to have wrappers for some functionality with good defaults and naming consistent with common usage in the finance literature. In general, this package requires return (rather than price) data. Almost all of the functions will work with any periodicity, from annual, monthly, daily, to even minutes and seconds, either regular or irregular. The package documentation includes sections on. It also includes some thoughts on work yet to be done, acknowledgments, and pointers to other literature and resources in R useful for performance and risk analysis,. Some sample data is provided in the managers dataset. It is an xts object that contains columns of monthly returns for six hypothetical asset managers (HAM1 through HAM6), the EDHEC Long-Short Equity hedge fund index, the S&P 500 total returns, and total return series for the US Treasury 10-year bond and 3-month bill. Monthly returns for all series end in December 2006 and begin at different periods starting from January 1996. That data set is used extensively in our examples and should serve as a model for formatting your data.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of PerformanceAnalytics
PerformanceAnalytics Key Features
PerformanceAnalytics Examples and Code Snippets
Community Discussions
Trending Discussions on PerformanceAnalytics
QUESTION
I'm trying to create a finance-related R Shiny application. As of right now, I have a tab to create a custom portfolio, which requires me to have a numericInput
for each variable in the original source_file
. This is how the sample source_file
looks like:
Currently, I have to manually hardcode each numericInput
box for each variable like shown:
ANSWER
Answered 2021-May-13 at 12:13Here is a demo that may be helpful for you.
You can upload a .csv file to the shiny app. It will ignore the first column (or you can modify to specifically remove a date column).
The numeric inputs will be dynamically generated based on the header column names read in.
The demo has a calc
button, that will store the input data and for further processing (calculating returns). Also added a table to show the entered data.
Edit: If upon pressing the calc
button you want to call your custom function (calculate_portfolio_returns
), you can add the call to that function in eventReactive
, since that is dependent on the input button. To pass on the values from the numeric inputs, you can store these values temporarily in a vector vals
, and then pass vals
as an argument to the function (see modified code below). In the demo, I call a custom function calc_sum
that will print the sum of the numeric inputs in the console. One final note, I added an explicit return
at the end of input_vals()
, so that vals
can be shared for use in output$table
.
QUESTION
I have recently changed my plot to a dygraph and even though everything works fine when I run the app locally, I get the error message:
...ANSWER
Answered 2021-Mar-24 at 02:18I put everything in a single app.R file and it works fine : https://hleviel.shinyapps.io/testapp/
QUESTION
I have decided to change my basic plot() for a dygraph() but the dygraph isn't rendering (even though there is no error message). I have tested dygraphs in R shiny using the documentation and it worked. Could someone help me? Note that if you replace the dygraph at the end of my function with a basic plot(c(1,2),c(2,3)) the plot will render.
UI
...ANSWER
Answered 2021-Mar-23 at 02:36The error here is because removeModal()
is the last expression of the renderDygraph()
block, so it's return in interpreted as the plot while it's the return of RunPlot(...)
that contains the plot:
QUESTION
I am using a function to print a plot. This function will only be called once in order to print the plot to the UI (when I click on the "Go" button). The problem is that the plot only prints to the console and not to the UI. There is no error message. I think there might be a problem with my renderPlot. Here is my code:
UI
...ANSWER
Answered 2021-Mar-20 at 11:53You should have the observeEvent
outside the renderPlot
. To make it not react to changes in tickers, you need to isolate()
the reactive variables.
QUESTION
I have defined a function in the server as " RunPlot <- function(tickers, sharesVec, FromDate, ToDate)". The function should return a single numerical value. I want to output this value by clicking on the button "Go", but when I click on the button, nothing happens. Also, I have tried calling this function in a separate script and everything worked so there is no error inside the function. Here is my code:
UI
...ANSWER
Answered 2021-Mar-19 at 02:22Your object BETA
is only available inside the observer. One way to make it available outside is to create a reactiveValues
object as shown below.
QUESTION
I want to define two variables ("tickers" and "SharesVec") as empty vectors and add text inputs and numerical inputs (respectively) to these vectors when the button "action" is triggered. I will be using these vectors later to run a function. I'm not sure I understand how to use variables properly in R shiny (beginner). Here is what I tried so far:
UI
...ANSWER
Answered 2021-Mar-18 at 03:34Store the vectors in reactiveValues
. You can change the server function to :
QUESTION
I am struggling to calculate equal weighted portfolio returns. I am currently using Return.portfolio
from the PerformanceAnalytics
package and I encounter problems when dealing with NAs.
To give a reproduceable example:
...ANSWER
Answered 2021-Feb-22 at 14:30I think you encounter this problem, because the weights need be known before the rebalancing, i.e. you can get meaningful values, if you subtract one day from the index of your weights:
QUESTION
I'm trying to optimize the parameters of a simple strategy as the code below by maximizing the sharpe ratio. The output results are clearly wrong. Can you please provide some help?
...ANSWER
Answered 2021-Feb-11 at 23:33optim()
and related methods can find optima of smooth surfaces. With only two parameters it's easy enough to compute the objective function over a surface by brute force (I use functions from the emdbook
and plot3D
packages for convenience, but you could easily do this with for()
loops and the built-in persp()
function ...) (code below)
I know nothing about your subject area (finance?) or what's going on under the hood in the objective function, but it's not at all surprising that the optimization didn't work.
I was concerned that maybe the problem was with non-integer values of the parameters (which would present a problem for optim()
in any case, but might suggest other approaches), but even restricting to integer values in the range (5-20, 180-200) we still get a rough-looking surface:
I have found the DEoptim
(optimization by differential evolution) function useful for problems like this.
QUESTION
rh1 is the sample price dataframe rh2 is returns of rh1 and return_cum is the cumulative returns of rh2 and ret_drawdown computes drawdown.
...ANSWER
Answered 2021-Feb-11 at 20:24You could split
ret_drawdown
along the cumsum
of the identity of zero-valued dates. In S
filter out the zeroes. In an lapply
make data.frame
s out of min
and max
date of the index
of the time series as well as the sum of a
and rbind
and do some rownames
cosmetics. In a last step we calculate cumsum
within
the resulting data frame.
QUESTION
I am trying to transform a table of stocks ranked by their return to a matrix of values that would be inputted to PerformanceAnalytics::ReturnPortfolio
as the weights of the stocks in the portfolio.
What I am specially looking to do is to transform the ranking value of the 33% best stocks to 1, the 33% worst-performing stocks to -1 and the rest to 0.
This is the original code where I am just taking the best stocks and changing their ranked value to 1:
...ANSWER
Answered 2021-Jan-19 at 22:04We could loop over the rows with apply
and MARGIN = 1
, get the quantile
with probs
as .33
and .67
, pass that as breaks
in the cut
, convert to integer
and use that index for replacing the values to 1, 0, -1
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install PerformanceAnalytics
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page