Skip to content

Commit

Permalink
Update to QLNet-1.8.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
amaggiulli committed Sep 9, 2016
2 parents 43568bc + 8bc8542 commit 1fc2e7f
Show file tree
Hide file tree
Showing 290 changed files with 21,801 additions and 7,953 deletions.
1,345 changes: 597 additions & 748 deletions ChangeLog.txt

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions Examples/BermudanSwaption/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
// Le informazioni generali relative a un assembly sono controllate dal seguente
// insieme di attributi. Per modificare le informazioni associate a un assembly
// occorre quindi modificare i valori di questi attributi.
[assembly: AssemblyTitle("BermudanSwaption")]
[assembly: AssemblyTitle( "QLNet BermudanSwaption Example" )]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BermudanSwaption")]
[assembly: AssemblyCopyright("Copyright © 2010")]
[assembly: AssemblyProduct( "QLNet Examples" )]
[assembly: AssemblyCopyright( "Copyright (c) 2008-2016 Andrea Maggiulli ([email protected])" )]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand All @@ -32,5 +32,5 @@
// È possibile specificare tutti i valori oppure impostare i valori predefiniti per i numeri relativi alla build e alla revisione
// utilizzando l'asterisco (*) come descritto di seguito:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.7.0.0")]
[assembly: AssemblyFileVersion("1.7.0.0")]
[assembly: AssemblyVersion("1.8.0.0")]
[assembly: AssemblyFileVersion("1.8.0.0")]
10 changes: 5 additions & 5 deletions Examples/Bonds/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Bonds")]
[assembly: AssemblyTitle( "QLNet Bonds Example" )]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Bonds")]
[assembly: AssemblyCopyright("Copyright © 2008")]
[assembly: AssemblyProduct( "QLNet Examples" )]
[assembly: AssemblyCopyright( "Copyright (c) 2008-2016 Andrea Maggiulli ([email protected])" )]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand All @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.7.0.0")]
[assembly: AssemblyFileVersion("1.7.0.0")]
[assembly: AssemblyVersion("1.8.0.0")]
[assembly: AssemblyFileVersion("1.8.0.0")]
189 changes: 189 additions & 0 deletions Examples/CVAIRS/CVAIRS.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
// Copyright (C) 2008-2016 Andrea Maggiulli ([email protected])
//
// This file is part of QLNet Project https://github.com/amaggiulli/qlnet
// QLNet is free software: you can redistribute it and/or modify it
// under the terms of the QLNet license. You should have received a
// copy of the license along with this program; if not, license is
// available online at <http://qlnet.sourceforge.net/License.html>.
//
// QLNet is a based on QuantLib, a free-software/open-source library
// for financial quantitative analysts and developers - http://quantlib.org/
// The QuantLib license is available online at http://quantlib.org/license.shtml.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the license for more details.
using System;
using System.Collections.Generic;
using QLNet;

namespace CVAIRS
{
class CVAIRS
{
static void Main( string[] args )
{
try
{

DateTime timer = DateTime.Now;
Calendar calendar = new TARGET();
Date todaysDate = new Date(10,Month.March, 2004);
// must be a business day
todaysDate = calendar.adjust(todaysDate);

Settings.setEvaluationDate(todaysDate);

IborIndex yieldIndx = new Euribor3M();
int[] tenorsSwapMkt = {5,10,15,20,25,30};

// rates ignoring counterparty risk:
double[] ratesSwapmkt = {.03249,.04074,.04463,.04675,.04775,.04811};

List<RateHelper> swapHelpers = new List<RateHelper>();
for (int i = 0; i < tenorsSwapMkt.Length; i++)
swapHelpers.Add(new SwapRateHelper(new Handle<Quote>(new SimpleQuote(ratesSwapmkt[i])),
new Period(tenorsSwapMkt[i],TimeUnit.Years),
new TARGET(),
Frequency.Quarterly,
BusinessDayConvention.ModifiedFollowing,
new ActualActual(ActualActual.Convention.ISDA),
yieldIndx));

YieldTermStructure swapTS = new PiecewiseYieldCurve<Discount, LogLinear>(2, new TARGET(), swapHelpers,
new ActualActual(ActualActual.Convention.ISDA));
swapTS.enableExtrapolation();

IPricingEngine riskFreeEngine = new DiscountingSwapEngine(new Handle<YieldTermStructure>(swapTS));

List<Handle<DefaultProbabilityTermStructure>> defaultIntensityTS =
new List<Handle<DefaultProbabilityTermStructure>>();

int[] defaultTenors = {0,12,36,60,84,120,180,240,300,360}; // months
// Three risk levels:
double[] intensitiesLow = {0.0036,0.0036,0.0065,0.0099,0.0111,0.0177,0.0177,0.0177,0.0177,0.0177,0.0177};
double[] intensitiesMedium = {0.0202,0.0202,0.0231,0.0266,0.0278,0.0349,0.0349,0.0349,0.0349,0.0349,0.0349};
double[] intensitiesHigh = {0.0534,0.0534,0.0564,0.06,0.0614,0.0696,0.0696,0.0696,0.0696,0.0696,0.0696};
// Recovery rates:
double ctptyRRLow = 0.4, ctptyRRMedium = 0.35, ctptyRRHigh = 0.3;

List<Date> defaultTSDates = new List<Date>();
List<double> intesitiesVLow = new List<double>(),
intesitiesVMedium = new List<double>(),
intesitiesVHigh = new List<double>();

for (int i = 0; i < defaultTenors.Length; i++)
{
defaultTSDates.Add(new TARGET().advance(todaysDate,new Period(defaultTenors[i], TimeUnit.Months)));
intesitiesVLow.Add(intensitiesLow[i]);
intesitiesVMedium.Add(intensitiesMedium[i]);
intesitiesVHigh.Add(intensitiesHigh[i]);
}

defaultIntensityTS.Add(new Handle<DefaultProbabilityTermStructure>(
new InterpolatedHazardRateCurve<BackwardFlat>(
defaultTSDates,
intesitiesVLow,
new Actual360(),
new TARGET())));
defaultIntensityTS.Add(new Handle<DefaultProbabilityTermStructure>(
new InterpolatedHazardRateCurve<BackwardFlat>(
defaultTSDates,
intesitiesVMedium,
new Actual360(),
new TARGET())));
defaultIntensityTS.Add(new Handle<DefaultProbabilityTermStructure>(
new InterpolatedHazardRateCurve<BackwardFlat>(
defaultTSDates,
intesitiesVHigh,
new Actual360(),
new TARGET())));

double blackVol = 0.15;
IPricingEngine ctptySwapCvaLow = new CounterpartyAdjSwapEngine(new Handle<YieldTermStructure>(swapTS),
blackVol,defaultIntensityTS[0],ctptyRRLow);

IPricingEngine ctptySwapCvaMedium = new CounterpartyAdjSwapEngine(new Handle<YieldTermStructure>(swapTS),
blackVol,defaultIntensityTS[1],ctptyRRMedium);

IPricingEngine ctptySwapCvaHigh = new CounterpartyAdjSwapEngine(new Handle<YieldTermStructure>(swapTS),
blackVol,defaultIntensityTS[2],ctptyRRHigh);

defaultIntensityTS[0].link.enableExtrapolation();
defaultIntensityTS[1].link.enableExtrapolation();
defaultIntensityTS[2].link.enableExtrapolation();

// SWAP RISKY REPRICE----------------------------------------------

// fixed leg
Frequency fixedLegFrequency = Frequency.Quarterly;
BusinessDayConvention fixedLegConvention = BusinessDayConvention.ModifiedFollowing;
DayCounter fixedLegDayCounter = new ActualActual(ActualActual.Convention.ISDA);
DayCounter floatingLegDayCounter = new ActualActual(ActualActual.Convention.ISDA);

VanillaSwap.Type swapType =
//VanillaSwap::Receiver ;
VanillaSwap.Type.Payer;
IborIndex yieldIndxS = new Euribor3M(new Handle<YieldTermStructure>(swapTS));
List<VanillaSwap> riskySwaps = new List<VanillaSwap>();
for (int i = 0; i < tenorsSwapMkt.Length; i++)
riskySwaps.Add(new MakeVanillaSwap(new Period(tenorsSwapMkt[i],TimeUnit.Years),
yieldIndxS,
ratesSwapmkt[i],
new Period(0,TimeUnit.Days))
.withSettlementDays(2)
.withFixedLegDayCount(fixedLegDayCounter)
.withFixedLegTenor(new Period(fixedLegFrequency))
.withFixedLegConvention(fixedLegConvention)
.withFixedLegTerminationDateConvention(fixedLegConvention)
.withFixedLegCalendar(calendar)
.withFloatingLegCalendar(calendar)
.withNominal(100.0)
.withType(swapType).value());

Console.WriteLine("-- Correction in the contract fix rate in bp --" );
/* The paper plots correction to be substracted, here is printed
with its sign
*/
for (int i = 0; i < riskySwaps.Count; i++)
{
riskySwaps[i].setPricingEngine(riskFreeEngine);
// should recover the input here:
double nonRiskyFair = riskySwaps[i].fairRate();
Console.Write( (tenorsSwapMkt[i]).ToString( "0" ).PadLeft( 6 ) );
Console.Write( " | " + nonRiskyFair.ToString( "P3" ).PadLeft( 6 ) );
// Low Risk:
riskySwaps[i].setPricingEngine(ctptySwapCvaLow);
Console.Write( " | " + ( 10000.0 * ( riskySwaps[i].fairRate() - nonRiskyFair ) ).ToString( "#0.00" ).PadLeft( 6 ) );
//cout << " | " << setw(6) << riskySwaps[i].NPV() ;

// Medium Risk:
riskySwaps[i].setPricingEngine(ctptySwapCvaMedium);
Console.Write( " | " + ( 10000.0 * ( riskySwaps[i].fairRate() - nonRiskyFair ) ).ToString( "#0.00" ).PadLeft( 6 ) );
//cout << " | " << setw(6) << riskySwaps[i].NPV() ;

riskySwaps[i].setPricingEngine(ctptySwapCvaHigh);
Console.Write( " | " + ( 10000.0 * ( riskySwaps[i].fairRate() - nonRiskyFair ) ).ToString( "#0.00" ).PadLeft( 6 ) );
//cout << " | " << setw(6) << riskySwaps[i].NPV() ;

Console.WriteLine();
}

Console.WriteLine();

Console.WriteLine(" \nRun completed in {0}", DateTime.Now - timer);
Console.WriteLine();

Console.Write("Press any key to continue ...");
Console.ReadKey();

}
catch (Exception e)
{
Console.Write(e.Message);
Console.Write( "Press any key to continue ..." );
Console.ReadKey();
}
}
}
}
61 changes: 61 additions & 0 deletions Examples/CVAIRS/CVAIRS.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{46817C48-9DE1-4A56-82CF-3B7A3BEF712B}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CVAIRS</RootNamespace>
<AssemblyName>CVAIRS</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="CVAIRS.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\QLNet\QLNet.csproj">
<Project>{f6e762bd-dcdf-4ca0-abad-cb21c7d03bec}</Project>
<Name>QLNet</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
36 changes: 36 additions & 0 deletions Examples/CVAIRS/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle( "QLNet CVAIRS Example" )]
[assembly: AssemblyDescription( "" )]
[assembly: AssemblyConfiguration( "" )]
[assembly: AssemblyCompany( "" )]
[assembly: AssemblyProduct( "QLNet Examples" )]
[assembly: AssemblyCopyright( "Copyright (c) 2008-2016 Andrea Maggiulli ([email protected])" )]
[assembly: AssemblyTrademark( "" )]
[assembly: AssemblyCulture( "" )]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible( false )]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid( "c4a8eb32-aee9-471f-98f0-43dc343ad495" )]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion( "1.8.0.0" )]
[assembly: AssemblyFileVersion( "1.8.0.0" )]
10 changes: 5 additions & 5 deletions Examples/CallableBonds/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
// Le informazioni generali relative a un assembly sono controllate dal seguente
// set di attributi. Per modificare le informazioni associate a un assembly
// occorre quindi modificare i valori di questi attributi.
[assembly: AssemblyTitle("CallableBonds")]
[assembly: AssemblyTitle( "QLNet CallableBonds Example" )]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CallableBonds")]
[assembly: AssemblyCopyright("Copyright © 2012")]
[assembly: AssemblyProduct( "QLNet Examples" )]
[assembly: AssemblyCopyright( "Copyright (c) 2008-2016 Andrea Maggiulli ([email protected])" )]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand All @@ -32,5 +32,5 @@
// È possibile specificare tutti i valori oppure impostare valori predefiniti per i numeri relativi alla revisione e alla build
// utilizzando l'asterisco (*) come descritto di seguito:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.7.0.0")]
[assembly: AssemblyFileVersion("1.7.0.0")]
[assembly: AssemblyVersion("1.8.0.0")]
[assembly: AssemblyFileVersion("1.8.0.0")]
6 changes: 3 additions & 3 deletions Examples/EquityOption/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("EquityOption")]
[assembly: AssemblyTitle( "QLNet EquityOption Example" )]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("EquityOption")]
[assembly: AssemblyCopyright("Copyright © 2008")]
[assembly: AssemblyProduct( "QLNet Examples" )]
[assembly: AssemblyCopyright( "Copyright (c) 2008-2016 Andrea Maggiulli ([email protected])" )]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand Down
6 changes: 3 additions & 3 deletions Examples/FRA/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
// Le informazioni generali relative a un assembly sono controllate dal seguente
// insieme di attributi. Per modificare le informazioni associate a un assembly
// occorre quindi modificare i valori di questi attributi.
[assembly: AssemblyTitle("FRA")]
[assembly: AssemblyTitle( "QLNet FRA Example" )]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("FRA")]
[assembly: AssemblyCopyright("Copyright © 2008")]
[assembly: AssemblyProduct( "QLNet Examples" )]
[assembly: AssemblyCopyright( "Copyright (c) 2008-2016 Andrea Maggiulli ([email protected])" )]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand Down
Loading

0 comments on commit 1fc2e7f

Please sign in to comment.