Thursday, August 22, 2013

CALCULATION OF XIRR

How do you calculate your returns when you every year you invest different amount and at the end you receive your Money back? Suppose your invest 1000, 1000, 2000, 2000 and 3000 in 5 yrs and Get 11,000 at the end of 5 yrs then what is your Return? It’s 8%. The concept is called IRR.


WHAT IS IRR?


IRR is Internal Rate of Return and it is used to calculate the returns given some amount at a fixed interval i.e. after every 3 months or after every 1 yr. The only thing which matters is that there should be equal distance between two installments. Compared to XIRR it is easy to calculate and you can find so many online IRR calculators.



WHAT IS XIRR?
IRR does not solve one problem and that is when the payments are at Irregular interval. In that case we use XIRR.

CALCULATION OF XIRR

IN XIRR compared to IRR we will take dates in addition as XIRR is for irregular intervals.  The formula for calculating XIRR is given below



where:
di = the ith, or last, payment date.
d1 = the 0th payment date.
Pi = the ith, or last, payment.


Note: A value of N/A will be returned when using this rate of return if the following conditions are
not met:
1. There must be at least one buy in the account.
2. An iterative technique is used for calculating XIRR. Using a changing rate (starting with
guess), XIRR cycles through the calculation until the result is accurate within 0.000001
percent. If XIRR can't find a result that works after 100 tries, the N/A error value is
returned.


Note: One thing which should be kept in mind while calculating IRR/XIRR is Net Present Value is zero (or We can say cash inflows -cash outflows is equal to zero)


if you need any help regarding xirr calculation mail me to :  chandraganeshchowdary@gmail.com

Tuesday, July 2, 2013

How to display jasper report in jsp


import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.HashMap;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.jasperreports.engine.JREmptyDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperRunManager;
public class JasperReportsBrowserDemoServlet extends HttpServlet
{
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
ServletOutputStream servletOutputStream = response.getOutputStream();
File reportFile = new File(getServletConfig().getServletContext()
.getRealPath("report4.jasper"));
byte[] bytes = null;
try
{
bytes = JasperRunManager.runReportToPdf(reportFile.getPath(),
new HashMap(), new JREmptyDataSource());
response.setContentType("application/pdf");
response.setContentLength(bytes.length);
servletOutputStream.write(bytes, 0, bytes.length);
servletOutputStream.flush();
servletOutputStream.close();
}
catch (JRException e)
{
// display stack trace in the browser
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
e.printStackTrace(printWriter);
response.setContentType("text/plain");
response.getOutputStream().print(stringWriter.toString());
}
}
}

Tuesday, June 25, 2013

How to run the sample program given in Getting Started with REST Web Service API?

Report on How to run the sample program given in Getting Started with REST Web Service API?
  • First we have to install maven on your system.

  • Added maven path to eclipse this is external maven. Don’t use embedded maven which is given in eclipse.

  • Note: I am saying not to use embedded maven because it is having a bug. If you use embedded maven for test then it always gives following report.
        SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
        SLF4J: Defaulting to no-operation (NOP) logger implementation
        SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
  • But the thing is there is no need of SLF4J for running this code. We can simply remove this error by adding external maven

  • How to add external maven to eclipse.

  • Step1 Go to window in eclipse menu.
    Step2 Go to maven in the list and in it installations.
    Step3 Click on ADD and add folder of your external maven and click ok.
  • For the first time after adding external maven if we do mvn test it works fine. But for the second time we will get following error.


  • ------------------------------------------------------- T E S T S ------------------------------------------------------- Running com.jaspersoft.jasperserver.rest.sample.BasicResourceCRUDTest log4j:WARN No appenders could be found for logger (com.jaspersoft.jasperserver.rest.sample.RestAPIUtils). log4j:WARN Please initialize the log4j system properly. INFO [com.jaspersoft.jasperserver.rest.sample.RestAPIUtils] sending Request. url: http://localhost:8080/jasperserver/rest/resource req verb: PUT INFO [com.jaspersoft.jasperserver.rest.sample.RestAPIUtils] response status line: HTTP/1.1 400 Bad Request Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 2.785 sec <<< FAILURE! com.jaspersoft.jasperserver.rest.sample.BasicResourceCRUDTest Time elapsed: 2.778 sec <<< FAILURE! java.lang.AssertionError: basic response check did not pass at org.junit.Assert.fail(Assert.java:91) at org.junit.Assert.assertTrue(Assert.java:43) at com.jaspersoft.jasperserver.rest.sample.RestAPIUtils.sendAndAssert(RestAPIUtils.java:123) at com.jaspersoft.jasperserver.rest.sample.RestAPIUtils.sendAndAssert(RestAPIUtils.java:117) at com.jaspersoft.jasperserver.rest.sample.BasicResourceCRUDTest.setUp(BasicResourceCRUDTest.java:47) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31) at org.junit.runners.ParentRunner.run(ParentRunner.java:236) at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252) at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141) at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189) at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165) at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85) at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115) at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75) Results : Failed tests: com.jaspersoft.jasperserver.rest.sample.BasicResourceCRUDTest: basic response check did not pass Tests run: 1, Failures: 1, Errors: 0, Skipped: 0 [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 7.393s [INFO] Finished at: Wed Jun 26 11:59:09 IST 2013 [INFO] Final Memory: 9M/106M [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project RESTCodeSample: There are test failures. [ERROR] [ERROR] Please refer to C:\Users\BizAct20\Desktop\restapicodesample\target\surefire-reports for the individual test results. [ERROR] -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
  • This is because the folder is already created so before running second time we have to make sure that the folder is deleted or not.