Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/amaggiulli/qlnet
Browse files Browse the repository at this point in the history
  • Loading branch information
amaggiulli committed Nov 11, 2015
2 parents 667085d + 663c2ea commit 84fafd7
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 40 deletions.
8 changes: 4 additions & 4 deletions QLNet/Cashflows/Cashflowvectors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,17 @@ public static List<CashFlow> FloatingLeg<InterestRateIndexType, FloatingCouponTy
} else {
if (Utils.noOption(caps, floors, i)) {
leg.Add(new FloatingCouponType().factory(Utils.Get(nominals, i),
paymentDate, start, end,
Utils.Get(fixingDays, i, 2),
paymentDate, start, end,
Utils.Get( fixingDays, i, index.fixingDays() ),
index,
Utils.Get(gearings, i, 1),
Utils.Get(spreads, i),
refStart, refEnd, paymentDayCounter,
isInArrears));
} else {
leg.Add(new CappedFlooredCouponType().factory(Utils.Get(nominals, i),
paymentDate, start, end,
Utils.Get(fixingDays, i, 2),
paymentDate, start, end,
Utils.Get( fixingDays, i, index.fixingDays() ),
index,
Utils.Get(gearings, i, 1),
Utils.Get(spreads, i),
Expand Down
21 changes: 7 additions & 14 deletions QLNet/Math/PrimeNumbers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,17 @@ private PrimeNumbers() { }
public static ulong get(int absoluteIndex)
{
if (primeNumbers_.empty())
{
//int n = sizeof(firstPrimes)/sizeof(firstPrimes[0]);
int n = 8*sizeof(ulong)/sizeof(ulong);
//primeNumbers_.insert(primeNumbers_.end(),firstPrimes, firstPrimes+n);
//IEnumerable<ulong> colection=firstPrimes..ForEach((i, x) => i <n));
primeNumbers_.AddRange( firstPrimes.ToList<ulong>().GetRange(0,n));
}
while (primeNumbers_.Count<=absoluteIndex)
primeNumbers_.AddRange(firstPrimes);

while (primeNumbers_.Count<=absoluteIndex)
nextPrimeNumber();
return primeNumbers_[absoluteIndex];

return primeNumbers_[absoluteIndex];
}

private static ulong nextPrimeNumber()
{
//ulong p, n, m = primeNumbers_.back();
ulong p, n, m = primeNumbers_.First();
ulong p, n, m = primeNumbers_.Last();
do {
// skip the even numbers
m += 2;
Expand All @@ -80,12 +75,10 @@ private static ulong nextPrimeNumber()
p = primeNumbers_[i];
++i;
}
while ((m % p==1) && p <= n);//while ( m%p && p<=n );
while ((m % p != 0) && p <= n);
} while ( p<=n );
primeNumbers_.Add(m);
return m;
}

}

}
10 changes: 5 additions & 5 deletions QLNet/QLNet.nuspec
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?xml version="1.0"?>
<package >
<metadata>
<id>$id$</id>
<id>QLNet</id>
<version>$version$</version>
<title>$title$</title>
<title>QLNet</title>
<authors>Andrea Maggiulli</authors>
<owners>Andrea Maggiulli</owners>
<licenseUrl>http://qlnet.sourceforge.net/License.html</licenseUrl>
<projectUrl>http://github.com/amaggiulli/qlnet</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>A free/open-source library for quantitative finance</description>
<releaseNotes>Initial release to NuGet for version 1.2.0.0</releaseNotes>
<copyright>Copyright (c) 2008-2013 Andrea Maggiulli (a.maggiulli@gmail.com)</copyright>
<releaseNotes>Version $version$</releaseNotes>
<copyright>Copyright (c) 2008-2014 Andrea Maggiulli (a.maggiulli@gmail.com)</copyright>
<tags>QLNet QuantLib quantitative finance financial</tags>
</metadata>
</package>
</package>
2 changes: 1 addition & 1 deletion QLNet/Termstructures/Yield/ZeroCurve.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ private void initialize(Compounding compounding, Frequency frequency)
InterestRate r = new InterestRate(data_[0], dayCounter(), compounding, frequency);
data_[0] = r.equivalentRate(Compounding.Continuous, Frequency.NoFrequency, dt).value();
#if !QL_NEGATIVE_RATES
Utils.QL_REQUIRE(data_[0] > 0.0, "non-positive yield");
Utils.QL_REQUIRE( data_[0] > 0.0, () => "non-positive yield" );
#endif
}

Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ QLNet is a financial library written in c# for the Windows enviroment derived pr
which has been used as a base reference for modelling of various financial instruments.
QLNet contains also new developments on the bond market like MBS , Amortized Cost, PSA Curve and others.

[![Build status](https://ci.appveyor.com/api/projects/status/iii1m7n3cdq3v5xm?svg=true)](https://ci.appveyor.com/project/amaggiulli/qlnet)
[![Release](https://img.shields.io/github/release/amaggiulli/qlnet.svg)](https://github.com/amaggiulli/qlnet/releases/latest)
[![NuGet](https://img.shields.io/nuget/dt/qlnet.svg)](http://nuget.org/packages/qlnet)
[![Stars](https://img.shields.io/github/stars/amaggiulli/qlnet.svg)](https://github.com/amaggiulli/qlnet/stargazers)

How source code is organized
=====
We have recently changed the policy for commit changes .
Expand Down
1 change: 0 additions & 1 deletion Test/T_DividendOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,6 @@ public void testEuropeanValues()
// Reference pg. 253 - Hull - Options, Futures, and Other Derivatives 5th ed
// Exercise 12.8
// Doesn't quite work. Need to deal with date conventions
[TestMethod()]
void testEuropeanKnownValue()
{

Expand Down
16 changes: 8 additions & 8 deletions Test/T_LiborMarketModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ OptionletVolatilityStructure makeCapVolCurve(Date todaysDate)

return new CapletVarianceCurve(todaysDate, dates,
capletVols,new Actual360());
}
[TestMethod()]
}

[TestCategory( "LongRun" ), TestMethod()]
public void testSimpleCovarianceModels()
{
//"Testing simple covariance models...";
Expand Down Expand Up @@ -153,9 +153,9 @@ public void testSimpleCovarianceModels()
+ "\n expected: " + expected);
}
}
}

[TestMethod()]
}

[TestCategory( "LongRun" ), TestMethod()]
public void testCapletPricing()
{
//"Testing caplet pricing...";
Expand Down Expand Up @@ -200,7 +200,7 @@ public void testCapletPricing()
+ "\n expected: " + expected);
}

[TestMethod()]
[TestCategory("LongRun"), TestMethod()]
public void testCalibration()
{
//("Testing calibration of a Libor forward model...");
Expand Down Expand Up @@ -300,7 +300,7 @@ public void testCalibration()
+ "\n expected : smaller than " + tolerance);
}

[TestMethod()]
[TestCategory("LongRun"),TestMethod()]
public void testSwaptionPricing()
{
//"Testing forward swap and swaption pricing...");
Expand Down
10 changes: 5 additions & 5 deletions Test/T_LiborMarketModelProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ LiborForwardModelProcess makeProcess(Matrix volaComp)

return process;
}
[TestMethod()]

[TestCategory( "LongRun" ), TestMethod()]
public void testInitialisation()
{
//"Testing caplet LMM process initialisation..."
Expand Down Expand Up @@ -146,8 +146,8 @@ public void testInitialisation()

}
}
[TestMethod()]

[TestCategory( "LongRun" ), TestMethod()]
public void testLambdaBootstrapping()
{
//"Testing caplet LMM lambda bootstrapping..."
Expand Down Expand Up @@ -197,7 +197,7 @@ public void testLambdaBootstrapping()
}
}

[TestMethod()]
[TestCategory("LongRun") , TestMethod()]
public void testMonteCarloCapletPricing()
{
//"Testing caplet LMM Monte-Carlo caplet pricing..."
Expand Down
4 changes: 2 additions & 2 deletions Test/T_PathGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public void testMultiple(StochasticProcess process,
}
}

[TestMethod()]
[TestCategory( "LongRun" ), TestMethod()]
public void testPathGenerator() {

//"Testing 1-D path generation against cached values...");
Expand Down Expand Up @@ -182,7 +182,7 @@ public void testPathGenerator() {
"square-root", false, 1.70608664108, 6.024200546031);
}

[TestMethod()]
[TestCategory( "LongRun" ), TestMethod()]
public void testMultiPathGenerator()
{

Expand Down
50 changes: 50 additions & 0 deletions Test/T_Swaps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,56 @@ public void testCachedValue()
+ " expected: " + cachedNPV);
}

[TestMethod()]
public void testFixing()
{
Date tradeDate = new Date( 17, Month.April, 2015 );
Calendar calendar = new UnitedKingdom();
Date settlementDate = calendar.advance( tradeDate, 2, TimeUnit.Days, BusinessDayConvention.Following );
Date maturityDate = calendar.advance( settlementDate, 5, TimeUnit.Years, BusinessDayConvention.Following );

Date valueDate = new Date( 20, Month.April, 2015 );
Settings.setEvaluationDate( valueDate );

List<Date> dates = new List<Date>();
dates.Add( valueDate );
dates.Add( valueDate + new Period( 1, TimeUnit.Years ) );
dates.Add( valueDate + new Period( 2, TimeUnit.Years ) );
dates.Add( valueDate + new Period( 5, TimeUnit.Years ) );
dates.Add( valueDate + new Period( 10, TimeUnit.Years ) );
dates.Add( valueDate + new Period( 20, TimeUnit.Years ) );

List<double> rates = new List<double>();
rates.Add( 0.01 );
rates.Add( 0.01 );
rates.Add( 0.01 );
rates.Add( 0.01 );
rates.Add( 0.01 );
rates.Add( 0.01 );

var discountCurveHandle = new RelinkableHandle<YieldTermStructure>();
var forecastCurveHandle = new RelinkableHandle<YieldTermStructure>();
GBPLibor index = new GBPLibor( new Period( 6, TimeUnit.Months ), forecastCurveHandle );
InterpolatedZeroCurve<Linear> zeroCurve = new InterpolatedZeroCurve<Linear>( dates, rates, new Actual360(), new Linear() );
var fixedSchedule = new Schedule( settlementDate, maturityDate, new Period( 1, TimeUnit.Years ), calendar, BusinessDayConvention.Following, BusinessDayConvention.Following, DateGeneration.Rule.Forward, false );
var floatSchedule = new Schedule( settlementDate, maturityDate, index.tenor(), calendar, BusinessDayConvention.Following, BusinessDayConvention.Following, DateGeneration.Rule.Forward, false );
VanillaSwap swap = new VanillaSwap( VanillaSwap.Type.Payer, 1000000, fixedSchedule, 0.01, new Actual360(), floatSchedule, index, 0, new Actual360() );
discountCurveHandle.linkTo( zeroCurve );
forecastCurveHandle.linkTo( zeroCurve );
var swapEngine = new DiscountingSwapEngine( discountCurveHandle, false, null );
swap.setPricingEngine( swapEngine );

try
{
double npv = swap.NPV();
}
catch ( Exception ex )
{
Assert.Fail( ex.Message );
Console.WriteLine( ex );
}
}

public void suite()
{
testFairRate();
Expand Down
3 changes: 3 additions & 0 deletions Test/default.testsettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<TestSettings name="Local" id="1fc46845-a72b-4ac7-a418-a6522918efe9" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
</TestSettings>

0 comments on commit 84fafd7

Please sign in to comment.