Code Monkey home page Code Monkey logo

finmath-lib's People

Contributors

agrotz avatar alessandrognoatto avatar algoamigo avatar bbreiden avatar cfries avatar delreluca avatar emcleod avatar ianmayo avatar ikethermite avatar luca-bressan avatar maxsing avatar mquirin avatar nahian1005002 avatar niklasrodi avatar noittom avatar rolandbachl avatar silversteven avatar stefansedlmair avatar veichel avatar william1104 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

finmath-lib's Issues

Class Diagram is obsolete

Hi,

in net.finmath.montecarlo.assetderivativevaluation we have a class diagram. This is obsolete due to several renamings that happened in the transition to version 4.0.

I am attaching a possible substitute.

net finmath montecarlo model

CapletVolatilitiesParametricCalibrationTest can run in a time out on Travis

The unit test net.finmath.marketdata.model.volatilities.CapletVolatilitiesParametricCalibrationTest can run in a time out on Travis (depends on the machine we get on Travis):

Running calibration test using quoting convention VOLATILITYNORMAL for calibration objective function.
Given a discount curve:
DiscountCurveNelsonSiegelSvensson [timeScaling=1.0, parameter=[0.02, -0.01, 0.14, -0.1, 4.0, 3.0], toString()=AbstractCurve [name=EUR, referenceDate=2014-07-15]]
Quaterly forward with fixing in 1.0 requested from forward curve is 0.016235670732787796
Quaterly forward with fixing in 1.0 calculated from that discount curve is 0.016235670732787796

No output has been received in the last 10m0s, this potentially indicates a stalled build or something wrong with the build itself.
Check the details on how to adjust your build configuration on: https://docs.travis-ci.com/user/common-build-problems/#Build-times-out-because-no-output-was-received

The build has been terminated

Missing AbstractDiscountCurve class

There should be an AbstractDiscountCurve class that e.g. implements getDiscountCurve(double) = getDiscountCurve(model, double) instead having to implement that in each subclass

Moment Explosions for stochastic volatility models.

I have a concern regarding the present version of the implementation of both the Heston and Bates models. So far I was not complaining because we only had BlackScholes in the library and everything is fine in that case. Introducing more advanced models implies that one has to pay more attention.

Currently it is possible to choose quite freely the domain of integration, this implies that the characteristic function may explode in finite time, which results in non-sense option prices.
There is a vast literature on the topic. Prominent examples are given by Andersen and Piterbarg
https://link.springer.com/article/10.1007/s00780-006-0011-7
and Keller-Ressel
http://onlinelibrary.wiley.com/doi/10.1111/j.1467-9965.2010.00423.x/abstract

In concrete terms, to obtain a situation where you get in trouble with the current implementation try the following:
In net.finmath.fouriermethod.products.AbstractProductFourierTransform
Set some very nasty value in lineOfIntegration like
final double lineOfIntegration = 10.5 * getIntegrationDomainImagUpperBound()+getIntegrationDomainImagLowerBound();

and set the maturity of the option to 10 years. You should see option prices going to infinity.

To solve the issue without getting mad there is a trick: the use of the Cauchy residue theorem. To this you have to change the following lines in EuropeanOption
@OverRide
public double getIntegrationDomainImagLowerBound() {
return -1;
}

/* (non-Javadoc)
 * @see net.finmath.fouriermethod.products.AbstractProductFourierTransform#getDomainImagUpperBound()
 */
@Override
public double getIntegrationDomainImagUpperBound() {
	return 0;
}

But since we change the countour of integration, we have to add the residue term in front of the integral, so in AbstractProductFourierMethod you need to do something like

return residueTerm + integrator.integrate(integrand) / 2.0 / Math.PI;

and then you must provide in the interface a method getResidueTerm which provides the right residue (the residue depends on the contour you choose on the complex plane). In case we choose IntegrationDomainBound in (-1,0) the residue Term is simply the value of the asset today or, equivalently, the characteristic function of the asset computed at the point -1, which gives the martingale property of the asset.

Financially speaking, instead of transforming a call Option, you transform a covered call Position.

This is the best way to guarantee that your model does not become numerically unstable when you consider vanilla call/put options:
By definition of characteristic function you have that 0 and -1 are always good points: 0, by definition of characteristic function returns you 1 for the ch. Function while -1 is simply a statement of the martingale property of the (discounted) asset.

For more precise formulas please see the following paper by Roger Lee
https://www.math.uchicago.edu/~rl/dft.pdf

finmath-lib vs finmath-experiments

There's a suggestion to merge both packages in one. Consider to make maven-like project structure and probably use maven to project build.

main/src/java
main/test/java

as an example of directory structure in project. A problem you have now is that finmath-experiments depends on finmath-lib but finmath-lib is included into the the former as a compiled jar. Hence they are separated somewhat, but I'm not sure it was the purpose.

Update a REDAME.md file

Please, convert your custom READ ME.txt file to a README.md which will be displayed by default on project page.

Consider unification of models

Hi Christian, I have a suggestion:

Let us compare
net.finmath.fouriermethods.models.BlackScholesModel.java
and
net.finmath.montecarlo.assetderivativevaluation.BlackScholesModel.java

These two classes provide model specific information to different numerical methods, but a BlackScholes model is a BlackScholes model. The one in our Fourier methods package is merely providing the characteristic function. So I think that these two functionalities could be unified in a unique BlackScholes model class that provides:

public CharacteristicFunctionInterface apply(double time)

plus all other method from net.finmath.montecarlo.assetderivativevaluation.BlackScholesModel.java

If you consider the case of the Heston model, you have then a nice feature, we can calibrate our Heston model to a book of vanillas and then we can directly send the calibrated clone to the Monte Carlo engine to price exotics.

Suggestion - use Travis to include jars in release

Hi,
just adopted the lib. It's solving an optimisation problem that kept tripping up Apache Maths Common. Thanks!

Quick suggestion. You have a releases page for the project. This includes the source for each tagged release version.

It is possible to configure Travis to push the compiled jars to the release folder:
https://docs.travis-ci.com/user/deployment/releases/

Here's an example of a repo that includes compiled jars in the release:
https://github.com/ngageoint/geopackage-android/releases

Oh, while I'm begging... At very low cost (effort), it would be straightforward for you to modify your maven build to construct javadoc and source jar files.

Change default behaviours with system properties

Hi Christian,

Some classes (e.g. LinearAlgebra, CalibrationSpec and LIBORMarketModelStandard) control default behaviours with some embedded variables. Those variable values can be changed only with code changes.

May I modify related classes, so that those variable values can be changed with some system properties? I will keep the code backward compatible.

Best regards,
William

implement please Serializable interface in optimizer package

hi!

I want to distrubute the optimizers (especially the LevenbergMarquardt) to different nodes in my hazelcast cluster. Therefore I would like to ask you if you could implement the Serializable interface to your optimizers.

Thanks and all the best
KIC

Fourier Methods - Major rewrite needed.

The structure of this parts need to be revisited. Issues I see at the moment:

Models feature a riskFreeRate and dividendYield. It makes much more sense to use DiscountCurve (standalone, without any AnalyticModel overkill) for the purpose and refactor the characteristic function as fundamental transform, using the terminology of Alan Lewis.

Secondly, I can currently instantiate a Heston model where the correlation is 3, or the starting istantaneous variance is negative, which does not make any sense. Anyway I can do that because parameters are doubles currently. Models need to be equipped with constraint classes for the parameters and the library should complain when I feed it with nonsense.

In Quantlib this is solved e.g. in the Class HestonModel where in the constructor you see something like

arguments_[3] = ConstantParameter(process->rho(),BoundaryConstraint(-1.0, 1.0));

question on SABRVolatilityCube

Hi,

I am looking – as a relative beginner to Java – at your finmath package, specifically to build a SABR swaption grid.

I am confused by your conventions though.

In the code to getValue in SABRVolatilityCube.java you have

if(termination<maturity) {
   throw new IllegalArgumentException("Termination has to be larger (or equal) maturity. Was termination="+termination+", maturity="+maturity);
}

Therefore termination must be an absolute number, not relative to maturity.

But all the code does next is call the data tables:

final double underlying = underlyingTable.getValue(maturity, termination);
final double sabrRho = rhoTable.getValue(maturity, termination);
final double baseVol = baseVolTable.getValue(maturity, termination);
final double sabrVolvol = volvolTable.getValue(maturity, termination);

and DataTableLinear is defined with termination being relative to maturity:

* @param maturities The maturities of the points as offset with respect to the reference date.
* @param terminations The terminations of the points as offset with respect to the maturity date.

So for example a 5y-2y swaption cannot be accessed. Have I missed something?

Regards

Paul

Non-open source code?

From this file:

/* 
 * (c) Copyright Christian P. Fries, Germany. All rights reserved. Contact: [email protected]. 
 *  
 * Created on 25.01.2004 
 */ 

That would appear to contradict the Apache license this project is distributed under.

Eclipse - JUnit not recognized - All tests are failing

Hi,

I am testing finmath with the newest release of Eclipse, Eclipse 2018-12. I started from a fresh install and installed the Maven-Git SCM. After that I imported the project from Import /Maven / Check out project from SCM.

Import works, unfortunately alle test classes are not working because Junit is not recognized.

Junit is mentioned among the dependencies but it is in "dark grey". I looked for multiple solutions on Stackoverflow but nothing worked so far. The best I could understand is that this is related to a new option in Eclipse Photon https://stackoverflow.com/questions/51372670/eclipse-maven-dependency-jar-grayed-out-cant-import-classes-from-it/52946385

Schermata 2019-03-16 alle 10 43 28

CDS Schedules

Hi,

I am trying to hack the Schedule generator in order to replicate the coupon of a Credit Default Swap according to the ISDA model. This is what I got so far. Any help in finding bugs/wrong reasonings etc is appreciated.

My source is the following document by ISDA: https://www.isda.org/a/vGiDE/amend-single-name-on-the-run-frequency-faq-revised-as-of-12-10.pdf

Here is my code:

package schedule;

import java.time.LocalDate;
import java.time.Month;
import java.util.StringTokenizer;

import net.finmath.time.Schedule;
import net.finmath.time.ScheduleGenerator;
import net.finmath.time.businessdaycalendar.BusinessdayCalendarExcludingTARGETHolidays;
import net.finmath.time.businessdaycalendar.BusinessdayCalendar.DateOffsetUnit;

public class ScheduleTest {

public static void main(String[] args) {

/*
 * Today is   
 */
LocalDate referenceDate = LocalDate.of(2015, 12, 20);

ScheduleTest test = new ScheduleTest();

String tenor = "5Y";

System.out.println(test.getPreviousRollDate(referenceDate).getDayOfWeek());
System.out.println(test.getFirstImmDateAfterRoll(referenceDate).getDayOfWeek());

System.out.println("Maturity Date of the CDS: this is an unadjusted IMM Date");
LocalDate unadjustedMaturityDate = test.getMaturityDate(referenceDate, tenor);
System.out.println(unadjustedMaturityDate);
System.out.println(unadjustedMaturityDate.getDayOfWeek());

BusinessdayCalendarExcludingTARGETHolidays cal = new BusinessdayCalendarExcludingTARGETHolidays();
if(cal.isBusinessday(unadjustedMaturityDate)==false) {
  System.out.println(unadjustedMaturityDate + " is not a good business day.");
}

Schedule schedule = ScheduleGenerator.createScheduleFromConventions(
    test.getPreviousRollDate(referenceDate)/* referenceDate */,
    test.getFirstImmDateAfterRoll(referenceDate)/* startDate */,
    test.getMaturityDate(referenceDate, tenor) /* maturity */,
    "quarterly" /* frequency */,
    "act/360" /* daycountConvention */,
    "first" /* shortPeriodConvention */,
    "following",
    new BusinessdayCalendarExcludingTARGETHolidays(),
    0,
    0);

System.out.println(schedule);

}

/**

  • CDS maturities are rolled twice a year, on March 20 and September 20
  • For a given trade date, return the previous roll date, this is either
  • March 20 or September 20.
  • @param tradeDate representing the date at which the trade is entered.
  • @return the previous roll date.
    */
    public LocalDate getPreviousRollDate(LocalDate tradeDate) {
    //Date is before march
    if(tradeDate.isBefore(LocalDate.of(tradeDate.getYear(), 3, 19))) {
    return LocalDate.of(tradeDate.getYear() -1, 9, 20);
    }else if(tradeDate.isAfter(LocalDate.of(tradeDate.getYear(), 3, 19)) && tradeDate.isBefore(LocalDate.of(tradeDate.getYear(), 9, 19)) ) {
    return LocalDate.of(tradeDate.getYear(), 3, 20);
    }else {
    return LocalDate.of(tradeDate.getYear(), 9, 20);
    }
    }

/**

  • Find the first IMM date after the previous roll date.
  • From this date we compute the maturity of the contract.
  • @param tradeDate representing the date at which the trade is entered.
  • @return the next IMM date after the previous roll date.
    */
    public LocalDate getFirstImmDateAfterRoll(LocalDate tradeDate) {
LocalDate rollDate = getPreviousRollDate(tradeDate);

//Roll month is march
if(rollDate.getMonth().equals(Month.MARCH)) {
  //The first Imm Date is 20 June of the same year
  return LocalDate.of(rollDate.getYear(), Month.JUNE, 20);
}else {
  //The roll month is September, hence the first IMM date is 20 December.
  return LocalDate.of(rollDate.getYear(), Month.DECEMBER, 20);
}

}

public LocalDate getMaturityDate(LocalDate tradeDate, String dateOffsetCode) {
dateOffsetCode = dateOffsetCode.trim();

StringTokenizer tokenizer = new StringTokenizer(dateOffsetCode);

LocalDate maturityDate = getFirstImmDateAfterRoll(tradeDate);

while(tokenizer.hasMoreTokens()) {
  String maturityCodeSingle = tokenizer.nextToken();
  String[] maturityCodeSingleParts = maturityCodeSingle.split("(?<=[0-9|\\.])(?=[A-Z|a-z])");
  
  if(maturityCodeSingleParts.length == 2) {
    int maturityValue = Integer.valueOf(maturityCodeSingleParts[0]);
    DateOffsetUnit dateOffsetUnit = DateOffsetUnit.getEnum(maturityCodeSingleParts[1]);

    switch(dateOffsetUnit) {
    case DAYS:
    {
      maturityDate = maturityDate.plusDays(maturityValue);
      break;
    }
    case WEEKS:
    {
      maturityDate = maturityDate.plusWeeks(maturityValue);
      break;
    }
    case MONTHS:
    {
      maturityDate = maturityDate.plusMonths(maturityValue);
      break;
    }
    case YEARS:
    {
      maturityDate = maturityDate.plusYears(maturityValue);
      break;
    }
    default:
      throw new IllegalArgumentException("Cannot handle dateOffsetCode '" + dateOffsetCode + "'.");
    }
  }
  else {
    throw new IllegalArgumentException("Cannot handle dateOffsetCode '" + dateOffsetCode + "'.");
  }
}
return maturityDate;

}

}

Non-vanilla Bermudan Swaption

Hi,
How should I build a Bermudan Option on a general swap in the LMM? For example a swap paying CMS v Libor. The BermudanSwaption class assumes a Fixed/Libor swap.

Thanks

Paul

B&S ImpliedVolatilty for a put

Hello,

Is it possible to have implied volatilty for a put ?
AnalyticFormulas.blackScholesOptionImpliedVolatility

Currently it is only available for a call.

Thanks,
Luc

TimeDiscretization inconsistency

TimeDiscretization states that it will round times to a certain tick size in the Javadoc. This is done inconsistently between the different constructors:

The ellipsis/double array constructor will not round the given times to tick size.
The other constructors (boxed Double array, Set and ArrayList) will do that.

All constructors fail to remove duplicates though.

A unit test for the missing rounding can look like this:

public class TimeDiscretizationTest {

    private static double getHalfTickMore(double a) {
        return a + 0.5 / (365.0 * 24.0);
    }

    @Test
    public void testTickRoundingOfUnboxedArrayConstruction() {

        double a = 4.2;
        double identicalToA = getHalfTickMore(a);

        TimeDiscretization discretization = new TimeDiscretization(a, identicalToA);

        Assert.assertEquals(discretization.getTime(0), discretization.getTime(1), 0.0);
    }

    @Test
    public void testTickRoundingOfBoxedArrayConstruction() {

        double a = 4.2;
        double identicalToA = getHalfTickMore(a);

        TimeDiscretization discretization = new TimeDiscretization(new Double[] { a, identicalToA});

        Assert.assertEquals(discretization.getTime(0), discretization.getTime(1), 0.0);
    }
}

There is another inconsistency: The interface Set<> is accepted but List<> is not, although its implementation ArrayList<> is.

I will try and perform a pull request with the following fixes and unit tests soon:

  • The tests above should all pass.
  • In addition, in the above tests discretization should only contain 1 time point.
  • Any Iterable<> should be accepted

Here are some other features that might be useful:

  • Add methods for union and intersection to the TimeDiscretizationInterface as these are actually quite common operations (the SDE process time discretization must contain the LIBOR period discretization in the LIBORMarketModel for example). The implementation of this for TimeDiscretization would depend on the correct rounding and duplicate removal.
  • I have no personal stake in this but control of the tick size might be useful for people operating on high frequencies. In this case I propose adding the tick size to the interface and having unions/intersections use the coarser tick size.
  • Windowing a time discretization (intersecting with an interval) might also be a useful operation.

Observer Pattern and lazy recalculation

The library should provide a mechanism for the interaction between market data (Observables) and products (Observers). You can find a tentative implementation of the Observer pattern at the following link: https://github.com/AlessandroGnoatto/mafinlib

This implementation is thread safe with an exception.

The next Feature would then be lazy recalculation happening only to the products which are notified.

net.finmath.montecarlo.interestrate.products.indices.LIBORIndexTest may take very long.

The unit test net.finmath.montecarlo.interestrate.products.indices.LIBORIndexTest may take very long. Could be a memory problem. Some profiling should be done here.

Sample Output:

2.00 2.50 0.000013 0.000212
2.00 2.25 0.000019 0.000212
2.00 3.00 0.000024 0.000212
2.50 3.00 0.000013 0.000212
2.50 3.25 0.000034 0.000212
2.50 3.50 0.000023 0.000212
2.00 4.00 0.000039 0.000212
2.00 5.00 0.000050 0.000212
2.25 2.50 -0.000006 0.000212
4.00 5.00 -0.000007 0.000212

-0.000147 0.001414
2.00 20.00 -0.000168

[INFO] Tests run: 60, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 4,007.218 s - in net.finmath.montecarlo.interestrate.products.indices.LIBORIndexTest

Kotlin outdated

Hi. Thanks for the library!

Just a quick note that the Kotlin reference (1.2.0 from 2017) is somewhat outdated. I just spent quite a while debugging an issue, which turned out to be this 'elderly' Kotlin (indirectly referenced through a component and thus hidden in the dependency tree) quietly overtaking a directly referenced Kotlin 1.3 - and breaking the web server due to missing API. The Maven workaround is to exclude the Kotlin dependency of finmath but I figured I'd drop a related note here. Cheers.

Kotlin curve calibration test

Hi

I have been trying to run the curve calibration test script in kotlin but the editor does not give me any option to run the test.

Any idea why that might be?

finmath-lib/src/test/kotlin/net/finmath/marketdata/model/curves/CalibrationMultiCurveKotlinTest.kt

Eclipse: import “Project from Git” no longer works

Hi,

Trying to directly import the finmath library as a project from git in Eclipse 2020-12 does not work. The structure of the project is not correcly recognized, see the following snapshot:

PastedGraphic-1

The issue has been reported by some students of mine and replicated on my environment.
Best,
Alessandro

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.