.NET,MVC,MVC API,jQuery,SQL Server, Sql Business Intelligence,QlickView,Sharepoint,Sharepoint Performancepoint
Tuesday, September 27, 2016
Integrate MS Dynamics CRM 2015 With Microsoft SharePoint 2013
Provide a complete step by step process on how to integrate Microsoft Dynamics CRM with Microsoft SharePoint using the out-of-the-box configuration tools provided by Microsoft for both platforms.
Step 1:Firstly, you'll want to create a new collection in SharePoint to keep your files separate.
Step 2: We need to setup SharePoint for this List Component. For that download the List component for the correct version of CRM and upload it into the Solutions Gallery of SharePoint.
Step 3: Activate the solution and be sure that the Status is activated.
You may get errors in activation. To rectify, make sure the Microsoft Dynamics CRM Sandbox Processing Service and Microsoft SharePoint foundation Sandboxed Code Service services are started.
Step 4: Then Click on CRM -> Settings -> Document Management as shown below.
Step 5: You will settings available under the document management settings.
Step 6: Click on Document Management Settings, enter the SharePoint site URL where you want to save documents. Click Next. In case you don't have the Microsoft Dynamics CRM List Component it will give you the following warning.
Step 7: Document management can be enabled for those entities in Microsoft Dynamics CRM that can be customized. By default, document management is enabled only for the following entities in a new installation of CRM.
Account
KbArticle
Lead
Opportunity
Product
Quote
SalesLiterature
You can enable document management for an entity, as shown below.
Step 8: Once document management is enabled for an entity, you will see the option for documents as shown below.
Step 9: You can add document location for this entity assuming the location is created and the appropriate permissions are set on SharePoint.
Step 10: And if everything goes right, you will see the familiar (at least to me) interface of SharePoint from within Dynamics CRM as shown below. You can start uploading documents and use document management functionality.
Step 11: In case you do not want to manage the folder structure on your own and let CRM make it for you, if the CRM List Component is installed correctly, you get an option for creating a folder structure based on the entities.
CRM users and non-CRM users can work together to achieve common business goals through improved communication by this integration.
Thursday, August 25, 2016
CRMAF Querys:Multiple Records in Dynamics CRM and SSRS Run on
In Dynamics CRM, when we create a report in SSRS we can choose to add filtering so it can be run on a record based, or multiple records based from CRM.
Say we want to create a custom invoice report, which contains our company logo, and some details about the invoice and line items. This will typically be a 1 page report, which would run on one Product at a time.
Now say we need to print these invoices out every day, of which there could be upwards of one hundred invoices to run and print at once. Opening each invoice and running the report individually is tedious, and in an automated system like Dynamics CRM, there should be an easier way.
We can make the report available to run on multiple records, however because of the way it’s designed, it will only print one page. Additionally, the line items from all Prodcuts will be displayed in the table, which is not right.
What we really need is the report to run separately for each invoice, but the only way to do this using a single report is to put everything in a repeating table. Unfortunately, we cannot put a repeating table inside a repeating table, so the line items cannot be added.
1)First we need to make a few minor adjustments to the original report query. Instead of getting all invoices and using CRMAF for filtering, we need to add a WHERE clause with a parameter for the invoiceid. Something like this (note this example is using SQL, but the same rules apply for FetchXML):
SELECT id ,name WHERE filteredproducts P
INNER JOIN filteredcategory CP on CP.productid=P.ID
WHERE P.ID=@ID
2)Next we need to edit the parameter properties to make it hidden, and we should also specify a default value using the ID of an Products from our system so that we can preview the report.
We should then rename this report to include ‘Sub-Report’, and create another report in our project for the main report. The query for the main report should simply get the id and perform the pre-filtering:
SELECT id FROM filteredProducts as CRMAF_FilteredProducts
For the body of the main report, we need to add a table with just one repeating cell. The table should use our only dataset, and should group by the id column.
3)Then we need to drag a Subreport item from the toolbox into the table cell.
4)Then we need to pass in the Id as a parameter to the subreport, so click on Parameters from the subreport properties, and add the Id as a parameter. There should only be 1 parameter and 1 column to pick from.
5)One last thing I like to do is edit the group properties again and make sure Page Breaking is added between each instance of the group. This ensures that when the report is run, it will split each Products onto its own page.
6)Now you can upload the reports to CRM. First, upload the main/parent report, and allow it to run on forms and views for the Product entity.
Hope it's help you...
Say we want to create a custom invoice report, which contains our company logo, and some details about the invoice and line items. This will typically be a 1 page report, which would run on one Product at a time.
Now say we need to print these invoices out every day, of which there could be upwards of one hundred invoices to run and print at once. Opening each invoice and running the report individually is tedious, and in an automated system like Dynamics CRM, there should be an easier way.
We can make the report available to run on multiple records, however because of the way it’s designed, it will only print one page. Additionally, the line items from all Prodcuts will be displayed in the table, which is not right.
What we really need is the report to run separately for each invoice, but the only way to do this using a single report is to put everything in a repeating table. Unfortunately, we cannot put a repeating table inside a repeating table, so the line items cannot be added.
1)First we need to make a few minor adjustments to the original report query. Instead of getting all invoices and using CRMAF for filtering, we need to add a WHERE clause with a parameter for the invoiceid. Something like this (note this example is using SQL, but the same rules apply for FetchXML):
SELECT id ,name WHERE filteredproducts P
INNER JOIN filteredcategory CP on CP.productid=P.ID
WHERE P.ID=@ID
2)Next we need to edit the parameter properties to make it hidden, and we should also specify a default value using the ID of an Products from our system so that we can preview the report.
We should then rename this report to include ‘Sub-Report’, and create another report in our project for the main report. The query for the main report should simply get the id and perform the pre-filtering:
SELECT id FROM filteredProducts as CRMAF_FilteredProducts
For the body of the main report, we need to add a table with just one repeating cell. The table should use our only dataset, and should group by the id column.
3)Then we need to drag a Subreport item from the toolbox into the table cell.
4)Then we need to pass in the Id as a parameter to the subreport, so click on Parameters from the subreport properties, and add the Id as a parameter. There should only be 1 parameter and 1 column to pick from.
5)One last thing I like to do is edit the group properties again and make sure Page Breaking is added between each instance of the group. This ensures that when the report is run, it will split each Products onto its own page.
6)Now you can upload the reports to CRM. First, upload the main/parent report, and allow it to run on forms and views for the Product entity.
Hope it's help you...
Wednesday, January 6, 2016
Error occurred in deployment step 'Install app for SharePoint': Failed to extract the cab file in the solution.
This error, Failed to extract the cab file in the solution , will be thrown while deploying a WSP in SharePoint , if that WSP contains any files with special characters that are not accepted by SharePoint in its file name. This applies to sand box solution as well. The only resolution would be to rename the file without any non acceptable special characters.
Kindly check any file with special characters,If there remove special characters,then deploye....
Enj...
Kindly check any file with special characters,If there remove special characters,then deploye....
Enj...
Wednesday, December 23, 2015
Error occurred in deployment step 'Install app for SharePoint': The requested service, AppMng.svc' could not be activated. See the server's diagnostic trace logs for more information
The cause for getting the above error is free memory is less to start this service. So you need to free some memory.
“Memory gates checking failed because the free memory is less than 5% of total memory. As a result, the service will not be available for incoming requests. To resolve this, either reduce the load on the machine or adjust the value of minFreeMemoryPercentageToActivateService on the serviceHostingEnvironment config element.”
You can resolve this issue by restarting the SPSearchHostController service in services.msc console as this consumes lot of memory, which will free some memory for you. You can also try to reboot your server or close unnecessary applications to free some memory.
more :http://social.technet.microsoft.com/wiki/contents/articles/25793.step-by-step-guide-to-configure-environment-for-creating-your-first-sharepoint-hosted-app.aspx
Error occurred in deployment step 'Uninstall app for SharePoint': The System Account cannot perform this action
- Create a new account.
- Add this account to local admin.
- Then add the account to farm admin group. Open sharepoint central administration, go to Security. From there select Manage the farm administrators group.
- Now open visual studio into different user ( Shift + Right Click, and open with different user ). and put the user which you have created now.
Thursday, December 17, 2015
CONFIGURATION FAILED – FAILED TO CREATE SAMPLE DATA-SHAREPOINT 2013
I am installing SharePoint 2013 for the first time – it’s a standalone installation on a clean Windows 2012 server. SharePoint appears to have installed without incident but the Configuration Wizard has failed with the following message: “The SDDL string contains an invalid sid or a sid that cannot be translated.”
It appears to have failed to create the sample database. After rebuilding the server to try again, and spending a bit of time searching for a solution, it would appear that this is a common problem and there isn’t one solution for all. For me, it only took a few simple steps to fix by sharing a folder and setting some permissions:
1. Once the Configuration Wizard has failed browse to C:\Program Files\Microsoft Office Servers\15.0\Data\Office Server
2. Right-click on the Analytics_GUID folder and choose Properties
3. On the Sharing tab click Advanced Sharing
4. Tick the box to share the folder (don’t change the share name) and click the Permissions button
5. Click Add, enter WSS_ADMIN_WPG and click OK. Grant the group Full Control and click OK
6. Click Close
I ran the Configuration Wizard again and it completed successfully
eNJ....
Thursday, August 14, 2014
Table per concrete class example in entity framework by using code first ..
example:
step 1:Crate Main class:
public class Output//Main class
{
public long Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public double EstValue { get; set; }
public long PhaseId { get; set; }
[JsonIgnore]
public Phase Phase { get; set; }
// public abstract double Total();
public OutputCategory OutputCategory { get; set; }
}
step 2:
Relationship Output calss :
public class ServiceDeliveryOutput:Output
{
public double NumberOfUnit { get; set; }
public Money RevenueGenerated { get; set; }
public Money EstimatedUnitValue { get; set; }
public ServiceDeliveryOutput()
{
RevenueGenerated = new Money();
EstimatedUnitValue = new Money();
}
public Money Total()
{
throw new NotImplementedException();
}
public class ReachNIntermediateOutcome:Output
{
public double Numerator { get; set; }
public double Denominator { get; set; }
public double Total()
{
throw new NotImplementedException();
}
}
}
step 3:
Then we SET Mapping in db Context :
modelBuilder.Entity<ServiceDeliveryOutput>().Map(m =>
{
m.MapInheritedProperties();
m.ToTable("ServiceDeliveryOutputs");
});
modelBuilder.Entity<ReachNIntermediateOutcome>().Map(m =>
{
m.MapInheritedProperties();
m.ToTable("ReachNIntermediateOutcomes");
});
Enj..Hope it will help u..all the best....
step 1:Crate Main class:
public class Output//Main class
{
public long Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public double EstValue { get; set; }
public long PhaseId { get; set; }
[JsonIgnore]
public Phase Phase { get; set; }
// public abstract double Total();
public OutputCategory OutputCategory { get; set; }
}
step 2:
Relationship Output calss :
public class ServiceDeliveryOutput:Output
{
public double NumberOfUnit { get; set; }
public Money RevenueGenerated { get; set; }
public Money EstimatedUnitValue { get; set; }
public ServiceDeliveryOutput()
{
RevenueGenerated = new Money();
EstimatedUnitValue = new Money();
}
public Money Total()
{
throw new NotImplementedException();
}
public class ReachNIntermediateOutcome:Output
{
public double Numerator { get; set; }
public double Denominator { get; set; }
public double Total()
{
throw new NotImplementedException();
}
}
}
step 3:
Then we SET Mapping in db Context :
modelBuilder.Entity<ServiceDeliveryOutput>().Map(m =>
{
m.MapInheritedProperties();
m.ToTable("ServiceDeliveryOutputs");
});
modelBuilder.Entity<ReachNIntermediateOutcome>().Map(m =>
{
m.MapInheritedProperties();
m.ToTable("ReachNIntermediateOutcomes");
});
Enj..Hope it will help u..all the best....
create Complex type in entity framework
Create calss:
public class Address//Complex type
{
public string Location { get; set; }
}
public class Person : IComparable
{
public long Id { get; set; }
public long UserId { get; set; }//Mapping to User table
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public long? OrganizationId { get; set; }
public Organization Organization { get; set; }
public User User { get; set; }
public string Phone { get; set; }
public Address Address { get; set; }///Mapping class
public DateTime CreatedOn { get; set; }
public DateTime ModifiedOn { get; set; }
public int CompareTo(object obj)
{
throw new NotImplementedException();
}
}
In Db Context :
modelBuilder.ComplexType<Address>();
When you go to use Complex Type with an existing database, you'll probably find your existing database won't support it. EF naming conventions mean the database is going to expect the Customer table corresponding to my Customer entity to have columns with the names [Address_Location] and so on.
Enj..Hope it will help you ..all the best
public class Address//Complex type
{
public string Location { get; set; }
}
public class Person : IComparable
{
public long Id { get; set; }
public long UserId { get; set; }//Mapping to User table
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public long? OrganizationId { get; set; }
public Organization Organization { get; set; }
public User User { get; set; }
public string Phone { get; set; }
public Address Address { get; set; }///Mapping class
public DateTime CreatedOn { get; set; }
public DateTime ModifiedOn { get; set; }
public int CompareTo(object obj)
{
throw new NotImplementedException();
}
}
In Db Context :
modelBuilder.ComplexType<Address>();
When you go to use Complex Type with an existing database, you'll probably find your existing database won't support it. EF naming conventions mean the database is going to expect the Customer table corresponding to my Customer entity to have columns with the names [Address_Location] and so on.
Enj..Hope it will help you ..all the best
Wednesday, August 13, 2014
c# IRR function:Arguments not valid exception
I would like to provide you two points of view from the document of this method:
1. The first parameter "ValueArray" is the array of Double specifying cash flow values. The array must contain at least one negative value (a payment) and one positive value (a receipt).
2. The IRR function uses the order of values within the array to interpret the order of payments and receipts. Be sure to enter your payment and receipt values in the correct sequence. The cash flow for each period does not need to be fixed, as it is for an annuity.
Example:
List<double> items = new List<double>();
items.Add(-10000);
items.Add(30000);
items.Add(50000);
items.Add(50000);
double[] itemsArray = items.ToArray();
Hope i will help all financial domain developers..enj...all the best
Financial Fuctions in c# (IRR,PV,NPV,DDB,SLN,SYD,FV,MIRR , MIRR ,NPer,IPmt ,PPmt )
using System;
using System.IO;
using System.Collections;
using Microsoft.VisualBasic;
namespace MonoTests.Microsoft_VisualBasic
{
[TestFixture]
public class FinancialTests
{
public FinancialTests()
{
}
[SetUp]
public void GetReady()
{
}
[TearDown]
public void Clean()
{
}
#region DDB Tests
//[Test]
//[ExpectedException(typeof(ArgumentException))]
//public void DDBArg1()
//{
// // docs doesn`t say it should throw an exception on 'cost' <= 0
// Financial.DDB (-1, 1, 1, 1, 1);
//}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void DDBArg2()
{
Financial.DDB (1, -1, 1, 1, 1);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void DDBArg3()
{
Financial.DDB (1, 1, 0, 1, 1);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void DDBArg4()
{
Financial.DDB (1, 1, 1, 1, 0);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void DDBArg5()
{
// Period has to be <= Life
Financial.DDB (1, 1, 1, 2, 1);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void DDBArg6()
{
// Period has to be > 0
Financial.DDB (1, 1, 1, 0, 1);
}
[Test]
public void DDB()
{
double ddb = Financial.DDB(1000, 50, 10, 5, 3);
Assert.AreEqual(72.03, ddb, 1E-10);
ddb = Financial.DDB (1000, 50, 10, 5, 2);
Assert.AreEqual(81.92, ddb, 1E-10);
ddb = Financial.DDB (1000, 50, 10, 1, 0.1);
Assert.AreEqual(10, ddb, 1E-10);
ddb = Financial.DDB (1000, 50, 10, 0.3, 0.1);
Assert.AreEqual(10, ddb, 1E-10);
}
[Test]
public void DDB_1()
{
Assert.AreEqual(47.999403820109578, Financial.DDB(1500, 120, 24, 12, 2.0), 1E-10);
Assert.AreEqual(479.9940382010958, Financial.DDB(15000, 1000, 24, 12, 2.0), 1E-10);
Assert.AreEqual(391.34749179845591, Financial.DDB(15000, 1000, 48, 12, 2.0), 1E-10);
Assert.AreEqual(33.646996435384537, Financial.DDB(1500, 120, 24, 12, 4.0), 1E-10);
Assert.AreEqual(43.160836714378092, Financial.DDB(1500, 100, 48, 12, 6.0), 1E-10);
Assert.AreEqual(24.789790003786901, Financial.DDB(1500, 100, 48, 12, 1.0), 1E-10);
Assert.AreEqual(383.10767441791506, Financial.DDB(15000, 1000, 48, 12.5, 2.0), 1E-10);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void DDB_2()
{
// Argument 'Factor' is not a valid value.
double d = Financial.DDB(1500, 120, 12, 24, 2.0);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void DDB_3()
{
// Argument 'Factor' is not a valid value.
double d = Financial.DDB(1500, 120, 48, 24, -1);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void DDB_4()
{
// Argument 'Factor' is not a valid value.
double d = Financial.DDB(1500, -2, 48, 24, 2.0);
}
[Test]
//[ExpectedException(typeof(ArgumentException))]
//LAMESPEC: MSDN claims the exception should be thrown in this case
public void DDB_5()
{
// Argument 'Factor' is not a valid value.
double d = Financial.DDB(-5, 120, 48, 24, 2.0);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void DDB_6()
{
// Argument 'Factor' is not a valid value.
double d = Financial.DDB(1500, 120, 48, -24, 2.0);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void DDB_7()
{
// Argument 'Factor' is not a valid value.
double d = Financial.DDB(1500, 120, -2, -5, 2.0);
}
#endregion
#region SLN Tests
[Test]
[ExpectedException(typeof(ArgumentException))]
public void TestSLNArgs()
{
Financial.SLN (0, 0, 0);
}
[Test]
public void SLN()
{
// double d = Financial.SLN (0, 0, 1);
// Assert.AreEqual( 0, d, "#SLN01");
Assert.AreEqual(0.037681159420289857, Financial.SLN (45, 32, 345), 0.00002);
Assert.AreEqual(0.657894736842105, Financial.SLN (-54, -4, -76), 0.00002);
}
[Test]
public void SLN_1()
{
Assert.AreEqual(20.833333333333332, Financial.SLN(1500, 500, 48));
Assert.AreEqual(10.416666666666666, Financial.SLN(1500, 500, 96));
Assert.AreEqual(0, Financial.SLN(500, 500, 96));
Assert.AreEqual(500, Financial.SLN(1500, 500, 2));
Assert.AreEqual(-500, Financial.SLN(1500, 500, -2));
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void SLN_2()
{
//Argument 'Life' cannot be zero.
Financial.SLN(1500, 500, 0);
}
#endregion
#region SYD Tests
[Test]
[ExpectedException(typeof(ArgumentException))]
public void SYDArgs1()
{
Financial.SYD (1, 1, 1, -1);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void SYDArgs2()
{
Financial.SYD (1, -1, 1, 1);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void SYDArgs3()
{
Financial.SYD (1, 1, 1, 2);
}
[Test]
public void SYD()
{
double d = Financial.SYD (23, 34, 26, 21);
Assert.AreEqual( -0.188034188034188, d, 0.0001, "#SYD01");
d = Financial.SYD (0, 1, 1, 1);
Assert.AreEqual( -1, d, 0.00001, "#SYD02");
}
[Test]
public void SYD_1()
{
Assert.AreEqual (44.047619047619044, Financial.SYD (1500, 100, 48, 12), 1E-10);
Assert.AreEqual (1.1904761904761905, Financial.SYD (1500, 100, 48, 48), 1E-10);
Assert.AreEqual(0, Financial.SYD(100, 100, 48, 48));
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void SYD_2()
{
// Argument 'Salvage' must be greater than or equal to zero.
Financial.SYD(1500, -100, 48, 12);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void SYD_3()
{
// Argument 'Period' must be less than or equal to argument 'Life'.
Financial.SYD(1500, 100, 8, 12);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void SYD_4()
{
// Argument 'Period' must be greater than zero.
Financial.SYD(1500, 100, 48, 0);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void SYD_5()
{
// Argument 'Period' must be greater than zero.
Financial.SYD(1500, 100, 48, -2);
}
#endregion
#region FV Tests
[Test]
public void FV()
{
double d = Financial.FV (10, 5, 3, 7, DueDate.BegOfPeriod);
Assert.AreEqual (-1658822, d, "#FV01");
d = Financial.FV (10, 5, 3, 7, DueDate.EndOfPeriod);
Assert.AreEqual (-1175672, d, "#FV02");
d = Financial.FV (0, 5, 3, 7, DueDate.BegOfPeriod);
Assert.AreEqual (-22, d, "#FV03");
d = Financial.FV(0, 1, 1, 1, DueDate.BegOfPeriod);
Assert.AreEqual (-2, d, "#FV04");
d = Financial.FV (0, 0, 0, 0, DueDate.BegOfPeriod);
Assert.AreEqual (0, d, "#FV05");
d = Financial.FV (-3, -5, -6, -4, DueDate.BegOfPeriod);
Assert.AreEqual (-4.25, d, "#FV06");
}
[Test]
public void FV_1()
{
Assert.AreEqual(-5042.6861628644065, Financial.FV (0.1 / 48, 48, 100, 0, DueDate.EndOfPeriod), 1E-8);
Assert.AreEqual(5042.6861628644065, Financial.FV(0.1/48, 48, -100, 0, DueDate.EndOfPeriod), 1E-8);
Assert.AreEqual(6026.9653563801103, Financial.FV(0.45/48, 48, -100, 0, DueDate.EndOfPeriod), 1E-8);
Assert.AreEqual(30134.826781900552, Financial.FV(0.45/48, 48, -500, 0, DueDate.EndOfPeriod), 1E-8);
Assert.AreEqual(5053.1917590370413, Financial.FV(0.1/48, 48, -100, 0, DueDate.BegOfPeriod), 1E-8);
Assert.AreEqual(1727.5182776853812, Financial.FV(0.1/48, 48, -100, 3000, DueDate.EndOfPeriod), 1E-8);
Assert.AreEqual(8357.8540480434312, Financial.FV(0.1/48, 48, -100, -3000, DueDate.EndOfPeriod), 1E-8);
Assert.AreEqual(1738.023873858016, Financial.FV(0.1/48, 48, -100, 3000, DueDate.BegOfPeriod), 1E-8);
Assert.AreEqual(8368.359644216067, Financial.FV(0.1/48, 48, -100, -3000, DueDate.BegOfPeriod), 1E-8);
Assert.AreEqual(-4572.3341785092407, Financial.FV(-0.1/48, 48, 100, 0, DueDate.EndOfPeriod), 1E-8);
Assert.AreEqual(-4599.4962842992118, Financial.FV(-0.1/48, 48.3, 100, 0, DueDate.EndOfPeriod), 1E-8);
}
#endregion
#region Rate Tests
[Category ("NotWorking")]//Not Implemented
[Test]
[ExpectedException(typeof(ArgumentException))]
public void RateArgs1()
{
double d = Financial.Rate (-1, 1, 1, 1, DueDate.BegOfPeriod, 1);
}
[Category ("NotWorking")]//Not Implemented
[Test]
public void Rate()
{
Assert.AreEqual(-1.5000000000001, Financial.Rate (1, 1, 1, 1, DueDate.BegOfPeriod, 0.1), 0.1);
Assert.AreEqual(-1.5000000000001, Financial.Rate (1, -1, -1, -1, DueDate.BegOfPeriod, 0.1), 0.1);
Assert.AreEqual(-1.71428571428571, Financial.Rate (1, 2, 12, 10, DueDate.BegOfPeriod, 0.5), 0.1);
}
[Category ("NotWorking")]//Not Implemented
[Test]
public void Rate_1()
{
Assert.AreEqual(-0.067958335561249847, Financial.Rate(48, -120, 50000, 0, DueDate.EndOfPeriod, 0.1));
Assert.AreEqual(-0.054284323350630818, Financial.Rate(48, -200, 50000, 0, DueDate.EndOfPeriod, 0.1));
Assert.AreEqual(-0.03391640485393424, Financial.Rate(48, -400, 50000, 0, DueDate.EndOfPeriod, 0.1));
Assert.AreEqual(0.19996831303445506, Financial.Rate(48, -1000, 5000, 0, DueDate.EndOfPeriod, 0.1));
Assert.AreEqual(-0.99999999998846933, Financial.Rate(48, -1000, 5000, 0, DueDate.BegOfPeriod, 0.1));
Assert.AreEqual(-0.055871364867281934, Financial.Rate(48, -200, 50000, 0, DueDate.BegOfPeriod, 0.1));
Assert.AreEqual(-0.065503055347169575, Financial.Rate(48, -200, 50000, 1000, DueDate.EndOfPeriod, 0.1));
Assert.AreEqual(-0.058920469572311909, Financial.Rate(48, -200, 50000, 500, DueDate.EndOfPeriod, 0.1));
}
[Category ("NotWorking")]//Not Implemented
[Test]
public void Rate_2()
{
Assert.AreEqual(-0.067958335561434935, Financial.Rate(48, -120, 50000, 0, DueDate.EndOfPeriod, 0.3));
Assert.AreEqual(-0.054284323350996831, Financial.Rate(48, -200, 50000, 0, DueDate.EndOfPeriod, 0.3));
Assert.AreEqual(-0.033916404853936467, Financial.Rate(48, -400, 50000, 0, DueDate.EndOfPeriod, 0.3));
Assert.AreEqual(0.19996831303445506, Financial.Rate(48, -1000, 5000, 0, DueDate.EndOfPeriod, 0.2));
Assert.AreEqual(-0.99999999999999079, Financial.Rate(48, -1000, 5000, 0, DueDate.BegOfPeriod, 0.3));
Assert.AreEqual(-0.055871364867277139, Financial.Rate(48, -200, 50000, 0, DueDate.BegOfPeriod, 0.3));
Assert.AreEqual(-0.065503055348340639, Financial.Rate(48, -200, 50000, 1000, DueDate.EndOfPeriod, 0.3));
Assert.AreEqual(-0.058920469572100169, Financial.Rate(48, -200, 50000, 500, DueDate.EndOfPeriod, 0.3));
}
[Category ("NotWorking")]//Not Implemented
[Test]
[ExpectedException(typeof(ArgumentException))]
public void Rate_3()
{
// Argument 'NPer' must be greater than zero.
Financial.Rate(0, -120, 50000, 0, DueDate.EndOfPeriod, 0.1);
}
[Category ("NotWorking")]//Not Implemented
[Test]
[ExpectedException(typeof(ArgumentException))]
public void Rate_4()
{
// Argument 'NPer' must be greater than zero.
Financial.Rate(-10, -120, 50000, 0, DueDate.EndOfPeriod, 0.1);
}
[Category ("NotWorking")]//Not Implemented
[Test]
[ExpectedException(typeof(ArgumentException))]
public void Rate_5()
{
// Cannot calculate rate using the arguments provided.
Financial.Rate(48, -1000, 5000, 0, DueDate.EndOfPeriod, 0.3);
}
#endregion
#region IRR Tests
[Category ("NotWorking")]//Not Implemented
[Test]
[ExpectedException(typeof(ArgumentException))]
public void IRRArgs1()
{
double [] arr = new double [0];
Financial.IRR (ref arr, 0.1);
}
[Category ("NotWorking")]//Not Implemented
[Test]
[ExpectedException(typeof(ArgumentException))]
public void IRRArgs2()
{
double [] arr = new double [] {134};
Financial.IRR (ref arr, 0.1);
}
// [Test]
// [ExpectedException(typeof(ArgumentException))]
// public void IRRArgs3()
// {
// // -0.99 as Guess throws an exception on MS.NET, -0.98 doesn't
// //double [] arr = new double [] {-70000, 22000, 25000, 28000, 31000};
// //double d = Financial.IRR (ref arr, -0.99);
// }
[Category ("NotWorking")]//Not Implemented
[Test]
public void IRR()
{
double [] arr = new double [] {-70000, 22000, 25000, 28000, 31000};
double d = Financial.IRR (ref arr, 0.1);
Assert.AreEqual ( 0.177435884422527, d, 0.00001);
}
[Category ("NotWorking")]//Not Implemented
[Test]
public void IRR_1 ()
{
double [] values = new double [] { -50000, 20000, 20000, 20000, 10000 };
Assert.AreEqual (0.16479098450887533, Financial.IRR (ref values, 0.1));
Assert.AreEqual (0.16479098450893837, Financial.IRR (ref values, 0.3));
Assert.AreEqual (0.16479098450893415, Financial.IRR (ref values, 0.5));
values = new double [] { -100000, 40000, 35000, 30000, 25000 };
Assert.AreEqual (0.12441449540624081, Financial.IRR (ref values, 0.1));
Assert.AreEqual (0.12441449541502105, Financial.IRR (ref values, 0.3));
Assert.AreEqual (0.12441449541025705, Financial.IRR (ref values, 0.5));
}
[Category ("NotWorking")]//Not Implemented
[Test]
[ExpectedException(typeof(ArgumentException))]
public void IRR_2()
{
//Arguments are not valid.
double[] values = new double[] {-500000, 20, 20, 20, 10000};
Financial.IRR(ref values, 10000);
}
[Category ("NotWorking")]//Not Implemented
[Test]
[ExpectedException(typeof(ArgumentException))]
public void IRR_3()
{
//Arguments are not valid.
double[] values = new double[] {100, 20, 30, 30, 30};
Financial.IRR(ref values, 0.1);
}
#endregion
#region MIRR Tests
[Test]
[ExpectedException(typeof(ArgumentException))]
public void MIRRArgs1()
{
double [] arr = new double [] {-70000, 22000, 25000, 28000, 31000};
double d = Financial.MIRR(ref arr, -1, 1);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void MIRRArgs2()
{
double [] arr = new double [] {-70000, 22000, 25000, 28000, 31000};
double d = Financial.MIRR(ref arr, 1, -1);
}
[Test]
public void MIRR()
{
double [] arr = new double [] {-70000, 22000, 25000, 28000, 31000};
double d = Financial.MIRR (ref arr, 1, 1);
Assert.AreEqual(0.509044845533018, d, 0.00001, "#MIRR01");
arr = new double [] {-70000, 22000, 25000, 28000, 31000};
d = Financial.MIRR (ref arr, 5, 5);
Assert.AreEqual(2.02366041666348, d, 0.00001, "#MIRR02");
}
[Test]
public void MIRR_1()
{
double[] values = new double[] {-50000, 20000, 20000, 20000, 10000};
Assert.AreEqual(0.14382317535283296, Financial.MIRR(ref values, 0.1, 0.12), 1E-10);
Assert.AreEqual(0.32152371134887248, Financial.MIRR(ref values, 0.3, 0.5), 1E-10);
Assert.AreEqual(0.41431961645993387, Financial.MIRR(ref values, 0.5, 0.7), 1E-10);
values = new double[] {-100000, 40000, 35000, 30000, 25000};
Assert.AreEqual(0.12239312521886214, Financial.MIRR(ref values, 0.1, 0.12), 1E-10);
Assert.AreEqual(0.29787828889780776, Financial.MIRR(ref values, 0.3, 0.5), 1E-10);
Assert.AreEqual(0.39034333083777972, Financial.MIRR(ref values, 0.5, 0.7), 1E-10);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void MIRR_2()
{
// Argument 'FinanceRate' is not a valid value.
double[] values = new double[] {-50000, 20000, 20000, 20000, 10000};
Financial.MIRR(ref values, -1, 0.12);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void MIRR_3()
{
// Argument 'ReinvestRate' is not a valid value.
double[] values = new double[] {-50000, 20000, 20000, 20000, 10000};
Financial.MIRR(ref values, 0.1, -1);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void MIRR_4()
{
// Argument 'ReinvestRate' is not a valid value.
double[] values = new double[] {-50000, 20000, 20000, 20000, 10000};
Financial.MIRR(ref values, 0.1, -3);
}
[Test]
[ExpectedException(typeof(System.NullReferenceException))]
public void MIRR_5()
{
double[] values = null;
Financial.MIRR(ref values, 0.1, 0.12);
}
[Category ("NotWorking")]
[Category ("TargetJvmNotWorking")]
[Test]
[ExpectedException(typeof(DivideByZeroException))]
public void MIRR_6()
{
double[] values = new double[] {100, 20, 30, 30, 30};
Financial.MIRR(ref values, 0.1, 0.1);
}
#endregion
#region NPer Tests
[Test]
[ExpectedException(typeof(ArgumentException))]
public void NPerArgs1()
{
double d = Financial.NPer (-1, 2, 2, 2, DueDate.BegOfPeriod);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void NPerArgs2()
{
double d = Financial.NPer (0, 0, 2, 2, DueDate.BegOfPeriod);
}
[Test]
public void NPer()
{
double d = Financial.NPer (3, 4, 6, 2, DueDate.BegOfPeriod);
Assert.AreEqual(-0.882767373181489, d, 0.0000001, "#NPer01");
d = Financial.NPer (1, -4, -6, -2, DueDate.EndOfPeriod);
Assert.AreEqual(-2.32192809488736, d, 0.0000001, "#NPer02");
}
[Test]
public void NPer_1()
{
Assert.AreEqual(-47.613161535165531, (Financial.NPer(0.1/48, 200, 10000, 0, DueDate.EndOfPeriod)), 0.00000001);
Assert.AreEqual(-47.518910769564712, Financial.NPer(0.1/48, 200, 10000, 0, DueDate.BegOfPeriod), 0.00000001);
Assert.AreEqual(-401.12014892843246, Financial.NPer(0.1/48, 200, 10000, 50000, DueDate.EndOfPeriod), 0.0000001);
Assert.AreEqual(-399.9412969471162, Financial.NPer(0.1/48, 200, 10000, 50000, DueDate.BegOfPeriod), 0.0000001);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void NPer_2()
{
// Argument 'Rate' is not a valid value.
Financial.NPer(-1, 200, 10000, 0, DueDate.EndOfPeriod);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void NPer_3()
{
// Argument 'Pmt' is not a valid value.
Financial.NPer(0, 0, 10000, 0, DueDate.EndOfPeriod);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void NPer_4()
{
// Cannot calculate number of periods using the arguments provided.
Financial.NPer(0.1/48, 0, 10000, 0, DueDate.EndOfPeriod);
}
#endregion
#region IPmt Tests
[Test]
[ExpectedException(typeof(ArgumentException))]
public void IPmtArgs1()
{
Financial.IPmt (3, 6, 4, 2, 2, DueDate.BegOfPeriod);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void IPmtArgs2()
{
Financial.IPmt (3, 0, 4, 2, 2, DueDate.BegOfPeriod);
}
[Test]
public void IPmt()
{
double d = Financial.IPmt (10, 2, 3, 7, 9, DueDate.BegOfPeriod);
Assert.AreEqual ( -6.25427204374573, d, 1E-10, "#IPmt01");
d = Financial.IPmt (10, 4, 4, 7, 4, DueDate.EndOfPeriod);
Assert.AreEqual ( -60.0068306011053, d, 1E-10 , "#IPmt02");
d = Financial.IPmt (0, 5, 7, 7, 2, DueDate.BegOfPeriod);
Assert.AreEqual( 0, d, "#IPmt03");
d = Financial.IPmt (1000, 1, 7, 7, 2, DueDate.BegOfPeriod);
Assert.AreEqual( 0, d, "#IPmt03");
d = Financial.IPmt (-5, 5, 7, -7, -2, DueDate.BegOfPeriod);
Assert.AreEqual(8.92508391821792, d, 1E-10, "#IPmt04");
}
[Test]
public void IPmt_1()
{
Assert.AreEqual(-29.246960945707116, Financial.IPmt(0.1/48, 36, 48, 50000, 0, DueDate.EndOfPeriod), 1E-10);
Assert.AreEqual(-55.550772957533624, Financial.IPmt(0.1/48, 24, 48, 50000, 0, DueDate.EndOfPeriod), 1E-10);
Assert.AreEqual(-54.4678461379274, Financial.IPmt(0.1/48, 24.5, 48, 50000, 0, DueDate.EndOfPeriod), 1E-10);
Assert.AreEqual(-2.2779661153231245, Financial.IPmt(0.1/48, 48, 48, 50000, 0, DueDate.EndOfPeriod), 1E-10);
Assert.AreEqual(42.6652760279442, Financial.IPmt(0.1/48, 24.3, 48.3, 50000, 100000, DueDate.EndOfPeriod), 1E-9);
Assert.AreEqual(-29.186156453096753, Financial.IPmt(0.1/48, 36, 48, 50000, 0, DueDate.BegOfPeriod), 1E-10);
Assert.AreEqual(-55.435282785064992, Financial.IPmt(0.1/48, 24, 48, 50000, 0, DueDate.BegOfPeriod), 1E-10);
Assert.AreEqual(-54.3546073725681, Financial.IPmt(0.1/48, 24.5, 48, 50000, 0, DueDate.BegOfPeriod), 1E-10);
Assert.AreEqual(-2.2732302190335001, Financial.IPmt(0.1/48, 48, 48, 50000, 0, DueDate.BegOfPeriod), 1E-10);
Assert.AreEqual(201.49943498736394, Financial.IPmt(0.1/48, 48, 48, 50000, 100000, DueDate.EndOfPeriod), 1E-9);
Assert.AreEqual(201.08051724310744, Financial.IPmt(0.1/48, 48, 48, 50000, 100000, DueDate.BegOfPeriod), 1E-9);
Assert.AreEqual(42.5765748303808, Financial.IPmt(0.1/48, 24.3, 48.3, 50000, 100000, DueDate.BegOfPeriod), 1E-9);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void IPmt_2()
{
// Argument 'Per' is not a valid value.
Financial.IPmt(0.1/48, 56, 48, 50000, 0, DueDate.EndOfPeriod);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void IPmt_3()
{
// Argument 'Per' is not a valid value.
Financial.IPmt(0.1/48, -48, -48, 50000, 0, DueDate.EndOfPeriod);
}
#endregion
#region Pmt Tests
[Test]
[ExpectedException(typeof(ArgumentException))]
public void PmtArgs()
{
Financial.Pmt (1, 0, 1, 1, DueDate.BegOfPeriod);
}
[Test]
public void Pmt()
{
double d = Financial.Pmt (2, 5, 2, 3, DueDate.BegOfPeriod);
Assert.AreEqual (-1.3471074380165289, d, 1E-10, "#Pmt01");
d = Financial.Pmt (2, 5, 2, 3, DueDate.EndOfPeriod);
Assert.AreEqual (-4.0413223140495864, d, 1E-10, "#Pmt02");
d = Financial.Pmt (-3, -5, -3, -4, DueDate.BegOfPeriod);
Assert.AreEqual (-5.6818181818181817, d, 1E-10, "#Pmt03");
d = Financial.Pmt (-3, -5, -3, -4, DueDate.EndOfPeriod);
Assert.AreEqual (11.363636363636363, d, 1E-10, "#Pmt04");
d = Financial.Pmt (0, 1, 0, 0, DueDate.BegOfPeriod);
Assert.AreEqual ( 0, d, 1E-10, "#Pmt05");
d = Financial.Pmt (0, 1, 0, 0, DueDate.EndOfPeriod);
Assert.AreEqual ( 0, d, 1E-10, "#Pmt06");
}
[Test]
public void Pmt_1()
{
Assert.AreEqual (-1095.7017014703874, Financial.Pmt (0.1 / 48, 48, 50000, 0, DueDate.EndOfPeriod), 1E-8);
Assert.AreEqual(-1093.4237353550641, Financial.Pmt(0.1/48, 48, 50000, 0, DueDate.BegOfPeriod), 1E-8);
Assert.AreEqual(-3072.37099816498, Financial.Pmt(0.1/48, 48, 50000, 100000, DueDate.BegOfPeriod), 1E-8);
Assert.AreEqual(-3027.53768194438, Financial.Pmt(0.1/48, 48.7, 50000, 100000, DueDate.BegOfPeriod), 1E-8);
Assert.AreEqual(3182.938437744494, Financial.Pmt(0.1/48, -48, 50000, 100000, DueDate.EndOfPeriod), 1E-8);
Assert.AreEqual(3138.01171878177, Financial.Pmt(0.1/48, -48.7, 50000, 100000, DueDate.EndOfPeriod), 1E-8);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void Pmt_2()
{
// Argument 'NPer' is not a valid value.
Financial.Pmt(0.1/48, 0, 50000, 0, DueDate.EndOfPeriod);
}
#endregion
#region PPmt Tests
[Test]
[ExpectedException(typeof(ArgumentException))]
public void PPmtArgs1()
{
double d = Financial.PPmt (2, -1, 1, 1, 1, DueDate.EndOfPeriod);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void PPmtArgs2()
{
double d = Financial.PPmt (1, 2, 1, 1, 1, DueDate.BegOfPeriod);
}
[Test]
public void PPmt()
{
double d = Financial.PPmt (10, 2, 3, 7, 9, DueDate.BegOfPeriod);
Assert.AreEqual(-0.120300751879702, d, 1E-10, "#PPmt01");
d = Financial.PPmt (10, 4, 4, 7, 4, DueDate.EndOfPeriod);
Assert.AreEqual(-10.0006830600969, d, 1E-10, "#PPmt02");
d = Financial.PPmt (0, 5, 7, 7, 2, DueDate.BegOfPeriod);
Assert.AreEqual(-1.28571428571429, d, 1E-10, "#PPmt03");
d = Financial.PPmt (-5, 5, 7, -7, -2, DueDate.BegOfPeriod);
Assert.AreEqual( -0.175770521818777, d, 1E-10, "#PPmt04");
}
[Test]
public void PPmt_1()
{
Assert.AreEqual(-1066.4547405246804, Financial.PPmt(0.1/48, 36, 48, 50000, 0, DueDate.EndOfPeriod), 1E-8);
Assert.AreEqual(-1040.1509285128539, Financial.PPmt(0.1/48, 24, 48, 50000, 0, DueDate.EndOfPeriod), 1E-8);
Assert.AreEqual(-1093.4237353550643, Financial.PPmt(0.1/48, 48, 48, 50000, 0, DueDate.EndOfPeriod), 1E-8);
Assert.AreEqual(-1064.2375789019673, Financial.PPmt(0.1/48, 36, 48, 50000, 0, DueDate.BegOfPeriod), 1E-8);
Assert.AreEqual(-1037.988452569999, Financial.PPmt(0.1/48, 24, 48, 50000, 0, DueDate.BegOfPeriod), 1E-8);
Assert.AreEqual(-1091.1505051360307, Financial.PPmt(0.1/48, 48, 48, 50000, 0, DueDate.BegOfPeriod), 1E-8);
Assert.AreEqual(-3280.2712060651929, Financial.PPmt(0.1/48, 48, 48, 50000, 100000, DueDate.EndOfPeriod), 1E-8);
Assert.AreEqual(-3273.4515154080918, Financial.PPmt(0.1/48, 48, 48, 50000, 100000, DueDate.BegOfPeriod), 1E-8);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void PPmt_2()
{
// Argument 'Per' is not a valid value.
Financial.PPmt(0.1/48, 56, 48, 50000, 0, DueDate.EndOfPeriod);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void PPmt_3()
{
// Argument 'Per' is not a valid value.
Financial.PPmt(0.1/48, -48, -48, 50000, 0, DueDate.EndOfPeriod);
}
#endregion
#region NPV Tests
[Test]
[ExpectedException(typeof(ArgumentException))]
public void NPVArgs1()
{
double [] arr = null;
double d = Financial.NPV (0.0625, ref arr);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void NPVArgs2()
{
double [] arr = new double [] {-70000, 22000, 25000, 28000, 31000};
double d = Financial.NPV (-1, ref arr);
}
[Test]
public void NPV()
{
double [] arr = new double [] {-70000, 22000, 25000, 28000, 31000};
double d = Financial.NPV (0.0625, ref arr);
Assert.AreEqual(19312.5702095352, d, 0.000001);
}
[Test]
public void NPV_1()
{
double[] values = new double[] {10000, 20000, 30000, 20000, 10000};
Assert.AreEqual(68028.761075684073, Financial.NPV(0.1, ref values), 1E-7);
Assert.AreEqual(42877.457964464716, Financial.NPV(0.3, ref values), 1E-7);
Assert.AreEqual(22007.920515939288, Financial.NPV(0.7, ref values), 1E-7);
Assert.AreEqual(15312.5, Financial.NPV(1, ref values), 1E-7);
Assert.AreEqual(5895.8421600621214, Financial.NPV(2.3, ref values), 1E-7);
Assert.AreEqual(-5203.7070453792549, Financial.NPV(-2.3, ref values), 1E-7);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void NPV_2()
{
//Argument 'Rate' is not a valid value.
double[] values = new double[] {10000, 20000, 30000, 20000, 10000};
Financial.NPV(-1, ref values);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void NPV_3()
{
// Argument 'ValueArray' is Nothing.
double[] values = null;
Financial.NPV(0.1, ref values);
}
#endregion
#region PV Tests
[Test]
public void TestPV()
{
double d = Financial.PV (1, 1, 1, 1, DueDate.BegOfPeriod);
Assert.AreEqual (-1.5, d, "#PV01");
d = Financial.PV (1, 1, 1, 1, DueDate.EndOfPeriod);
Assert.AreEqual (-1, d, "#PV02");
}
[Test]
public void PV_1()
{
Assert.AreEqual(-4563.2857859855494, Financial.PV(0.1/48, 48, 100, 0, DueDate.EndOfPeriod), 1E-8);
Assert.AreEqual(4563.2857859855494, Financial.PV(0.1/48, 48, -100, 0, DueDate.EndOfPeriod), 1E-8);
Assert.AreEqual(3851.0271688809689, Financial.PV(0.45/48, 48, -100, 0, DueDate.EndOfPeriod), 1E-8);
Assert.AreEqual(19255.135844404842, Financial.PV(0.45/48, 48, -500, 0, DueDate.EndOfPeriod), 1E-8);
Assert.AreEqual(4572.7926313730195, Financial.PV(0.1/48, 48, -100, 0, DueDate.BegOfPeriod), 1E-8);
Assert.AreEqual(1848.4911476096459, Financial.PV(0.1/48, 48, -100, 3000, DueDate.EndOfPeriod), 1E-8);
Assert.AreEqual(7278.0804243614521, Financial.PV(0.1/48, 48, -100, -3000, DueDate.EndOfPeriod), 1E-8);
Assert.AreEqual(1857.9979929971164, Financial.PV(0.1/48, 48, -100, 3000, DueDate.BegOfPeriod), 1E-8);
Assert.AreEqual(7287.5872697489231, Financial.PV(0.1/48, 48, -100, -3000, DueDate.BegOfPeriod), 1E-8);
Assert.AreEqual(-5053.7378976476075, Financial.PV(-0.1/48, 48, 100, 0, DueDate.EndOfPeriod), 1E-8);
Assert.AreEqual(-5086.9414579281301, Financial.PV(-0.1/48, 48.3, 100, 0, DueDate.EndOfPeriod), 1E-8);
}
#endregion
}
}
Hope it will help all financial domain develpers..enj...all the best
using System.IO;
using System.Collections;
using Microsoft.VisualBasic;
namespace MonoTests.Microsoft_VisualBasic
{
[TestFixture]
public class FinancialTests
{
public FinancialTests()
{
}
[SetUp]
public void GetReady()
{
}
[TearDown]
public void Clean()
{
}
#region DDB Tests
//[Test]
//[ExpectedException(typeof(ArgumentException))]
//public void DDBArg1()
//{
// // docs doesn`t say it should throw an exception on 'cost' <= 0
// Financial.DDB (-1, 1, 1, 1, 1);
//}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void DDBArg2()
{
Financial.DDB (1, -1, 1, 1, 1);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void DDBArg3()
{
Financial.DDB (1, 1, 0, 1, 1);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void DDBArg4()
{
Financial.DDB (1, 1, 1, 1, 0);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void DDBArg5()
{
// Period has to be <= Life
Financial.DDB (1, 1, 1, 2, 1);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void DDBArg6()
{
// Period has to be > 0
Financial.DDB (1, 1, 1, 0, 1);
}
[Test]
public void DDB()
{
double ddb = Financial.DDB(1000, 50, 10, 5, 3);
Assert.AreEqual(72.03, ddb, 1E-10);
ddb = Financial.DDB (1000, 50, 10, 5, 2);
Assert.AreEqual(81.92, ddb, 1E-10);
ddb = Financial.DDB (1000, 50, 10, 1, 0.1);
Assert.AreEqual(10, ddb, 1E-10);
ddb = Financial.DDB (1000, 50, 10, 0.3, 0.1);
Assert.AreEqual(10, ddb, 1E-10);
}
[Test]
public void DDB_1()
{
Assert.AreEqual(47.999403820109578, Financial.DDB(1500, 120, 24, 12, 2.0), 1E-10);
Assert.AreEqual(479.9940382010958, Financial.DDB(15000, 1000, 24, 12, 2.0), 1E-10);
Assert.AreEqual(391.34749179845591, Financial.DDB(15000, 1000, 48, 12, 2.0), 1E-10);
Assert.AreEqual(33.646996435384537, Financial.DDB(1500, 120, 24, 12, 4.0), 1E-10);
Assert.AreEqual(43.160836714378092, Financial.DDB(1500, 100, 48, 12, 6.0), 1E-10);
Assert.AreEqual(24.789790003786901, Financial.DDB(1500, 100, 48, 12, 1.0), 1E-10);
Assert.AreEqual(383.10767441791506, Financial.DDB(15000, 1000, 48, 12.5, 2.0), 1E-10);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void DDB_2()
{
// Argument 'Factor' is not a valid value.
double d = Financial.DDB(1500, 120, 12, 24, 2.0);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void DDB_3()
{
// Argument 'Factor' is not a valid value.
double d = Financial.DDB(1500, 120, 48, 24, -1);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void DDB_4()
{
// Argument 'Factor' is not a valid value.
double d = Financial.DDB(1500, -2, 48, 24, 2.0);
}
[Test]
//[ExpectedException(typeof(ArgumentException))]
//LAMESPEC: MSDN claims the exception should be thrown in this case
public void DDB_5()
{
// Argument 'Factor' is not a valid value.
double d = Financial.DDB(-5, 120, 48, 24, 2.0);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void DDB_6()
{
// Argument 'Factor' is not a valid value.
double d = Financial.DDB(1500, 120, 48, -24, 2.0);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void DDB_7()
{
// Argument 'Factor' is not a valid value.
double d = Financial.DDB(1500, 120, -2, -5, 2.0);
}
#endregion
#region SLN Tests
[Test]
[ExpectedException(typeof(ArgumentException))]
public void TestSLNArgs()
{
Financial.SLN (0, 0, 0);
}
[Test]
public void SLN()
{
// double d = Financial.SLN (0, 0, 1);
// Assert.AreEqual( 0, d, "#SLN01");
Assert.AreEqual(0.037681159420289857, Financial.SLN (45, 32, 345), 0.00002);
Assert.AreEqual(0.657894736842105, Financial.SLN (-54, -4, -76), 0.00002);
}
[Test]
public void SLN_1()
{
Assert.AreEqual(20.833333333333332, Financial.SLN(1500, 500, 48));
Assert.AreEqual(10.416666666666666, Financial.SLN(1500, 500, 96));
Assert.AreEqual(0, Financial.SLN(500, 500, 96));
Assert.AreEqual(500, Financial.SLN(1500, 500, 2));
Assert.AreEqual(-500, Financial.SLN(1500, 500, -2));
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void SLN_2()
{
//Argument 'Life' cannot be zero.
Financial.SLN(1500, 500, 0);
}
#endregion
#region SYD Tests
[Test]
[ExpectedException(typeof(ArgumentException))]
public void SYDArgs1()
{
Financial.SYD (1, 1, 1, -1);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void SYDArgs2()
{
Financial.SYD (1, -1, 1, 1);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void SYDArgs3()
{
Financial.SYD (1, 1, 1, 2);
}
[Test]
public void SYD()
{
double d = Financial.SYD (23, 34, 26, 21);
Assert.AreEqual( -0.188034188034188, d, 0.0001, "#SYD01");
d = Financial.SYD (0, 1, 1, 1);
Assert.AreEqual( -1, d, 0.00001, "#SYD02");
}
[Test]
public void SYD_1()
{
Assert.AreEqual (44.047619047619044, Financial.SYD (1500, 100, 48, 12), 1E-10);
Assert.AreEqual (1.1904761904761905, Financial.SYD (1500, 100, 48, 48), 1E-10);
Assert.AreEqual(0, Financial.SYD(100, 100, 48, 48));
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void SYD_2()
{
// Argument 'Salvage' must be greater than or equal to zero.
Financial.SYD(1500, -100, 48, 12);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void SYD_3()
{
// Argument 'Period' must be less than or equal to argument 'Life'.
Financial.SYD(1500, 100, 8, 12);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void SYD_4()
{
// Argument 'Period' must be greater than zero.
Financial.SYD(1500, 100, 48, 0);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void SYD_5()
{
// Argument 'Period' must be greater than zero.
Financial.SYD(1500, 100, 48, -2);
}
#endregion
#region FV Tests
[Test]
public void FV()
{
double d = Financial.FV (10, 5, 3, 7, DueDate.BegOfPeriod);
Assert.AreEqual (-1658822, d, "#FV01");
d = Financial.FV (10, 5, 3, 7, DueDate.EndOfPeriod);
Assert.AreEqual (-1175672, d, "#FV02");
d = Financial.FV (0, 5, 3, 7, DueDate.BegOfPeriod);
Assert.AreEqual (-22, d, "#FV03");
d = Financial.FV(0, 1, 1, 1, DueDate.BegOfPeriod);
Assert.AreEqual (-2, d, "#FV04");
d = Financial.FV (0, 0, 0, 0, DueDate.BegOfPeriod);
Assert.AreEqual (0, d, "#FV05");
d = Financial.FV (-3, -5, -6, -4, DueDate.BegOfPeriod);
Assert.AreEqual (-4.25, d, "#FV06");
}
[Test]
public void FV_1()
{
Assert.AreEqual(-5042.6861628644065, Financial.FV (0.1 / 48, 48, 100, 0, DueDate.EndOfPeriod), 1E-8);
Assert.AreEqual(5042.6861628644065, Financial.FV(0.1/48, 48, -100, 0, DueDate.EndOfPeriod), 1E-8);
Assert.AreEqual(6026.9653563801103, Financial.FV(0.45/48, 48, -100, 0, DueDate.EndOfPeriod), 1E-8);
Assert.AreEqual(30134.826781900552, Financial.FV(0.45/48, 48, -500, 0, DueDate.EndOfPeriod), 1E-8);
Assert.AreEqual(5053.1917590370413, Financial.FV(0.1/48, 48, -100, 0, DueDate.BegOfPeriod), 1E-8);
Assert.AreEqual(1727.5182776853812, Financial.FV(0.1/48, 48, -100, 3000, DueDate.EndOfPeriod), 1E-8);
Assert.AreEqual(8357.8540480434312, Financial.FV(0.1/48, 48, -100, -3000, DueDate.EndOfPeriod), 1E-8);
Assert.AreEqual(1738.023873858016, Financial.FV(0.1/48, 48, -100, 3000, DueDate.BegOfPeriod), 1E-8);
Assert.AreEqual(8368.359644216067, Financial.FV(0.1/48, 48, -100, -3000, DueDate.BegOfPeriod), 1E-8);
Assert.AreEqual(-4572.3341785092407, Financial.FV(-0.1/48, 48, 100, 0, DueDate.EndOfPeriod), 1E-8);
Assert.AreEqual(-4599.4962842992118, Financial.FV(-0.1/48, 48.3, 100, 0, DueDate.EndOfPeriod), 1E-8);
}
#endregion
#region Rate Tests
[Category ("NotWorking")]//Not Implemented
[Test]
[ExpectedException(typeof(ArgumentException))]
public void RateArgs1()
{
double d = Financial.Rate (-1, 1, 1, 1, DueDate.BegOfPeriod, 1);
}
[Category ("NotWorking")]//Not Implemented
[Test]
public void Rate()
{
Assert.AreEqual(-1.5000000000001, Financial.Rate (1, 1, 1, 1, DueDate.BegOfPeriod, 0.1), 0.1);
Assert.AreEqual(-1.5000000000001, Financial.Rate (1, -1, -1, -1, DueDate.BegOfPeriod, 0.1), 0.1);
Assert.AreEqual(-1.71428571428571, Financial.Rate (1, 2, 12, 10, DueDate.BegOfPeriod, 0.5), 0.1);
}
[Category ("NotWorking")]//Not Implemented
[Test]
public void Rate_1()
{
Assert.AreEqual(-0.067958335561249847, Financial.Rate(48, -120, 50000, 0, DueDate.EndOfPeriod, 0.1));
Assert.AreEqual(-0.054284323350630818, Financial.Rate(48, -200, 50000, 0, DueDate.EndOfPeriod, 0.1));
Assert.AreEqual(-0.03391640485393424, Financial.Rate(48, -400, 50000, 0, DueDate.EndOfPeriod, 0.1));
Assert.AreEqual(0.19996831303445506, Financial.Rate(48, -1000, 5000, 0, DueDate.EndOfPeriod, 0.1));
Assert.AreEqual(-0.99999999998846933, Financial.Rate(48, -1000, 5000, 0, DueDate.BegOfPeriod, 0.1));
Assert.AreEqual(-0.055871364867281934, Financial.Rate(48, -200, 50000, 0, DueDate.BegOfPeriod, 0.1));
Assert.AreEqual(-0.065503055347169575, Financial.Rate(48, -200, 50000, 1000, DueDate.EndOfPeriod, 0.1));
Assert.AreEqual(-0.058920469572311909, Financial.Rate(48, -200, 50000, 500, DueDate.EndOfPeriod, 0.1));
}
[Category ("NotWorking")]//Not Implemented
[Test]
public void Rate_2()
{
Assert.AreEqual(-0.067958335561434935, Financial.Rate(48, -120, 50000, 0, DueDate.EndOfPeriod, 0.3));
Assert.AreEqual(-0.054284323350996831, Financial.Rate(48, -200, 50000, 0, DueDate.EndOfPeriod, 0.3));
Assert.AreEqual(-0.033916404853936467, Financial.Rate(48, -400, 50000, 0, DueDate.EndOfPeriod, 0.3));
Assert.AreEqual(0.19996831303445506, Financial.Rate(48, -1000, 5000, 0, DueDate.EndOfPeriod, 0.2));
Assert.AreEqual(-0.99999999999999079, Financial.Rate(48, -1000, 5000, 0, DueDate.BegOfPeriod, 0.3));
Assert.AreEqual(-0.055871364867277139, Financial.Rate(48, -200, 50000, 0, DueDate.BegOfPeriod, 0.3));
Assert.AreEqual(-0.065503055348340639, Financial.Rate(48, -200, 50000, 1000, DueDate.EndOfPeriod, 0.3));
Assert.AreEqual(-0.058920469572100169, Financial.Rate(48, -200, 50000, 500, DueDate.EndOfPeriod, 0.3));
}
[Category ("NotWorking")]//Not Implemented
[Test]
[ExpectedException(typeof(ArgumentException))]
public void Rate_3()
{
// Argument 'NPer' must be greater than zero.
Financial.Rate(0, -120, 50000, 0, DueDate.EndOfPeriod, 0.1);
}
[Category ("NotWorking")]//Not Implemented
[Test]
[ExpectedException(typeof(ArgumentException))]
public void Rate_4()
{
// Argument 'NPer' must be greater than zero.
Financial.Rate(-10, -120, 50000, 0, DueDate.EndOfPeriod, 0.1);
}
[Category ("NotWorking")]//Not Implemented
[Test]
[ExpectedException(typeof(ArgumentException))]
public void Rate_5()
{
// Cannot calculate rate using the arguments provided.
Financial.Rate(48, -1000, 5000, 0, DueDate.EndOfPeriod, 0.3);
}
#endregion
#region IRR Tests
[Category ("NotWorking")]//Not Implemented
[Test]
[ExpectedException(typeof(ArgumentException))]
public void IRRArgs1()
{
double [] arr = new double [0];
Financial.IRR (ref arr, 0.1);
}
[Category ("NotWorking")]//Not Implemented
[Test]
[ExpectedException(typeof(ArgumentException))]
public void IRRArgs2()
{
double [] arr = new double [] {134};
Financial.IRR (ref arr, 0.1);
}
// [Test]
// [ExpectedException(typeof(ArgumentException))]
// public void IRRArgs3()
// {
// // -0.99 as Guess throws an exception on MS.NET, -0.98 doesn't
// //double [] arr = new double [] {-70000, 22000, 25000, 28000, 31000};
// //double d = Financial.IRR (ref arr, -0.99);
// }
[Category ("NotWorking")]//Not Implemented
[Test]
public void IRR()
{
double [] arr = new double [] {-70000, 22000, 25000, 28000, 31000};
double d = Financial.IRR (ref arr, 0.1);
Assert.AreEqual ( 0.177435884422527, d, 0.00001);
}
[Category ("NotWorking")]//Not Implemented
[Test]
public void IRR_1 ()
{
double [] values = new double [] { -50000, 20000, 20000, 20000, 10000 };
Assert.AreEqual (0.16479098450887533, Financial.IRR (ref values, 0.1));
Assert.AreEqual (0.16479098450893837, Financial.IRR (ref values, 0.3));
Assert.AreEqual (0.16479098450893415, Financial.IRR (ref values, 0.5));
values = new double [] { -100000, 40000, 35000, 30000, 25000 };
Assert.AreEqual (0.12441449540624081, Financial.IRR (ref values, 0.1));
Assert.AreEqual (0.12441449541502105, Financial.IRR (ref values, 0.3));
Assert.AreEqual (0.12441449541025705, Financial.IRR (ref values, 0.5));
}
[Category ("NotWorking")]//Not Implemented
[Test]
[ExpectedException(typeof(ArgumentException))]
public void IRR_2()
{
//Arguments are not valid.
double[] values = new double[] {-500000, 20, 20, 20, 10000};
Financial.IRR(ref values, 10000);
}
[Category ("NotWorking")]//Not Implemented
[Test]
[ExpectedException(typeof(ArgumentException))]
public void IRR_3()
{
//Arguments are not valid.
double[] values = new double[] {100, 20, 30, 30, 30};
Financial.IRR(ref values, 0.1);
}
#endregion
#region MIRR Tests
[Test]
[ExpectedException(typeof(ArgumentException))]
public void MIRRArgs1()
{
double [] arr = new double [] {-70000, 22000, 25000, 28000, 31000};
double d = Financial.MIRR(ref arr, -1, 1);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void MIRRArgs2()
{
double [] arr = new double [] {-70000, 22000, 25000, 28000, 31000};
double d = Financial.MIRR(ref arr, 1, -1);
}
[Test]
public void MIRR()
{
double [] arr = new double [] {-70000, 22000, 25000, 28000, 31000};
double d = Financial.MIRR (ref arr, 1, 1);
Assert.AreEqual(0.509044845533018, d, 0.00001, "#MIRR01");
arr = new double [] {-70000, 22000, 25000, 28000, 31000};
d = Financial.MIRR (ref arr, 5, 5);
Assert.AreEqual(2.02366041666348, d, 0.00001, "#MIRR02");
}
[Test]
public void MIRR_1()
{
double[] values = new double[] {-50000, 20000, 20000, 20000, 10000};
Assert.AreEqual(0.14382317535283296, Financial.MIRR(ref values, 0.1, 0.12), 1E-10);
Assert.AreEqual(0.32152371134887248, Financial.MIRR(ref values, 0.3, 0.5), 1E-10);
Assert.AreEqual(0.41431961645993387, Financial.MIRR(ref values, 0.5, 0.7), 1E-10);
values = new double[] {-100000, 40000, 35000, 30000, 25000};
Assert.AreEqual(0.12239312521886214, Financial.MIRR(ref values, 0.1, 0.12), 1E-10);
Assert.AreEqual(0.29787828889780776, Financial.MIRR(ref values, 0.3, 0.5), 1E-10);
Assert.AreEqual(0.39034333083777972, Financial.MIRR(ref values, 0.5, 0.7), 1E-10);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void MIRR_2()
{
// Argument 'FinanceRate' is not a valid value.
double[] values = new double[] {-50000, 20000, 20000, 20000, 10000};
Financial.MIRR(ref values, -1, 0.12);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void MIRR_3()
{
// Argument 'ReinvestRate' is not a valid value.
double[] values = new double[] {-50000, 20000, 20000, 20000, 10000};
Financial.MIRR(ref values, 0.1, -1);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void MIRR_4()
{
// Argument 'ReinvestRate' is not a valid value.
double[] values = new double[] {-50000, 20000, 20000, 20000, 10000};
Financial.MIRR(ref values, 0.1, -3);
}
[Test]
[ExpectedException(typeof(System.NullReferenceException))]
public void MIRR_5()
{
double[] values = null;
Financial.MIRR(ref values, 0.1, 0.12);
}
[Category ("NotWorking")]
[Category ("TargetJvmNotWorking")]
[Test]
[ExpectedException(typeof(DivideByZeroException))]
public void MIRR_6()
{
double[] values = new double[] {100, 20, 30, 30, 30};
Financial.MIRR(ref values, 0.1, 0.1);
}
#endregion
#region NPer Tests
[Test]
[ExpectedException(typeof(ArgumentException))]
public void NPerArgs1()
{
double d = Financial.NPer (-1, 2, 2, 2, DueDate.BegOfPeriod);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void NPerArgs2()
{
double d = Financial.NPer (0, 0, 2, 2, DueDate.BegOfPeriod);
}
[Test]
public void NPer()
{
double d = Financial.NPer (3, 4, 6, 2, DueDate.BegOfPeriod);
Assert.AreEqual(-0.882767373181489, d, 0.0000001, "#NPer01");
d = Financial.NPer (1, -4, -6, -2, DueDate.EndOfPeriod);
Assert.AreEqual(-2.32192809488736, d, 0.0000001, "#NPer02");
}
[Test]
public void NPer_1()
{
Assert.AreEqual(-47.613161535165531, (Financial.NPer(0.1/48, 200, 10000, 0, DueDate.EndOfPeriod)), 0.00000001);
Assert.AreEqual(-47.518910769564712, Financial.NPer(0.1/48, 200, 10000, 0, DueDate.BegOfPeriod), 0.00000001);
Assert.AreEqual(-401.12014892843246, Financial.NPer(0.1/48, 200, 10000, 50000, DueDate.EndOfPeriod), 0.0000001);
Assert.AreEqual(-399.9412969471162, Financial.NPer(0.1/48, 200, 10000, 50000, DueDate.BegOfPeriod), 0.0000001);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void NPer_2()
{
// Argument 'Rate' is not a valid value.
Financial.NPer(-1, 200, 10000, 0, DueDate.EndOfPeriod);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void NPer_3()
{
// Argument 'Pmt' is not a valid value.
Financial.NPer(0, 0, 10000, 0, DueDate.EndOfPeriod);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void NPer_4()
{
// Cannot calculate number of periods using the arguments provided.
Financial.NPer(0.1/48, 0, 10000, 0, DueDate.EndOfPeriod);
}
#endregion
#region IPmt Tests
[Test]
[ExpectedException(typeof(ArgumentException))]
public void IPmtArgs1()
{
Financial.IPmt (3, 6, 4, 2, 2, DueDate.BegOfPeriod);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void IPmtArgs2()
{
Financial.IPmt (3, 0, 4, 2, 2, DueDate.BegOfPeriod);
}
[Test]
public void IPmt()
{
double d = Financial.IPmt (10, 2, 3, 7, 9, DueDate.BegOfPeriod);
Assert.AreEqual ( -6.25427204374573, d, 1E-10, "#IPmt01");
d = Financial.IPmt (10, 4, 4, 7, 4, DueDate.EndOfPeriod);
Assert.AreEqual ( -60.0068306011053, d, 1E-10 , "#IPmt02");
d = Financial.IPmt (0, 5, 7, 7, 2, DueDate.BegOfPeriod);
Assert.AreEqual( 0, d, "#IPmt03");
d = Financial.IPmt (1000, 1, 7, 7, 2, DueDate.BegOfPeriod);
Assert.AreEqual( 0, d, "#IPmt03");
d = Financial.IPmt (-5, 5, 7, -7, -2, DueDate.BegOfPeriod);
Assert.AreEqual(8.92508391821792, d, 1E-10, "#IPmt04");
}
[Test]
public void IPmt_1()
{
Assert.AreEqual(-29.246960945707116, Financial.IPmt(0.1/48, 36, 48, 50000, 0, DueDate.EndOfPeriod), 1E-10);
Assert.AreEqual(-55.550772957533624, Financial.IPmt(0.1/48, 24, 48, 50000, 0, DueDate.EndOfPeriod), 1E-10);
Assert.AreEqual(-54.4678461379274, Financial.IPmt(0.1/48, 24.5, 48, 50000, 0, DueDate.EndOfPeriod), 1E-10);
Assert.AreEqual(-2.2779661153231245, Financial.IPmt(0.1/48, 48, 48, 50000, 0, DueDate.EndOfPeriod), 1E-10);
Assert.AreEqual(42.6652760279442, Financial.IPmt(0.1/48, 24.3, 48.3, 50000, 100000, DueDate.EndOfPeriod), 1E-9);
Assert.AreEqual(-29.186156453096753, Financial.IPmt(0.1/48, 36, 48, 50000, 0, DueDate.BegOfPeriod), 1E-10);
Assert.AreEqual(-55.435282785064992, Financial.IPmt(0.1/48, 24, 48, 50000, 0, DueDate.BegOfPeriod), 1E-10);
Assert.AreEqual(-54.3546073725681, Financial.IPmt(0.1/48, 24.5, 48, 50000, 0, DueDate.BegOfPeriod), 1E-10);
Assert.AreEqual(-2.2732302190335001, Financial.IPmt(0.1/48, 48, 48, 50000, 0, DueDate.BegOfPeriod), 1E-10);
Assert.AreEqual(201.49943498736394, Financial.IPmt(0.1/48, 48, 48, 50000, 100000, DueDate.EndOfPeriod), 1E-9);
Assert.AreEqual(201.08051724310744, Financial.IPmt(0.1/48, 48, 48, 50000, 100000, DueDate.BegOfPeriod), 1E-9);
Assert.AreEqual(42.5765748303808, Financial.IPmt(0.1/48, 24.3, 48.3, 50000, 100000, DueDate.BegOfPeriod), 1E-9);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void IPmt_2()
{
// Argument 'Per' is not a valid value.
Financial.IPmt(0.1/48, 56, 48, 50000, 0, DueDate.EndOfPeriod);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void IPmt_3()
{
// Argument 'Per' is not a valid value.
Financial.IPmt(0.1/48, -48, -48, 50000, 0, DueDate.EndOfPeriod);
}
#endregion
#region Pmt Tests
[Test]
[ExpectedException(typeof(ArgumentException))]
public void PmtArgs()
{
Financial.Pmt (1, 0, 1, 1, DueDate.BegOfPeriod);
}
[Test]
public void Pmt()
{
double d = Financial.Pmt (2, 5, 2, 3, DueDate.BegOfPeriod);
Assert.AreEqual (-1.3471074380165289, d, 1E-10, "#Pmt01");
d = Financial.Pmt (2, 5, 2, 3, DueDate.EndOfPeriod);
Assert.AreEqual (-4.0413223140495864, d, 1E-10, "#Pmt02");
d = Financial.Pmt (-3, -5, -3, -4, DueDate.BegOfPeriod);
Assert.AreEqual (-5.6818181818181817, d, 1E-10, "#Pmt03");
d = Financial.Pmt (-3, -5, -3, -4, DueDate.EndOfPeriod);
Assert.AreEqual (11.363636363636363, d, 1E-10, "#Pmt04");
d = Financial.Pmt (0, 1, 0, 0, DueDate.BegOfPeriod);
Assert.AreEqual ( 0, d, 1E-10, "#Pmt05");
d = Financial.Pmt (0, 1, 0, 0, DueDate.EndOfPeriod);
Assert.AreEqual ( 0, d, 1E-10, "#Pmt06");
}
[Test]
public void Pmt_1()
{
Assert.AreEqual (-1095.7017014703874, Financial.Pmt (0.1 / 48, 48, 50000, 0, DueDate.EndOfPeriod), 1E-8);
Assert.AreEqual(-1093.4237353550641, Financial.Pmt(0.1/48, 48, 50000, 0, DueDate.BegOfPeriod), 1E-8);
Assert.AreEqual(-3072.37099816498, Financial.Pmt(0.1/48, 48, 50000, 100000, DueDate.BegOfPeriod), 1E-8);
Assert.AreEqual(-3027.53768194438, Financial.Pmt(0.1/48, 48.7, 50000, 100000, DueDate.BegOfPeriod), 1E-8);
Assert.AreEqual(3182.938437744494, Financial.Pmt(0.1/48, -48, 50000, 100000, DueDate.EndOfPeriod), 1E-8);
Assert.AreEqual(3138.01171878177, Financial.Pmt(0.1/48, -48.7, 50000, 100000, DueDate.EndOfPeriod), 1E-8);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void Pmt_2()
{
// Argument 'NPer' is not a valid value.
Financial.Pmt(0.1/48, 0, 50000, 0, DueDate.EndOfPeriod);
}
#endregion
#region PPmt Tests
[Test]
[ExpectedException(typeof(ArgumentException))]
public void PPmtArgs1()
{
double d = Financial.PPmt (2, -1, 1, 1, 1, DueDate.EndOfPeriod);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void PPmtArgs2()
{
double d = Financial.PPmt (1, 2, 1, 1, 1, DueDate.BegOfPeriod);
}
[Test]
public void PPmt()
{
double d = Financial.PPmt (10, 2, 3, 7, 9, DueDate.BegOfPeriod);
Assert.AreEqual(-0.120300751879702, d, 1E-10, "#PPmt01");
d = Financial.PPmt (10, 4, 4, 7, 4, DueDate.EndOfPeriod);
Assert.AreEqual(-10.0006830600969, d, 1E-10, "#PPmt02");
d = Financial.PPmt (0, 5, 7, 7, 2, DueDate.BegOfPeriod);
Assert.AreEqual(-1.28571428571429, d, 1E-10, "#PPmt03");
d = Financial.PPmt (-5, 5, 7, -7, -2, DueDate.BegOfPeriod);
Assert.AreEqual( -0.175770521818777, d, 1E-10, "#PPmt04");
}
[Test]
public void PPmt_1()
{
Assert.AreEqual(-1066.4547405246804, Financial.PPmt(0.1/48, 36, 48, 50000, 0, DueDate.EndOfPeriod), 1E-8);
Assert.AreEqual(-1040.1509285128539, Financial.PPmt(0.1/48, 24, 48, 50000, 0, DueDate.EndOfPeriod), 1E-8);
Assert.AreEqual(-1093.4237353550643, Financial.PPmt(0.1/48, 48, 48, 50000, 0, DueDate.EndOfPeriod), 1E-8);
Assert.AreEqual(-1064.2375789019673, Financial.PPmt(0.1/48, 36, 48, 50000, 0, DueDate.BegOfPeriod), 1E-8);
Assert.AreEqual(-1037.988452569999, Financial.PPmt(0.1/48, 24, 48, 50000, 0, DueDate.BegOfPeriod), 1E-8);
Assert.AreEqual(-1091.1505051360307, Financial.PPmt(0.1/48, 48, 48, 50000, 0, DueDate.BegOfPeriod), 1E-8);
Assert.AreEqual(-3280.2712060651929, Financial.PPmt(0.1/48, 48, 48, 50000, 100000, DueDate.EndOfPeriod), 1E-8);
Assert.AreEqual(-3273.4515154080918, Financial.PPmt(0.1/48, 48, 48, 50000, 100000, DueDate.BegOfPeriod), 1E-8);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void PPmt_2()
{
// Argument 'Per' is not a valid value.
Financial.PPmt(0.1/48, 56, 48, 50000, 0, DueDate.EndOfPeriod);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void PPmt_3()
{
// Argument 'Per' is not a valid value.
Financial.PPmt(0.1/48, -48, -48, 50000, 0, DueDate.EndOfPeriod);
}
#endregion
#region NPV Tests
[Test]
[ExpectedException(typeof(ArgumentException))]
public void NPVArgs1()
{
double [] arr = null;
double d = Financial.NPV (0.0625, ref arr);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void NPVArgs2()
{
double [] arr = new double [] {-70000, 22000, 25000, 28000, 31000};
double d = Financial.NPV (-1, ref arr);
}
[Test]
public void NPV()
{
double [] arr = new double [] {-70000, 22000, 25000, 28000, 31000};
double d = Financial.NPV (0.0625, ref arr);
Assert.AreEqual(19312.5702095352, d, 0.000001);
}
[Test]
public void NPV_1()
{
double[] values = new double[] {10000, 20000, 30000, 20000, 10000};
Assert.AreEqual(68028.761075684073, Financial.NPV(0.1, ref values), 1E-7);
Assert.AreEqual(42877.457964464716, Financial.NPV(0.3, ref values), 1E-7);
Assert.AreEqual(22007.920515939288, Financial.NPV(0.7, ref values), 1E-7);
Assert.AreEqual(15312.5, Financial.NPV(1, ref values), 1E-7);
Assert.AreEqual(5895.8421600621214, Financial.NPV(2.3, ref values), 1E-7);
Assert.AreEqual(-5203.7070453792549, Financial.NPV(-2.3, ref values), 1E-7);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void NPV_2()
{
//Argument 'Rate' is not a valid value.
double[] values = new double[] {10000, 20000, 30000, 20000, 10000};
Financial.NPV(-1, ref values);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void NPV_3()
{
// Argument 'ValueArray' is Nothing.
double[] values = null;
Financial.NPV(0.1, ref values);
}
#endregion
#region PV Tests
[Test]
public void TestPV()
{
double d = Financial.PV (1, 1, 1, 1, DueDate.BegOfPeriod);
Assert.AreEqual (-1.5, d, "#PV01");
d = Financial.PV (1, 1, 1, 1, DueDate.EndOfPeriod);
Assert.AreEqual (-1, d, "#PV02");
}
[Test]
public void PV_1()
{
Assert.AreEqual(-4563.2857859855494, Financial.PV(0.1/48, 48, 100, 0, DueDate.EndOfPeriod), 1E-8);
Assert.AreEqual(4563.2857859855494, Financial.PV(0.1/48, 48, -100, 0, DueDate.EndOfPeriod), 1E-8);
Assert.AreEqual(3851.0271688809689, Financial.PV(0.45/48, 48, -100, 0, DueDate.EndOfPeriod), 1E-8);
Assert.AreEqual(19255.135844404842, Financial.PV(0.45/48, 48, -500, 0, DueDate.EndOfPeriod), 1E-8);
Assert.AreEqual(4572.7926313730195, Financial.PV(0.1/48, 48, -100, 0, DueDate.BegOfPeriod), 1E-8);
Assert.AreEqual(1848.4911476096459, Financial.PV(0.1/48, 48, -100, 3000, DueDate.EndOfPeriod), 1E-8);
Assert.AreEqual(7278.0804243614521, Financial.PV(0.1/48, 48, -100, -3000, DueDate.EndOfPeriod), 1E-8);
Assert.AreEqual(1857.9979929971164, Financial.PV(0.1/48, 48, -100, 3000, DueDate.BegOfPeriod), 1E-8);
Assert.AreEqual(7287.5872697489231, Financial.PV(0.1/48, 48, -100, -3000, DueDate.BegOfPeriod), 1E-8);
Assert.AreEqual(-5053.7378976476075, Financial.PV(-0.1/48, 48, 100, 0, DueDate.EndOfPeriod), 1E-8);
Assert.AreEqual(-5086.9414579281301, Financial.PV(-0.1/48, 48.3, 100, 0, DueDate.EndOfPeriod), 1E-8);
}
#endregion
}
}
Hope it will help all financial domain develpers..enj...all the best
Subscribe to:
Posts (Atom)