Learning about structures. Appreciate any comments on the below
struct BASE
a::Int64
b::Int64
end
struct B1
base::BASE
b1::Int64
end
struct B2
base::BASE
b2::Int64
end
df = DataFrame( type = [:B1,:B2], a=[1,1], b=[1,1], b1=[1,missing], b2=[missing,2] )
value( x::B1 ) = x.base.a + x.b1 * 2
value( x::B2 ) = x.base.a + x.b2 * 3
Question 1
is there an easy way to put each row of df into the appropriate structure (B1, B2) ?
Iād like to have a new column of df with the structures.
then apply the value function to this column.
Question 2
is it possible to avoid the x in the value function. Something like
value( ::B1... ) = base.a + b1 * 2
Question 3
I believe putting base::BASE into B1 and B2 like this is the best way to do inheritance in Julia (please correct me otherwise).
Question 4
Is it possible to include BASE in other structures but not require a prefix base.
to access the a
and b
parameters. Assuming the B1 parameter set is unique e.g. a, b, b1
My actual example is FX Options. Iād like to have a struct for the parameters common to all (Strike, Expiry, Settlement etc) and paste this into structs for the various types (Barrier, Digital, Asian etc).
Iād prefer not to preface the base parameters with base.