0

I have a class that have class method "getSimulatedPricesFrom". It will call method "projectFromPrice" from the same class during the execution. However in the line sTPlus1 line, I encounter the 2 errors:

1) Class method "projectFromPrice" not found

2) Pointer cannot be cast to type "double" 

Does anyone have idea on why? I have already declare the method in .h file Below is part of the coding in AmericanOption.m file:

#import "AmericanOption.h"

@implementation AmericanOption

+(NSMutableArray*)getSimulatedPricesFrom:(double)s0 withRate:(double)r0 withVol:(double)v0 withDays:(int)D withPaths:(int)N
{
    double daysPerYr = 365.0;
    double sT;
    double sTPlus1;
    sT = s0;
...
    sTPlus1 = (double)[AmericanOption projectFromPrice:sT, r0/daysPerYr, v0/daysPerYr, 1/daysPerYr];
...
    return arrPricePaths;
}

+(double)projectFromPrice:(double)s0 withRate:(double)r0 withVol:(double)v0 withDt:(double)dt
{
    ...
}
Paul R
  • 208,748
  • 37
  • 389
  • 560
Tsui John
  • 107
  • 3
  • 21

2 Answers2

1

It looks like you should call the projectFromPrice method as follows:

sTPlus1 = [AmericanOption projectFromPrice:sT 
                                  withRate:r0/daysPerYr 
                                   withVol:v0/daysPerYr 
                                    withDt:1/daysPerYr];

In your example code you are just providing a comma separated list of parameters. You should use the named parameters of the method.

The first of the two errors is because the method projectFromPrice: is not the same as the method projectFromPrice:withRate:withVol:withDt:.

projectFromPrice:withRate:withVol:withDt: is the method that actually exists and is presumably defined in your interface (.h file). projectFromPrice: is the method that you are trying to call but it doesn't exist.

The second error is a result of the compiler assuming that the undefined projectFromPrice: method returns an id (a pointer) which can't be cast to a double.

mttrb
  • 8,297
  • 3
  • 35
  • 57
0

This is the way you call your second methods that seems to be the problem. Try this, instead :

+(NSMutableArray*)getSimulatedPricesFrom:(double)s0 withRate:(double)r0 withVol:(double)v0 withDays:(int)D withPaths:(int)N
{
    double daysPerYr = 365.0;
    double sT;
    double sTPlus1;
    sT = s0;
...
    sTPlus1 = (double)[AmericanOption projectFromPrice:sT withRate:r0/daysPerYr withVol:v0/daysPerYr withDt:1/daysPerYr];
...
    return arrPricePaths;
}

+(double)projectFromPrice:(double)s0 withRate:(double)r0 withVol:(double)v0 withDt:(double)dt
{
    ...
}
Niko
  • 2,543
  • 1
  • 24
  • 29