I have two different subclasses of Surface, IndexImpliedVolatilitySurface and InterestRateImpliedVolatilitySurface. I'm aoyed though, because these two classes are about 200 lines each and identical except for parameter names in one method and the names of a getter, as seen here
public class IndexImpliedVolatilitySurface : Surface
{
public IReadOnlyList<double> OptionMaturities
{
get { retu UnderlyingSurface.RowHeaders(); }
}
public IReadOnlyList<double> MoneynessLevels // notice different name
{
get { retu UnderlyingSurface.ColumnHeaders(); }
}
public int NumberOptionMaturities
{
get { retu UnderlyingSurface.RowCount; }
}
public int NumberMoneynessLevels // notice different name
{
get { retu UnderlyingSurface.ColumnCount; }
}
// a bunch more identical methods and constructors here
// different parameter name here
public double Volatility(double optionMaturity, double moneyness)
{
retu GetSurfacePointAt(optionMaturity, moneyness);
}
}
as compared to
public class InterestRateImpliedVolatilitySurface : Surface
{
public IReadOnlyList<double> OptionMaturities
{
get { retu UnderlyingSurface.RowHeaders(); }
}
public IReadOnlyList<double> SwapMaturities // notice different name
{
get { retu UnderlyingSurface.ColumnHeaders(); }
}
public int NumberOptionMaturities
{
get { retu UnderlyingSurface.RowCount; }
}
public int NumberSwapMaturities // notice different name
{
get { retu UnderlyingSurface.ColumnCount; }
}
// a bunch more identical methods and constructors here
// different parameter name here
public double Volatility(double optionMaturity, double swapTenor)
{
retu GetSurfacePointAt(optionMaturity, swapTenor);
}
}
So why do I have two classes? Because it's actually quite important for the client code that the getters have their respectively different names. I want to create a template class called ImpliedVolatilitySurface from which both surfaces can inherit and then override the getters, but I am not sure
-
If this is the right approach
-
How to override the getters properly such that they accomplish the very same thing but just have different names.
