90 lines
3.4 KiB
C#
90 lines
3.4 KiB
C#
using Qdp.Pricing.Base.Enums;
|
|
|
|
namespace YLErp.Modules.CalcModules
|
|
{
|
|
/// <summary>
|
|
/// SpreadOptionInfoTest 的摘要说明
|
|
/// </summary>
|
|
[TestClass]
|
|
public class SpreadOptionPayoffTest
|
|
{
|
|
#region 附加测试特性
|
|
//
|
|
// 编写测试时,可以使用以下附加特性:
|
|
//
|
|
// 在运行类中的第一个测试之前使用 ClassInitialize 运行代码
|
|
// [ClassInitialize()]
|
|
// public static void MyClassInitialize(TestContext testContext) { }
|
|
//
|
|
// 在类中的所有测试都已运行之后使用 ClassCleanup 运行代码
|
|
// [ClassCleanup()]
|
|
// public static void MyClassCleanup() { }
|
|
//
|
|
// 在运行每个测试之前,使用 TestInitialize 来运行代码
|
|
// [TestInitialize()]
|
|
// public void MyTestInitialize() { }
|
|
//
|
|
// 在每个测试运行完之后,使用 TestCleanup 来运行代码
|
|
// [TestCleanup()]
|
|
// public void MyTestCleanup() { }
|
|
//
|
|
#endregion
|
|
|
|
[TestMethod]
|
|
public void TestParse()
|
|
{
|
|
var spreadInfo = new SpreadOptionPayoff("S1+1.5S2-S3");
|
|
|
|
Assert.AreEqual(SpreadType.ThreeAssetsSpreadBasket, spreadInfo.SpreadType);
|
|
Assert.IsTrue(Enumerable.SequenceEqual(new double[] { 1.0, 1.5, 1.0 }, spreadInfo.Weights));
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TestTwoAssets()
|
|
{
|
|
var spreadInfo = new SpreadOptionPayoff("S1-S2");
|
|
|
|
Assert.AreEqual(SpreadType.TwoAssetsSpread, spreadInfo.SpreadType);
|
|
Assert.IsTrue(Enumerable.SequenceEqual(new double[] { 1.0, 1.0 }, spreadInfo.Weights));
|
|
|
|
var spreadInfo1 = new SpreadOptionPayoff("1.5S1-2S2");
|
|
|
|
Assert.AreEqual(SpreadType.TwoAssetsSpread, spreadInfo1.SpreadType);
|
|
Assert.IsTrue(Enumerable.SequenceEqual(new double[] { 1.5, 2.0 }, spreadInfo1.Weights));
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TestThreeAssets()
|
|
{
|
|
var spreadInfo = new SpreadOptionPayoff("2S1-S2-S3");
|
|
|
|
Assert.AreEqual(SpreadType.ThreeAssetsSpread, spreadInfo.SpreadType);
|
|
Assert.IsTrue(Enumerable.SequenceEqual(new double[] { 2.0, 1.0, 1.0 }, spreadInfo.Weights));
|
|
|
|
var spreadInfo1 = new SpreadOptionPayoff("S1+0.5S2-1.1S3");
|
|
Assert.AreEqual(SpreadType.ThreeAssetsSpreadBasket, spreadInfo1.SpreadType);
|
|
Assert.IsTrue(Enumerable.SequenceEqual(new double[] { 1.0, 0.5, 1.1 }, spreadInfo1.Weights));
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TestFourAssets()
|
|
{
|
|
var spreadInfo = new SpreadOptionPayoff("1.1S1-0.8S2-0.7S3-S4");
|
|
|
|
Assert.AreEqual(SpreadType.FourAssetsSpread, spreadInfo.SpreadType);
|
|
Assert.IsTrue(Enumerable.SequenceEqual(new double[] { 1.1, 0.8, 0.7, 1.0 }, spreadInfo.Weights));
|
|
|
|
var spreadInfo1 = new SpreadOptionPayoff("S1+0.5S2-1.1S3-2S4");
|
|
|
|
Assert.AreEqual(SpreadType.FourAssetsSpreadBasketType1, spreadInfo1.SpreadType);
|
|
Assert.IsTrue(Enumerable.SequenceEqual(new double[] { 1.0, 0.5, 1.1, 2.0 }, spreadInfo1.Weights));
|
|
|
|
var spreadInfo2 = new SpreadOptionPayoff("1.1S1+0.5S2+0.9S3-2.2S4");
|
|
|
|
Assert.AreEqual(SpreadType.FourAssetsSpreadBasketType2, spreadInfo2.SpreadType);
|
|
Assert.IsTrue(Enumerable.SequenceEqual(new double[] { 1.1, 0.5, 0.9, 2.2 }, spreadInfo2.Weights));
|
|
}
|
|
|
|
}
|
|
}
|