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

Finance metrics and median calculation #1289

Merged
merged 29 commits into from
Oct 9, 2020
Merged

Conversation

JiaZhou-PU
Copy link
Collaborator

@JiaZhou-PU JiaZhou-PU commented Jul 29, 2020


Pull Request Description

What issue does this change request address? (Use "#" before the issue to link it, i.e., #42.)

closes #1259

What are the significant changes in functionality due to this change request?
  1. Add financial metric:
    Sharpe ratio risk-free rate as 0
    Sortino ratio
    gain loss ratio:
    the first-order higher partial moment of a portfolio's returns, divided by the first-order lower partial moment of a portfolio's returns.
    value at risk
    conditional value at risk

  2. Fixed the percentile calculation with shift one index upper.


For Change Control Board: Change Request Review

The following review must be completed by an authorized member of the Change Control Board.

  • 1. Review all computer code.
  • 2. If any changes occur to the input syntax, there must be an accompanying change to the user manual and xsd schema. If the input syntax change deprecates existing input files, a conversion script needs to be added (see Conversion Scripts).
  • 3. Make sure the Python code and commenting standards are respected (camelBack, etc.) - See on the wiki for details.
  • 4. Automated Tests should pass, including run_tests, pylint, manual building and xsd tests. If there are changes to Simulation.py or JobHandler.py the qsub tests must pass.
  • 5. If significant functionality is added, there must be tests added to check this. Tests should cover all possible options. Multiple short tests are preferred over one large test. If new development on the internal JobHandler parallel system is performed, a cluster test must be added setting, in XML block, the node <internalParallel> to True.
  • 6. If the change modifies or adds a requirement or a requirement based test case, the Change Control Board's Chair or designee also needs to approve the change. The requirements and the requirements test shall be in sync.
  • 7. The merge request must reference an issue. If the issue is closed, the issue close checklist shall be done.
  • 8. If an analytic test is changed/added is the the analytic documentation updated/added?
  • 9. If any test used as a basis for documentation examples (currently found in raven/tests/framework/user_guide and raven/docs/workshop) have been changed, the associated documentation must be reviewed and assured the text matches the example.

@JiaZhou-PU JiaZhou-PU changed the title [WIP] Finance metrics and median calculation Finance metrics and median calculation Jul 30, 2020
@JiaZhou-PU JiaZhou-PU requested a review from alfoa July 30, 2020 21:16
doc/user_manual/postprocessor.tex Outdated Show resolved Hide resolved
framework/PostProcessors/BasicStatistics.py Outdated Show resolved Hide resolved
@JiaZhou-PU JiaZhou-PU changed the title Finance metrics and median calculation [WIP] Finance metrics and median calculation Aug 1, 2020
@JiaZhou-PU JiaZhou-PU changed the title [WIP] Finance metrics and median calculation Finance metrics and median calculation Aug 1, 2020
@moosebuild
Copy link

Job Test CentOS 7 on b65d0c4 : invalidated by @joshua-cogliati-inl

failed in set python environment.

@alfoa
Copy link
Collaborator

alfoa commented Aug 12, 2020

@JiaZhou-PU ready to be reviewed?

@JiaZhou-PU
Copy link
Collaborator Author

JiaZhou-PU commented Aug 12, 2020

@JiaZhou-PU ready to be reviewed?

Yep

framework/PostProcessors/EconomicRatio.py Outdated Show resolved Hide resolved
framework/PostProcessors/EconomicRatio.py Outdated Show resolved Hide resolved
framework/PostProcessors/EconomicRatio.py Outdated Show resolved Hide resolved
framework/PostProcessors/EconomicRatio.py Outdated Show resolved Hide resolved
framework/PostProcessors/EconomicRatio.py Show resolved Hide resolved
framework/PostProcessors/EconomicRatio.py Outdated Show resolved Hide resolved
framework/PostProcessors/EconomicRatio.py Outdated Show resolved Hide resolved
framework/PostProcessors/EconomicRatio.py Outdated Show resolved Hide resolved
Copy link
Contributor

@joshua-cogliati-inl joshua-cogliati-inl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did my first review. In general it looks reasonable, but I did have some comments and questions.

\item \textbf{sharpeRatio}: the Sharpe Ratio, measures the performance of an investment. It is defined as the historical returns of the investment, divided by the standard deviation of the investment(Volatility).
\item \textbf{sortinoRatio}: the Sortino ratio, measures the risk-adjusted return of an investment asset. Discounts the excess return of a portfolio above a target threshold by the volatility of downside returns. If this quantity is inputted as \textit{sortinoRatio} the threshold for separate upside and downside value will assign as $0$. Otherwise the user can specify this quantity with a parameter \xmlAttr{threshold='X'}, where the \xmlAttr{X} represents the requested threshold \xmlAttr{median} or \xmlAttr{zero}.

\item \textbf{gainLossRatio}: the gain-loss ratio, discounts the first-order higher partial moment of a portfolio's returns, by the first-order lower partial moment of a portfolio's returns. If this quantity is inputted as \textit{gainLossRatio} the threshold for separate upside and downside value will assign as $0$. Otherwise the user can specify this quantity with a parameter \xmlAttr{threshold='X'}, where the \xmlAttr{X} represents the requested threshold \xmlAttr{median} or \xmlAttr{zero}.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"threshold for separate upside and downside value will assign as $0$." I do not understand what this means?

Does this mean "the default threshold for the separate upside and downside value is $0$" maybe?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the financial data put in to calculation is usually the percentage change based on the original price. So 0 would be an ideal threshold, somehow in other calculation you could assign median as the gain or lose threshold.

\begin{equation}
ES_\alpha = -\frac{1}{\alpha} \int_0^\alpha \operatorname{VaR}_\gamma(X) \, d\gamma
\end{equation}
\item \textbf{valueAtRisk}: the value at risk for investments. Estimates the maximum possible loss after exclude worse outcomes whose combined probability is at most $\alpha$. If this quantity is inputted as \textit{ValueAtRisk} the $\alpha$ value will assign as $5\%$. Otherwise the user can specify this quantity with a parameter \xmlAttr{threshold='X'}, where the \xmlAttr{X} represents the requested $\alpha$ value (a floating point value between 0.0 and 1.0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do 0.0 to 1.0 represent 0% to 100%? (Also for expectedShortfall)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's basically like a quantile.

@@ -1,2 +1,2 @@
skew_x,vc_x,percentile_5_x,percentile_95_x,mean_x,kurt_x,median_x,max_x,min_x,samp_x,var_x,sigma_x
0.11423075075,0.188785800293,5.91996682062,8.1183566722,7.28508256545,-3.67853432603,6.33133089078,8.77067587821,5.91996682062,4.0,1.89150549387,1.37532014232
Copy link
Contributor

@joshua-cogliati-inl joshua-cogliati-inl Oct 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are there changes in basic statistics results?

Note that this is REQUIREMENT test, so this needs to be checked by Andrea as well.

Copy link
Collaborator

@alfoa alfoa Oct 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as COB Chair, I approve the modification/regolding of this test.

Thank you Josh for pointing this out.

An analytical test should be added

@joshua-cogliati-inl
Copy link
Contributor

This changes results (since this changes the median and percentile calculation). Can you write a proposed email explaining this?

@joshua-cogliati-inl
Copy link
Contributor

I am sorry about asking for more work, but if we are changing the percentages and the median value, we really need to add a test where we pass in a known vector and check that we get out the exact calculated values, so we can check that the values are really correct this time.

@JiaZhou-PU
Copy link
Collaborator Author

@joshua-cogliati-inl No problem Josh, I will send a test to you and explain.

@moosebuild
Copy link

Job Mingw Test on c861477 : invalidated by @alfoa

@alfoa
Copy link
Collaborator

alfoa commented Oct 9, 2020

@PaulTalbot-INL @dylanjm this PR causes Diff Failures on HERON plugin tests.

@alfoa alfoa added the RAVENv2.1 All tasks and defects that will go in RAVEN v2.1 label Oct 9, 2020
@alfoa
Copy link
Collaborator

alfoa commented Oct 9, 2020

@JiaZhou-PU can you update the issue #1225 (#1225) regarding the new features. I will update the Wiki page (Changelog) at https://github.com/idaholab/raven/wiki/RAVEN-Time-Line

Copy link
Collaborator Author

@JiaZhou-PU JiaZhou-PU left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved

@alfoa alfoa mentioned this pull request Oct 9, 2020
10 tasks
@alfoa
Copy link
Collaborator

alfoa commented Oct 9, 2020

@joshua-cogliati-inl I approved Jia PR. I think we are good to go.

@alfoa
Copy link
Collaborator

alfoa commented Oct 9, 2020

Checklist passed...

PR can be approved...

Comments have been addressed...

Merging...

@alfoa
Copy link
Collaborator

alfoa commented Oct 9, 2020

Plugin tests (HERON Ref Issue idaholab/HERON#42 ) are failing. The HERON team has been notified via email

@alfoa alfoa merged commit b9aceef into idaholab:devel Oct 9, 2020
@alfoa alfoa deleted the ppvar branch October 9, 2020 17:50
@joshua-cogliati-inl
Copy link
Contributor

I think we still need to send out an email to the users' list since this changes calculation results.

@alfoa
Copy link
Collaborator

alfoa commented Oct 12, 2020

Yes agree! @JiaZhou-PU can you draft an email and send it?

@PaulTalbot-INL
Copy link
Collaborator

PaulTalbot-INL commented Oct 12, 2020 via email

@alfoa
Copy link
Collaborator

alfoa commented Oct 12, 2020

see #1339 1339

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RAVENv2.1 All tasks and defects that will go in RAVEN v2.1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[TASK] New metric in post processor
5 participants